admin
2022-09-09 60feedf43a35a9ca69d05095a01c5d1797b1bdc3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
#include "L2DataCapture.h"
#include "CaptureUtil.h"
#include "THSActionUtil.h"
#include "Win32Util.h"
#include "LimitUpCapture.h"
#include "IndustryCapture.h"
#include "TradeListCapture.h"
#include "CurrentPriceCapture.h"
#include "log4cpp/Category.hh"
#include "log4cpp/FileAppender.hh"
#include "log4cpp/StringQueueAppender.hh"
#include "log4cpp/BasicLayout.hh"
using namespace log4cpp;
 
void gray();
void ths();
/*
#include <amp.h>
#include <amp_math.h>
*/
 
DWORD WINAPI threadname(LPVOID lpParamter) // 函数名字可随意
{
    int* index = (int*)lpParamter;
 
    int p = *index;
 
    L2DataCapture* creenDataCapture = new L2DataCapture();
    while (true)
    {
        //同花顺(v9.10.50) - 深圳Level-2分时走势
        //同花顺(v9.10.50) - pppp
        list<TradeData>  map = creenDataCapture->captureLevel2TradeData(cv::imread("C:\\Users\\Administrator\\Desktop\\ocr\\demo\\0_388.jpg"), p);
        //break;
    }
 
    return 0L;
}
 
DWORD WINAPI inputCode(LPVOID lpParamter) // 函数名字可随意
{
    Sleep(1000);
    char code[] = "601012";
    for (int i = 0;i < 6;i++)
    {
        keybd_event(code[i], 0, 0, 0);
        keybd_event(code[i], 0, KEYEVENTF_KEYUP, 0);
    }
    return 0L;
}
 
 
DWORD WINAPI inputEnter(LPVOID lpParamter) // 函数名字可随意
{
    Sleep(1500);
    keybd_event(VK_RETURN, 0, 0, 0);
    keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
    HWND win = FindWindowA(0, "添加股票");
 
    //CloseWindow(win);
    Sleep(100);
    SendMessage(win, WM_CLOSE, 0, 0);
    return 0L;
}
 
 
/*
int main() {
    //获取加速设备
    std::vector<concurrency::accelerator> aors= concurrency::accelerator::get_all();
 
    int size = 5;
    int aCPP[] = { 1, 2, 3, 4, 5 };
    int bCPP[] = { 6, 7, 8, 9, 10 };
    int sumCPP[5];
    concurrency::array_view<const int, 1> a(size, aCPP);
    concurrency::array_view<const int, 1> b(size, bCPP);
    concurrency::array_view<int, 1> sum(size, sumCPP);
    */
 
    /*
    concurrency::parallel_for_each(
        sum.extent,
        [=](concurrency::index<1> idx) restrict(amp)
        {
            sum[idx] = a[idx] + b[idx];
        }
    );
 
    for (int i = 0; i < size; i++)
    {
        std::cout << sum[i] << "\n";
    }
    */
    /*
        cv::waitKey(0);
        cv::destroyAllWindows();
 
 
        return 0;
    }
    */
 
void notify(int index, string code, list<TradeData> data, void* context) {
    cout << index << endl;
}
void callback(list<LimitUpData> codeList, void* contex) {
 
}
 
#include "TradeQueueCapture.h"
void splitTradeQueue() {
    //横向切割
    TradeQueueCapture* tradeQueueCapture = new TradeQueueCapture();
    for (int i = 0;i < 8;i++)
    {
        string path = "C:\\Users\\Administrator\\Desktop\\ocr\\trade_queue\\";
        path.append(to_string(i)).append(".jpg");
 
        tradeQueueCapture->recognition(cv::imread(path, cv::IMREAD_GRAYSCALE));
        
    }
 
    
}
 
void onTradeListCallBack(list<TradeSuccessData> dataList, void* contex) {
 
}
 
int getNowSecondTime1() {
    time_t timep;
    time(&timep);
    char tmp_h[64];
    strftime(tmp_h, sizeof(tmp_h), "%H", localtime(&timep));
    char tmp_m[64];
    strftime(tmp_m, sizeof(tmp_m), "%M", localtime(&timep));
    char tmp_s[64];
    strftime(tmp_s, sizeof(tmp_s), "%S", localtime(&timep));
    cout << string(tmp_h) << endl;
    cout << string(tmp_m) << endl;    cout << string(tmp_s) << endl;
 
    return stoi(string(tmp_h)) * 3600 + stoi(string(tmp_m)) * 60 + stoi(string(tmp_s));
}
 
int main() {
 
    cout << "开始程序" << endl;
    ImgUtil::init();
    bool dead= THSActionUtil::thsIsDead();
 
 
    //cv::imshow("test",cv::Mat(cv::imread("C:\\Users\\Administrator\\Desktop\\ocr\\limit_up\\企业微信截图_16624495173041.png"), cv::Rect(619, 123, 34, 10)));
 
    cv::Mat img = ImgUtil::grayImage(cv::imread("C:\\Users\\Administrator\\Desktop\\ocr\\时间.png"));
    cv::imwrite("C:\\Users\\Administrator\\Desktop\\ocr\\时间_gray.png", cv::Mat( img,cv::Rect(img.cols-60,0,60,19)));
 
 
    cv::waitKey(0);
    cv::destroyAllWindows();
    return 0;
 
    ImgUtil::init();
 
    cout << "ImgUtil初始化完成" << endl;
 
    IndustryCapture* industryCapture = new IndustryCapture();
    cout << "LimitUpCapture实例化" << endl;
    //industryCapture->init();
    cout << "LimitUpCapture初始化完成" << endl;
 
    list<list<IndustryData>> datas=    industryCapture->captureIndustryCodes();
    
 
    delete industryCapture;
    //splitTradeQueue();
 
    //SendMessage(HWND(0x000B1A86), WM_LBUTTONDOWN, 0, MAKEWORD(1, 1));
    //SendMessage(HWND(0x000B1A86), WM_LBUTTONUP, 0, MAKEWORD(1, 1));
 
 
    /*
    ImgUtil::init();
 
    ScreenDataCapture* capture = new ScreenDataCapture();
    capture->init(notify,nullptr);
    capture->start();
    capture->startAll();
    */
 
 
    /*
    RecognitionUtil::init();
    CaptureUtil::init("同花顺(v9.10.50) - 热门股888");// 热门股888
    ImgUtil::init();
    std::list<string> codeList;
    codeList.push_back("000333");
    bool setResult = THSActionUtil::setListenL2GP(4,"000333");
    printf("设置股票代码结果:%d\n", setResult);
        cv::waitKey(0);
    cv::destroyAllWindows();
    return 0;
 
    */
 
    /*
    RecognitionManager* recognitionManager = new RecognitionManager();
 
    for (int i = 1;i < 14;i++)
    {
        string path = "C:\\Users\\Administrator\\Desktop\\ocr\\split\\";
        path.append(to_string(i)).append("_1.jpg");
        list<cv::Mat> list1 = ImgUtil::splitNum(cv::imread(path.c_str(), cv::IMREAD_GRAYSCALE));
        list<uchar> resultList= recognitionManager->recognitionGPCode(list1);
        list<uchar>::iterator ele;
        for (ele = resultList.begin();ele != resultList.end();++ele) {
            printf("%d",*ele);
        }
        printf("\n");
    }
    */
 
    /*
 
    RecognitionUtil::init();
    ImgUtil::init();
    for (int i = 0;i < 1;i++)
    {
        int* params =(int*) malloc(sizeof(int));
        *params = i;
        HANDLE hThread = CreateThread(NULL, 0, threadname, params, 0, NULL);
    }
 
 
    system("PAUSE");
    */
    //system("PAUSE");
    //cv::waitKey(0);
    //cv::destroyAllWindows();
 
    return 0;
}
 
int main__() {
 
    for (int i = 5;i < 6;i++)
    {
        cv::Mat img = CaptureUtil::capture(1,CAPTURE_TYPE_L2);
        string path = "C:\\Users\\Administrator\\Desktop\\ocr\\demo\\";
        path.append(to_string(i));
        path.append(".jpg");
        cv::imwrite(path, img);
    }
 
 
    return 1;
}
 
int main_() {
    cv::Mat img = ImgUtil::grayImage(cv::imread("E:\\temp\\506518.jpg"));
 
    imwrite("E:\\temp\\506518_gray.jpg", img);
 
    clock_t time_2 = clock();
    LogUtil::debug("灰度完成");
    //图像分割
    list<int*>  data;
    try {
        data = ImgUtil::divideImg(img, 1);
        if (data.size() == 0) {
            throw ERROR_CODE_DIVIDE_IMG_FAIL;
        }
    }
    catch (...) {
        throw ERROR_CODE_DIVIDE_IMG_FAIL;
    }
 
    cv::waitKey(0);
    cv::destroyAllWindows();
    return 0;
}
 
void gray() {
    cv::Mat mat = cv::imread("C:\\Users\\Administrator\\Desktop\\ocr\\new.jpg");
    uchar* data = mat.data;
    int rows = mat.rows;
    int cols = mat.cols;
    uchar* grayData = (uchar*)malloc(sizeof(uchar) * mat.rows * mat.cols);
 
    for (int r = 0;r < rows;r++) {
        for (int c = 0;c < cols;c++) {
            int index = r * cols + c;
            int start = index * 3;
            uchar R = data[start];
            uchar G = data[start + 1];
            uchar B = data[start + 2];
            grayData[index] = (76 * R + 150 * G + 30 * B) >> 8;
        }
    }
 
 
 
    cv::Mat m = cv::Mat::zeros(mat.rows, mat.cols, CV_8UC1);
    m.data = grayData;
    imshow("黑白", m);
 
 
 
 
 
 
 
 
}
 
 
void ths() {
    //00421530
    cv::Mat img = CaptureUtil::capture(HWND(0x00040CAE));
    img = ImgUtil::grayImage(img);
    //cv::imwrite("C:\\Users\\Administrator\\Desktop\\ocr\\bk.jpg",img);
    std::list<GPCodeArea> list = THSActionUtil::recognitionGPArea(img);
    std::list<GPCodeArea>::iterator ele;
    RecognitionManager* recognitionManager = new RecognitionManager();
    int index = 0;
    for (ele = list.begin();ele != list.end();ele++) {
        index++;
        GPCodeArea codeArea = *ele;
        if (codeArea.type == IMG_TYPE_GP) {
            cv::Mat nums = cv::Mat(img, cv::Rect(codeArea.startx, codeArea.starty, codeArea.endx - codeArea.startx + 1, codeArea.endy - codeArea.starty + 1));
            std::list<cv::Mat> list2 = ImgUtil::splitNum(nums);
            std::list<uchar> resultList = recognitionManager->recognitionGPCode(list2);
            std::list<uchar>::iterator ele1;
            printf("%d-", index);
            for (ele1 = resultList.begin();ele1 != resultList.end();++ele1) {
                printf("%d", *ele1);
            }
            printf("\n");
        }
 
        continue;
 
        SetForegroundWindow(HWND(0x00161728));
        SetFocus(HWND(0x00161728));
        if (codeArea.type == IMG_TYPE_ADD) {
            RECT rc;
            GetWindowRect(HWND(0x00161728), &rc);
            int y = rc.top + codeArea.starty + (codeArea.endy - codeArea.starty) / 2;
            int x = rc.left + codeArea.startx + (codeArea.endx - codeArea.startx) / 2;
            //POINT p;
            //p.x = x;
            //p.y = y;
            //GetCursorPos(&p);
            //移动鼠标
            SetCursorPos(x, y);
            Sleep(100);
            //点击鼠标
            mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
            Sleep(10);
            mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
 
            //键盘输入
            HANDLE hThread = CreateThread(NULL, 0, inputCode, 0, 0, NULL);
            //system("PAUSE");
 
 
            CreateThread(NULL, 0, inputEnter, 0, 0, NULL);
 
            system("PAUSE");
 
            //keybd_event(VK_RETURN, 0, 0, 0);
            //keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
 
            break;
        }
    }
 
 
 
}