From 8b06b1cbf112d55307ea8a6efe711db4e7506d89 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 07 三月 2023 10:13:47 +0800 Subject: [PATCH] 'GPU内核方法优化' --- ConsoleApplication/L2DataCapture.cpp | 47 +++++++++++++++++++++++++++++------------------ 1 files changed, 29 insertions(+), 18 deletions(-) diff --git a/ConsoleApplication/L2DataCapture.cpp b/ConsoleApplication/L2DataCapture.cpp index 803303c..8054f11 100644 --- a/ConsoleApplication/L2DataCapture.cpp +++ b/ConsoleApplication/L2DataCapture.cpp @@ -40,6 +40,7 @@ { while (true) { + clock_t origin_start_time = clock(); if (killRunnings[index]) break; @@ -80,7 +81,7 @@ list<TradeData*> resultList = captureLevel2TradeData(mat, index); if (index == 0) { - cout << "-----------识别时间消耗:---------- " << index << " " << clock() - start << endl; + cout << "-----------识别时间消耗:---------- " << index <<" 数量:"<< resultList.size() << " " << clock() - start << endl; } long processTime = clock() - origin_start_time; start = clock(); @@ -151,7 +152,7 @@ } } - Sleep(50); + Sleep(600); } } @@ -194,7 +195,10 @@ int ele_count_per_line = splitAreas.size(); 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_NUM,NUM_TYPE_NUM,NUM_TYPE_NUM,NUM_TYPE_NUM,NUM_TYPE_NUM,NUM_TYPE_NUM,NUM_TYPE_NUM,NUM_TYPE_NUM,NUM_TYPE_NUM,NUM_TYPE_NUM,NUM_TYPE_NUM,NUM_TYPE_NUM,NUM_TYPE_NUM,NUM_TYPE_NUM,NUM_TYPE_NUM,NUM_TYPE_NUM,NUM_TYPE_NUM,NUM_TYPE_NUM }; + unsigned char types[24]; + for (int i = 0; i < 24; i++) { + types[i] = NUM_TYPE_NUM; + } UcharDataInfo typesData = UcharDataInfo(); typesData.length = ele_count_per_line; typesData.data = types; @@ -465,6 +469,8 @@ clock_t time_2 = clock(); + int ele_count_per_line = 7; + //图像分割---开始 @@ -494,7 +500,7 @@ free(indexs); } //一维按行切分图像数据 - int* rowSplitDataOneLevel = (int*)malloc(sizeof(int) * rowDataList.size() * 4 * 7); + int* rowSplitDataOneLevel = (int*)malloc(sizeof(int) * rowDataList.size() * 4 * ele_count_per_line); try { openCLExcuter->splitL2RowData(img, rowDataOneLevel, rowDataList.size(), rowSplitDataOneLevel); free(rowDataOneLevel); @@ -524,18 +530,18 @@ } */ - /* + //保存分隔的图片 - if (true) { - int start = 4 * 7 * (558 - 1); - start += 4 * (2); - int startx= rowSplitDataOneLevel[start]; - int starty = rowSplitDataOneLevel[start+1]; - int endx = rowSplitDataOneLevel[start+2]; - int endy = rowSplitDataOneLevel[start+3]; - cv::imshow("价格", cv::Mat(img, cv::Rect(startx, starty, endx - startx + 1, endy - starty + 1))); + if (false) { + int start = 4 * ele_count_per_line * (138); + start += 4 * (1); + int startx = 385;//rowSplitDataOneLevel[start]; + int starty = 1071;//rowSplitDataOneLevel[start + 1]; + int endx = 389;//rowSplitDataOneLevel[start + 2]; + int endy = 1078;//rowSplitDataOneLevel[start + 3]; + cv::imwrite(string("C:\\Users\\Administrator\\Desktop\\ocr\\l2分析\\test.png"), cv::Mat(img, cv::Rect(startx, starty, endx - startx + 1, endy - starty + 1))); } - */ + @@ -556,7 +562,7 @@ //图像识别(除开数字的部分) int* notNumberResult = (int*)malloc(sizeof(int) * rowDataList.size() * 3); - openCLExcuter->recognitionNotNum(img.data, img.cols, img.rows, rowSplitDataOneLevel, 7, rowDataList.size(), notNumberResult); + openCLExcuter->recognitionNotNum(img.data, img.cols, img.rows, rowSplitDataOneLevel, ele_count_per_line, rowDataList.size(), notNumberResult); int i = 0; @@ -632,7 +638,7 @@ index = 0; for (e = rowDataList.begin(); e != rowDataList.end(); e++) { - int startS = index * 4 * 7; + int startS = index * 4 * ele_count_per_line; int start = index * 4 * 4; @@ -673,6 +679,7 @@ if (identify == 0 && ENABLE_LOG) std::cout << "数据准备-位置数据准备: threadid-" << std::this_thread::get_id() << " 耗时:" << time_32 - time_31 << "总耗时:" << time_32 - time_1 << endl; + // TODO 变成全局 unsigned char* zeroData = (unsigned char*)malloc(sizeof(unsigned char) * _NUMBER_L2_WIDTH * _NUMBER_L2_HEIGHT); for (int r = 0; r < _NUMBER_L2_HEIGHT; r++) { for (int c = 0; c < _NUMBER_L2_WIDTH; c++) @@ -695,6 +702,12 @@ free(totalNumberData); throw string("splitL2Num出错"); } + + //测试,展示图像 + //cv::Mat imgTest = cv::Mat::zeros(_NUMBER_L2_HEIGHT * rowDataList.size(), _NUMBER_L2_WIDTH * 10 * _NUMBER_L2_TOTAL_NUMBER, CV_8UC1); + //imgTest.data = totalNumberData; + //cv::imwrite("C:\\Users\\Administrator\\Desktop\\ocr\\l2分析\\test1.png", imgTest); + @@ -720,7 +733,6 @@ free(totalNumberData); free(templateNums); throw string("创建数据模板出错"); - } //ImgUtil::createTemplateNumData(data.size()); @@ -773,7 +785,6 @@ string cancelTime = ""; cancelTime.append(to_string(lineData[6])).append(to_string(lineData[7])); - string price = ""; price.append(to_string(lineData[6 + 2])).append(to_string(lineData[7 + 2])).append(to_string(lineData[8 + 2])).append(to_string(lineData[9 + 2])); -- Gitblit v1.8.0