#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" #include #include "TradeQueueCaptureManager.h" #include "LogUtil.h" #include "L2TradeQueueUtil.h" #include "THSDXJLCapture.h" using namespace log4cpp; void gray(); void ths(); /* #include #include */ 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 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 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 a(size, aCPP); concurrency::array_view b(size, bCPP); concurrency::array_view 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 data, void* context) { cout << index << endl; } void callback(list codeList, void* contex) { } void onTradeListCallBack(list 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 testLog() { LogUtil::getInstance()->getL2Logger().info("测试"); return 0; } void grayImg() { ImgUtil::init(); OpenCLExcuter* openCLExcuter = new OpenCLExcuter(); openCLExcuter->init(); cv::Mat img = cv::imread("C:\\Users\\Administrator\\Desktop\\ocr\\dxjl\\test.png"); uchar* datas = (uchar*)malloc(sizeof(uchar) * img.rows * img.cols); if (img.channels() == 4) { openCLExcuter->rgba2Gray(img, datas); } else { openCLExcuter->rgb2Gray(img, datas); } cv::Mat img1 = cv::Mat::zeros(img.rows, img.cols, CV_8UC1); img1.data = datas; cv::Mat binary; threshold(img1, binary, 96, 255, cv::THRESH_BINARY); cv::imwrite("C:\\Users\\Administrator\\Desktop\\ocr\\dxjl\\test_gray.png", img1); } void testSplit() { ImgUtil::init(); //list areas = L2TradeQueueUtil::splitBuyQueue(cv::imread("C:\\Users\\Administrator\\Desktop\\ocr\\trade_queue\\demo\\test.png", cv::IMREAD_GRAYSCALE),0); list areas = L2TradeQueueUtil::splitViewElements(cv::imread("C:\\Users\\Administrator\\Desktop\\ocr\\trade_queue\\demo\\7_19353.png", cv::IMREAD_GRAYSCALE)); } void testCaptureL2Trade() { ImgUtil::init(); OpenCLExcuter* openCLExcuter = new OpenCLExcuter(); openCLExcuter->init(); L2DataCapture *capture = new L2DataCapture(); cv::Mat img = cv::imread("C:\\Users\\Administrator\\Desktop\\ocr\\trade_queue\\Snipaste_2023-02-02_15-32-01.png"); //L2TradeQueue tradeQueue = capture->captureLevel2TradeQueueData(openCLExcuter, img, 0); printf("\n"); } void testCaptureL2TradeQueue() { ImgUtil::init(); L2DataCapture* capture = new L2DataCapture(); capture->init(NULL,NULL,NULL); capture->setGPCode(0,"000610"); capture->startAll(); while (TRUE) { Sleep(1000); } } void testDelegate() { ImgUtil::init(); TradeListCapture* capture = new TradeListCapture(); capture->init(NULL,NULL,NULL); cv::Mat oimg = cv::imread("C:\\Users\\Administrator\\Desktop\\ocr\\trade\\Snipaste_2023-01-03_09-33-57.png"); capture->captureSimpleTradeDelegateInfo(oimg); } void testTradeSuccess() { ImgUtil::init(); TradeListCapture* capture = new TradeListCapture(); capture->init(NULL, NULL, NULL); capture->captureTradeSuccessInfo(cv::imread("C:\\Users\\Administrator\\Desktop\\ocr\\trade\\Snipaste_2022-12-23_09-39-02.png")); } void markImg() { cv::Mat mat = cv::imread("C:\\Users\\Administrator\\Desktop\\ocr\\trade_queue\\Snipaste_2023-02-02_15-22-58.png", cv::IMREAD_GRAYSCALE); mat = ImgUtil::markMat(mat,cv::Rect(60,50,100,10),255,1); cv::imwrite("C:\\Users\\Administrator\\Desktop\\ocr\\trade_queue\\mark.png", mat); } void spliteDXJL() { ImgUtil::init(); THSDXJLCapture* capture = new THSDXJLCapture(); capture->init(NULL); OpenCLExcuter* openCLExcuter=new OpenCLExcuter(); openCLExcuter->init(); while(TRUE) { cv::Mat img = cv::imread("C:\\Users\\Administrator\\Desktop\\ocr\\dxjl\\test3.png"); capture->capture( img, openCLExcuter); Sleep(5); break; } } void captureLimitUp() { ImgUtil::init(); LimitUpCapture* limitUpCapture = new LimitUpCapture(); limitUpCapture->init(NULL, NULL,NULL, NULL); limitUpCapture->captureLimitUpFirstCodes(cv::imread("C:\\Users\\Administrator\\Desktop\\ocr\\limit_up.png")); } void testL2() { ImgUtil::init(); L2DataCapture* l2 = new L2DataCapture(); OpenCLExcuter* openCLExcuter = new OpenCLExcuter(); openCLExcuter->init(); cv::Mat mat = cv::imread("C:\\Users\\Administrator\\Desktop\\ocr\\l2分析\\Snipaste_2023-03-04_17-17-05.png"); list results = l2->captureLevel2TradeData(openCLExcuter, mat,1); int index = 0; for (list::iterator ele = results.begin(); ele != results.end(); ele++) { TradeData* data = *ele; cout.width(3); cout << index << " "; cout << data->time<<" "; cout.width(2); cout << data->cancelTime << ""; if (data->cancelTimeUnit == 0) { cout << "s" << " "; }else if (data->cancelTimeUnit == 1) { cout << "m" << " "; } else if (data->cancelTimeUnit == 2) { cout << "h" << " "; } cout << data->price << " "; cout.width(5); cout << data->num << " "; switch (data->operateType) { case 0: cout << "买"; break; case 1: cout << "买撤"; break; case 2: cout << "卖"; break; case 3: cout << "卖撤"; break; default: break; } cout << endl; index++; } } int main() { testL2(); //cv::Mat mat = cv::imread("C:\\Users\\Administrator\\Desktop\\ocr\\l2分析\\test1.png", CV_8UC1); //cv::Mat b; //cv::threshold(mat,b,0,255, cv::THRESH_BINARY); //cv::imshow("test", b); //cv::imwrite("C:\\Users\\Administrator\\Desktop\\ocr\\l2分析\\test2.png", b); //cv::waitKey(0); //cv::destroyAllWindows(); return 1; //testL2(); //if (TRUE) { // return 0; //} //Win32Util::moveWin(HWND(0x000508D8), 0, 0, 1920, 1080); //return 0; cout << "开始程序" << endl; ImgUtil::init(); THSActionUtil::updateMainSite(); TradeListCapture *manager = new TradeListCapture(); manager->init(NULL, NULL,NULL); for (int i = 0; i < 10; i++) { manager->captureTradeSuccessInfo(); Sleep(2000); } //TradeQueueCapture* manager = new TradeQueueCapture(); //manager->recognition_buy_1_volumn(HWND(0x00020F28)); Sleep(1000); 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> 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 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 list1 = ImgUtil::splitNum(cv::imread(path.c_str(), cv::IMREAD_GRAYSCALE)); list resultList= recognitionManager->recognitionGPCode(list1); list::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(); //图像分割 list 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 list = THSActionUtil::recognitionGPArea(img); std::list::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 list2 = ImgUtil::splitNum(nums); std::list resultList = recognitionManager->recognitionGPCode(list2); std::list::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; } } }