| | |
| | | #include "TaskChecker.h" |
| | | #include "GPUtil.h" |
| | | #include "LogUtil.h" |
| | | #include "L2TradeQueueUtil.h" |
| | | |
| | | //#define malloc(size) malloc(size) |
| | | //#define free(ptr) free(ptr) |
| | |
| | | bool L2DataCapture::tradeTimeCapture; |
| | | |
| | | OpenCLExcuter* L2DataCapture::openCLExcuter[THS_FRAME_COUNT]; |
| | | OpenCLExcuter* L2DataCapture::openCLExcuterQueue[THS_FRAME_COUNT]; |
| | | |
| | | TradeQueueCapture* L2DataCapture::tradeQueueCapture[THS_FRAME_COUNT]; |
| | | |
| | | |
| | |
| | | Sleep(2); |
| | | continue; |
| | | } |
| | | } |
| | | |
| | | if (GPUtil::isBeforeTradeTime()) { |
| | | Sleep(1000); |
| | | } |
| | | |
| | | if (running && runnings[index] && gpCodes[index].length() > 0) { |
| | |
| | | void L2DataCapture::_run_trade_queue(int index) |
| | | { |
| | | while (true) { |
| | | if (killRunnings[index]) |
| | | break; |
| | | TaskChecker::clientLiveTime.l2[index] = clock(); |
| | | if (tradeTimeCapture) { |
| | | if (!GPUtil::isTradeTime()) { |
| | | Sleep(2); |
| | | continue; |
| | | } |
| | | } |
| | | |
| | | if (GPUtil::isBeforeTradeTime()) { |
| | | Sleep(1000); |
| | | } |
| | | |
| | | if (running && runnings[index] && gpCodes[index].length() > 0) { |
| | | //识别数据 |
| | | string code = gpCodes[index]; |
| | | try { |
| | | list<int> numList;//= tradeQueueCapture[index]->recognition(CaptureUtil::getHWND(index, CAPTURE_TYPE_TRADE_QUEUE)); |
| | | trade_queue_data_callback(index, code, numList, context); |
| | | clock_t start = clock(); |
| | | cv::Mat mat = CaptureUtil::capture(index, CAPTURE_TYPE_TRADE_QUEUE); |
| | | if (mat.cols <= 400 || mat.rows <= 30) { |
| | | mat.release(); |
| | | mat = NULL; |
| | | Sleep(100); |
| | | throw string("截图出错"); |
| | | } |
| | | |
| | | L2TradeQueue result = captureLevel2TradeQueueData(mat, index); |
| | | long processTime = clock() - start; |
| | | cout << "时间消耗:" << processTime << endl; |
| | | trade_queue_data_callback(index, code, result, context); |
| | | } |
| | | catch (...) { |
| | | |
| | |
| | | { |
| | | openCLExcuter[i] = new OpenCLExcuter(); |
| | | openCLExcuter[i]->init(); |
| | | openCLExcuterQueue[i]= new OpenCLExcuter(); |
| | | openCLExcuterQueue[i]->init(); |
| | | |
| | | tradeQueueCapture[i] = new TradeQueueCapture(); |
| | | } |
| | | |
| | |
| | | thread rt(&(L2DataCapture::_run), i); |
| | | rt.detach(); |
| | | killRunnings[i] = FALSE; |
| | | //thread rt_trade_queue(&(L2DataCapture::_run_trade_queue), i); |
| | | //rt_trade_queue.detach(); |
| | | thread rt_trade_queue(&(L2DataCapture::_run_trade_queue), i); |
| | | rt_trade_queue.detach(); |
| | | } |
| | | |
| | | //获取同花顺窗口句柄 |
| | |
| | | |
| | | return resultList; |
| | | } |
| | | |
| | | |
| | | list<TradeData> L2DataCapture::captureLevel2TradeData(OpenCLExcuter* openCLExcuter, cv::Mat& oimg, int identify) |
| | | { |
| | |
| | | return resultList; |
| | | } |
| | | |
| | | L2TradeQueue L2DataCapture::captureLevel2TradeQueueData(HWND hwnd, int index) |
| | | { |
| | | cv::Mat mat = CaptureUtil::capture(hwnd); |
| | | return captureLevel2TradeQueueData(mat,index); |
| | | } |
| | | |
| | | L2TradeQueue L2DataCapture::captureLevel2TradeQueueData(cv::Mat& oimg, int identify) |
| | | { |
| | | return captureLevel2TradeQueueData(openCLExcuterQueue[identify],oimg,identify); |
| | | } |
| | | |
| | | L2TradeQueue L2DataCapture::captureLevel2TradeQueueData(OpenCLExcuter* openCLExcuter, cv::Mat& oimg, int identify) |
| | | { |
| | | cv::Mat img = cv::Mat::zeros(oimg.rows, oimg.cols, CV_8UC1); |
| | | |
| | | if (oimg.channels() == 1) { |
| | | //黑白图片 |
| | | img.data = oimg.data; |
| | | } |
| | | else { |
| | | try { |
| | | if (oimg.channels() == 3) |
| | | { |
| | | openCLExcuter->rgb2Gray(oimg, img.data); |
| | | } |
| | | else { |
| | | openCLExcuter->rgba2Gray(oimg, img.data); |
| | | } |
| | | oimg.release(); |
| | | } |
| | | catch (...) { |
| | | oimg.release(); |
| | | oimg = NULL; |
| | | img.release(); |
| | | img = NULL; |
| | | throw string("灰度出错"); |
| | | } |
| | | } |
| | | |
| | | |
| | | try { |
| | | list<ImgArea> splitAreas = L2TradeQueueUtil::splitElements(img); |
| | | int* splitResult = (int*)malloc(sizeof(int) * 4 * 6); |
| | | int index = 0; |
| | | for (list<ImgArea>::iterator ele = splitAreas.begin(); ele != splitAreas.end(); ++ele) { |
| | | ImgArea area = *ele; |
| | | if (area.startx < 0) { |
| | | splitResult[index * 4 + 0] = 0; |
| | | splitResult[index * 4 + 1] = 0; |
| | | splitResult[index * 4 + 2] = 0; |
| | | splitResult[index * 4 + 3] = 0; |
| | | } |
| | | else { |
| | | splitResult[index * 4 + 0] = area.startx; |
| | | splitResult[index * 4 + 1] = area.starty; |
| | | splitResult[index * 4 + 2] = area.endx; |
| | | splitResult[index * 4 + 3] = area.endy; |
| | | } |
| | | index++; |
| | | } |
| | | |
| | | |
| | | |
| | | clock_t time_2 = clock(); |
| | | unsigned char* zeroData = (unsigned char*)malloc(sizeof(unsigned char) * _NUMBER_GP_CODE_WIDTH * _NUMBER_GP_CODE_HEIGHT); |
| | | for (int r = 0; r < _NUMBER_GP_CODE_HEIGHT; r++) { |
| | | for (int c = 0; c < _NUMBER_GP_CODE_WIDTH; c++) |
| | | { |
| | | zeroData[r * _NUMBER_GP_CODE_WIDTH + c] = ImgUtil::NUMS_GP_CODE[0].data.ptr<uchar>(r)[c]; |
| | | } |
| | | } |
| | | int num_length_per_ele = 6; |
| | | int ele_count_per_line = 6; |
| | | int line_number_count = ele_count_per_line * num_length_per_ele; |
| | | unsigned char* totalNumberData = (unsigned char*)malloc(sizeof(unsigned char) * (_NUMBER_GP_CODE_HEIGHT * 1) * _NUMBER_GP_CODE_WIDTH * 10 * line_number_count); |
| | | unsigned char types[] = { NUM_TYPE_TIME,NUM_TYPE_TIME,NUM_TYPE_PRICE, NUM_TYPE_NUM_SHOU,NUM_TYPE_PRICE, NUM_TYPE_NUM_SHOU }; |
| | | UcharDataInfo typesData = UcharDataInfo(); |
| | | typesData.length = 6; |
| | | typesData.data = types; |
| | | |
| | | openCLExcuter->splitPlateNum(img, IntDataInfo({ splitResult,(int)(ele_count_per_line * 1) }), UcharDataInfo({ totalNumberData, -1 }), typesData, zeroData, _NUMBER_GP_CODE_WIDTH, _NUMBER_GP_CODE_HEIGHT, ele_count_per_line, num_length_per_ele); |
| | | free(splitResult); |
| | | free(zeroData); |
| | | |
| | | //识别 |
| | | uchar* templateNums = (unsigned char*)malloc(sizeof(unsigned char) * (_NUMBER_GP_CODE_HEIGHT * 1) * _NUMBER_GP_CODE_WIDTH * 10 * line_number_count); |
| | | try { |
| | | openCLExcuter->createNumberTemplates(1, _NUMBER_GP_CODE_WIDTH, _NUMBER_GP_CODE_HEIGHT, line_number_count, ImgUtil::numsOneLevel_gpcode, templateNums); |
| | | } |
| | | catch (...) { |
| | | free(totalNumberData); |
| | | free(templateNums); |
| | | throw string("创建数据模板出错"); |
| | | } |
| | | |
| | | |
| | | uchar** numberResult = nullptr; |
| | | //数字识别 |
| | | try { |
| | | numberResult = openCLExcuter->recognition_numbers(totalNumberData, templateNums, 1 * _NUMBER_GP_CODE_HEIGHT, _NUMBER_GP_CODE_WIDTH * 10 * line_number_count, _NUMBER_GP_CODE_WIDTH, _NUMBER_GP_CODE_HEIGHT, line_number_count); |
| | | //释放内存 |
| | | free(totalNumberData); |
| | | free(templateNums); |
| | | } |
| | | catch (...) { |
| | | //释放内存 |
| | | free(totalNumberData); |
| | | free(templateNums); |
| | | throw string("数字识别出错"); |
| | | } |
| | | |
| | | img.release(); |
| | | |
| | | //循环读取数字 |
| | | uchar* lineData = numberResult[0]; |
| | | string sellOneTime = ""; |
| | | sellOneTime.append(to_string(lineData[0])).append(to_string(lineData[1])); |
| | | sellOneTime.append(":"); |
| | | sellOneTime.append(to_string(lineData[2])).append(to_string(lineData[3])); |
| | | sellOneTime.append(":"); |
| | | sellOneTime.append(to_string(lineData[4])).append(to_string(lineData[5])); |
| | | |
| | | string buyOneTime = ""; |
| | | buyOneTime.append(to_string(lineData[6])).append(to_string(lineData[7])); |
| | | buyOneTime.append(":"); |
| | | buyOneTime.append(to_string(lineData[8])).append(to_string(lineData[9])); |
| | | buyOneTime.append(":"); |
| | | buyOneTime.append(to_string(lineData[10])).append(to_string(lineData[11])); |
| | | |
| | | |
| | | string sellOnePrice = ""; |
| | | for (int i = 0; i < 6; i++) |
| | | { |
| | | sellOnePrice.append(to_string(lineData[12 + i])); |
| | | if (i == 3) { |
| | | sellOnePrice.append("."); |
| | | } |
| | | } |
| | | |
| | | string sellOneNum = ""; |
| | | for (int i = 0; i < 6; i++) |
| | | { |
| | | sellOneNum.append(to_string(lineData[18 + i])); |
| | | } |
| | | |
| | | string buyOnePrice = ""; |
| | | for (int i = 0; i < 6; i++) |
| | | { |
| | | buyOnePrice.append(to_string(lineData[24 + i])); |
| | | if (i == 3) { |
| | | buyOnePrice.append("."); |
| | | } |
| | | } |
| | | |
| | | string buyOneNum = ""; |
| | | for (int i = 0; i < 6; i++) |
| | | { |
| | | buyOneNum.append(to_string(lineData[30 + i])); |
| | | } |
| | | |
| | | //释放内存 |
| | | free(lineData); |
| | | index++; |
| | | free(numberResult); |
| | | |
| | | |
| | | L2TradeQueue tradeQueue = L2TradeQueue(); |
| | | tradeQueue.buyOnePrice = buyOnePrice; |
| | | tradeQueue.buyOneVolumn = buyOneNum; |
| | | tradeQueue.buyTime = buyOneTime; |
| | | tradeQueue.sellOnePrice = sellOnePrice; |
| | | tradeQueue.sellOneVolumn = sellOneNum; |
| | | tradeQueue.sellTime = sellOneTime; |
| | | return tradeQueue; |
| | | } |
| | | catch (...) { |
| | | img.release(); |
| | | img = NULL; |
| | | throw int(ERROR_CODE_DIVIDE_IMG_FAIL); |
| | | } |
| | | |
| | | } |
| | | |
| | | //捕获level2的盘口数据 |
| | | list<TradeData> L2DataCapture::captureLevel2TradeData(HWND hwnd, int index) throw(int) { |
| | | clock_t starttime = clock(); |