| | |
| | | uchar* imgData = (uchar*)malloc(sizeof(uchar) * oimg.rows * oimg.cols); |
| | | if (oimg.channels() == 3) |
| | | { |
| | | openCLExcuter->rgb2Gray(oimg.data, oimg.cols, oimg.rows, imgData); |
| | | openCLExcuter->rgb2Gray(oimg, imgData); |
| | | } |
| | | else { |
| | | openCLExcuter->rgba2Gray(oimg.data, oimg.cols, oimg.rows, imgData); |
| | | openCLExcuter->rgba2Gray(oimg, imgData); |
| | | } |
| | | grayImg.data = imgData; |
| | | |
| | | |
| | | |
| | | list<int*> rowData = THSActionUtil::splitPlateRowArea(grayImg); |
| | | list<int*> rowData; |
| | | try { |
| | | rowData = THSActionUtil::splitPlateRowArea(grayImg); |
| | | } |
| | | catch (string st) { |
| | | free(imgData); |
| | | throw st; |
| | | } |
| | | |
| | | //每行的元素个数 |
| | | int ele_count_per_line = 3; |
| | |
| | | |
| | | int line_number_count = ele_count_per_line * length_per_num; |
| | | |
| | | openCLExcuter->splitPlateContentRowData(grayImg.data, grayImg.cols, grayImg.rows, rowIndex, rowData.size(), ele_count_per_line,1,4,splitResult); |
| | | openCLExcuter->splitPlateContentRowData(grayImg.data, grayImg.cols, grayImg.rows, rowIndex, rowData.size(), ele_count_per_line,1,3,splitResult); |
| | | |
| | | /* |
| | | *测试 |
| | |
| | | int x = wrect.right - 50; |
| | | int y = wrect.top + 50; |
| | | PostMessage(win, WM_MOUSEWHEEL, 0, MAKEWORD(x, y)); |
| | | Sleep(150); |
| | | Sleep(1000); |
| | | cv::Mat oimg = CaptureUtil::capture(win); |
| | | list<CurrentPriceData> codes = capture(oimg,openCLExcuter); |
| | | for (list<CurrentPriceData>::iterator ele = codes.begin();ele != codes.end();ele++) { |
| | |
| | | uchar* imgData = (uchar*)malloc(sizeof(uchar) * oimg.rows * oimg.cols); |
| | | if (oimg.channels() == 3) |
| | | { |
| | | openCLExcuter->rgb2Gray(oimg.data, oimg.cols, oimg.rows, imgData); |
| | | openCLExcuter->rgb2Gray(oimg, imgData); |
| | | } |
| | | else { |
| | | openCLExcuter->rgba2Gray(oimg.data, oimg.cols, oimg.rows, imgData); |
| | | openCLExcuter->rgba2Gray(oimg, imgData); |
| | | } |
| | | grayImg.data = imgData; |
| | | |
| | |
| | | img.data = oimg.data; |
| | | } |
| | | else { |
| | | if (oimg.channels() == 3) |
| | | { |
| | | openCLExcuter->rgb2Gray(oimg.data, oimg.cols, oimg.rows, imgData); |
| | | try { |
| | | if (oimg.channels() == 3) |
| | | { |
| | | openCLExcuter->rgb2Gray(oimg, imgData); |
| | | } |
| | | else { |
| | | openCLExcuter->rgba2Gray(oimg, imgData); |
| | | } |
| | | } |
| | | else { |
| | | openCLExcuter->rgba2Gray(oimg.data, oimg.cols, oimg.rows, imgData); |
| | | catch (...) { |
| | | |
| | | cv::imwrite("D:\\imgs\\l2.png", oimg); |
| | | |
| | | if (imgData != NULL) |
| | | { |
| | | free(imgData); |
| | | } |
| | | imgData = NULL; |
| | | oimg.release(); |
| | | throw string("灰度出错"); |
| | | } |
| | | img.data = imgData; |
| | | oimg.release(); |
| | |
| | | catch (...) { |
| | | //释放内存 |
| | | free(imgData); |
| | | imgData = NULL; |
| | | |
| | | throw int(ERROR_CODE_DIVIDE_IMG_FAIL); |
| | | } |
| | | //一维行图像数据 |
| | |
| | | index++; |
| | | free(indexs); |
| | | } |
| | | //一维分块图像数据 |
| | | //一维按行切分图像数据 |
| | | int* rowSplitDataOneLevel = (int*)malloc(sizeof(int) * rowDataList.size() * 4 * 7); |
| | | openCLExcuter->splitL2RowData(imgData, img.cols, img.rows, rowDataOneLevel, rowDataList.size(), rowSplitDataOneLevel); |
| | | free(rowDataOneLevel); |
| | | try { |
| | | openCLExcuter->splitL2RowData(img, rowDataOneLevel, rowDataList.size(), rowSplitDataOneLevel); |
| | | free(rowDataOneLevel); |
| | | } |
| | | catch (...) { |
| | | free(rowDataOneLevel); |
| | | free(rowSplitDataOneLevel); |
| | | free(imgData); |
| | | throw string("图片分隔出错"); |
| | | } |
| | | |
| | | |
| | | /* |
| | | for (int i = 0;i < rowDataList.size();i++) { |
| | |
| | | |
| | | HWND LimitUpCapture::menuWin; |
| | | |
| | | |
| | | |
| | | RecognitionManager* LimitUpCapture::recognitionManager; |
| | | |
| | | HWND getWindow() { |
| | | return THSActionUtil::getThirdWindow(); |
| | | HWND win = THSActionUtil::getThirdWindow(); |
| | | if (win <= 0) { |
| | | win = THSActionUtil::getSecondWindow(); |
| | | } |
| | | return win; |
| | | } |
| | | |
| | | void LimitUpCapture::_run() { |
| | |
| | | TaskChecker::clientLiveTime.limitUp = clock(); |
| | | if (running && inited) { |
| | | clock_t start = clock(); |
| | | list<LimitUpData> codes = captureLimitUpCodes(); |
| | | cout << "耗时:" << clock() - start << " 数量:" << codes.size() << endl; |
| | | data_callback(codes, context); |
| | | codes.clear(); |
| | | try { |
| | | list<LimitUpData> codes = captureLimitUpCodes(); |
| | | cout << "耗时:" << clock() - start << " 数量:" << codes.size() << endl; |
| | | data_callback(codes, context); |
| | | codes.clear(); |
| | | } |
| | | catch (...) { |
| | | |
| | | } |
| | | Sleep(3000); |
| | | } |
| | | else { |
| | |
| | | context = contex; |
| | | running = false; |
| | | kill = false; |
| | | recognitionManager = new RecognitionManager(); |
| | | openCLExcuter = new OpenCLExcuter(); |
| | | openCLExcuter->init(); |
| | | thread rt(&(LimitUpCapture::_run)); |
| | |
| | | if (hwnd <= 0) |
| | | throw string("同花顺副屏2未打开"); |
| | | //输入快捷键51定位到我的版块 |
| | | Win32Util::showWindow(hwnd); |
| | | Win32Util::focus(hwnd); |
| | | Win32Util::keyboardNum("51", 200); |
| | | Win32Util::keyboard(VK_RETURN, 1000); |
| | |
| | | string path = "C:\\Users\\Administrator\\Desktop\\ocr\\menu\\"; |
| | | path.append("menu_").append(to_string(count)).append(".jpg"); |
| | | |
| | | cv::imwrite(path, cv::Mat(grayImg,cv::Rect(0,end_row,grayImg.cols,start_row-end_row))); |
| | | //cv::imwrite(path, cv::Mat(grayImg,cv::Rect(0,end_row,grayImg.cols,start_row-end_row))); |
| | | |
| | | pointList.push_back(cv::Point( ( 0 + grayImg.cols)/2, (start_row + end_row)/2)); |
| | | if (pointList.size() >= 2) { |
| | |
| | | cv::Mat grayImg = cv::Mat::zeros(oimg.rows, oimg.cols, CV_8UC1);//ImgUtil::grayImage(oimg); |
| | | |
| | | uchar* imgData = (uchar*)malloc(sizeof(uchar) * oimg.rows * oimg.cols); |
| | | if (oimg.channels() == 3) |
| | | { |
| | | openCLExcuter->rgb2Gray(oimg.data, oimg.cols, oimg.rows, imgData); |
| | | try { |
| | | if (oimg.channels() == 3) |
| | | { |
| | | openCLExcuter->rgb2Gray(oimg, imgData); |
| | | } |
| | | else { |
| | | openCLExcuter->rgba2Gray(oimg, imgData); |
| | | } |
| | | } |
| | | else { |
| | | openCLExcuter->rgba2Gray(oimg.data, oimg.cols, oimg.rows, imgData); |
| | | catch (...) { |
| | | //保存原始图片 |
| | | //string path = "D:\\imgs\\img.png"; |
| | | //cv::imwrite(path, oimg); |
| | | oimg.release(); |
| | | free(imgData); |
| | | imgData = NULL; |
| | | throw string("灰度出错"); |
| | | } |
| | | grayImg.data = imgData; |
| | | |
| | | |
| | | |
| | | list<int*> rowData = THSActionUtil::splitPlateRowArea(grayImg); |
| | | list<int*> rowData; |
| | | |
| | | try { |
| | | rowData = THSActionUtil::splitPlateRowArea(grayImg); |
| | | } |
| | | catch (string st) { |
| | | free(imgData); |
| | | throw st; |
| | | } |
| | | |
| | | //每行的元素个数 |
| | | int ele_count_per_line = 5; |
| | |
| | | uchar* templateNums = (unsigned char*)malloc(sizeof(unsigned char) * (_NUMBER_GP_CODE_HEIGHT * rowData.size()) * _NUMBER_GP_CODE_WIDTH * 10 * line_number_count); |
| | | openCLExcuter->createNumberTemplates(rowData.size(), _NUMBER_GP_CODE_WIDTH, _NUMBER_GP_CODE_HEIGHT, line_number_count, ImgUtil::numsOneLevel_gpcode, templateNums); |
| | | uchar** numberResult = openCLExcuter->recognition_numbers(totalNumberData, templateNums, rowData.size() * _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); |
| | | |
| | | list<LimitUpData> dataList; |
| | | for (int i = 0;i < rowData.size();i++) { |
| | |
| | | if (kill) { |
| | | break; |
| | | } |
| | | //暂停 |
| | | while (pause) { |
| | | cout <<"涨停识别暂停"<< endl; |
| | | Sleep(100); |
| | | } |
| | | //暂停 暂时注释掉 |
| | | //while (pause) { |
| | | // cout <<"涨停识别暂停"<< endl; |
| | | // Sleep(100); |
| | | //} |
| | | int x = (*ele).x;//+ menuRect.left; |
| | | int y = (*ele).y;//+ menuRect.top; |
| | | printf("x:%d y:%d\n", x, y); |
| | | PostMessage(menuWin, WM_LBUTTONDOWN, 0, MAKELONG(x, y)); |
| | | Sleep(10); |
| | | PostMessage(menuWin, WM_LBUTTONUP, 0, MAKELONG(x, y)); |
| | | //SendMessage(menuWin, WM_SETCURSOR,(int) menuWin, 0x02000001); |
| | | //Win32Util::focus(menuWin); |
| | | //Win32Util::click(x, y); |
| | | Sleep(50); |
| | | |
| | | for (int i = 0;i < 2;i++) |
| | |
| | | cv::Mat oimg = CaptureUtil::capture(win); |
| | | try { |
| | | list<LimitUpData> codes = captureLimitUpCodes(oimg); |
| | | for (list<LimitUpData>::iterator ele = codes.begin();ele != codes.end();ele++) { |
| | | string code = (*ele).code; |
| | | for (list<LimitUpData>::iterator e = codes.begin();e != codes.end();e++) { |
| | | string code = (*e).code; |
| | | if (codesSet.count(code) == 0) { |
| | | codesSet.insert(code); |
| | | flist.push_back(*ele); |
| | | flist.push_back(*e); |
| | | } |
| | | } |
| | | codes.clear(); |
| | |
| | | //交易时段识别 |
| | | static bool tradeTimeCapture; |
| | | static OpenCLExcuter* openCLExcuter; |
| | | static RecognitionManager* recognitionManager; |
| | | static bool inited; |
| | | //是否正在执行 |
| | | static bool running; |
| | |
| | | } |
| | | |
| | | |
| | | unsigned char** OpenCLExcuter::recognition_numbers(unsigned char* data, unsigned char* b_in, const int rows, const int cols, const int num_width, const int num_height, const int num_count) throw(std::string) { |
| | | unsigned char** OpenCLExcuter::recognition_numbers(unsigned char* data, unsigned char* b_in, const int rows, const int cols, const int num_width, const int num_height, const int line_number_count) throw(std::string) { |
| | | //----------程序正文开始--------- |
| | | auto startexectime = std::chrono::steady_clock::now(); |
| | | const int resultSize = rows * cols / (num_width * num_height); |
| | |
| | | } |
| | | |
| | | int width = cols / num_width; |
| | | |
| | | //设置内核参数 |
| | | error = clSetKernelArg(kernel, 0, sizeof(cl_mem), &memObject1); |
| | | error |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &memObject2); |
| | | error |= clSetKernelArg(kernel, 2, sizeof(int), &width); |
| | | error |= clSetKernelArg(kernel, 3, sizeof(int), &num_width); |
| | | error |= clSetKernelArg(kernel, 4, sizeof(int), &num_height); |
| | | error |= clSetKernelArg(kernel, 5, sizeof(int), &num_count); |
| | | error |= clSetKernelArg(kernel, 5, sizeof(int), &line_number_count); |
| | | error |= clSetKernelArg(kernel, 6, sizeof(cl_mem), &memObject4); |
| | | if (error != CL_SUCCESS) { |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | clReleaseMemObject(memObject4); |
| | | throw string("Error setting kernel arguments!\n"); |
| | | } |
| | | //执行内核 |
| | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | clReleaseMemObject(memObject4); |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | free(result); |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | clReleaseMemObject(memObject4); |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | /* |
| | |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | free(result); |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | clReleaseMemObject(memObject4); |
| | | clReleaseMemObject(memObject21); |
| | | clReleaseMemObject(memObject22); |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | |
| | | if (error != CL_SUCCESS) { |
| | | free(result); |
| | | free(result2); |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | clReleaseMemObject(memObject4); |
| | | clReleaseMemObject(memObject21); |
| | | clReleaseMemObject(memObject22); |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | |
| | |
| | | clReleaseMemObject(memObject22); |
| | | |
| | | //复制最后的计算结果 |
| | | int fcol = num_count; |
| | | int fcol = line_number_count; |
| | | int frow = rows / num_height; |
| | | unsigned char** fresult = (unsigned char**)malloc(sizeof(unsigned char*) * frow); |
| | | |
| | |
| | | throw string("Creat memObject5 failed!\n"); |
| | | } |
| | | |
| | | //设置内核参数 |
| | | error = clSetKernelArg(kernel, 0, sizeof(cl_mem), &memObject1); |
| | | error |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &memObject2); |
| | | error |= clSetKernelArg(kernel, 2, sizeof(cl_mem), &memObject3); |
| | | error |= clSetKernelArg(kernel, 3, sizeof(cl_mem), &memObject5); |
| | | error |= clSetKernelArg(kernel, 4, sizeof(int), &img.cols); |
| | | error |= clSetKernelArg(kernel, 5, sizeof(int), &num_width); |
| | | error |= clSetKernelArg(kernel, 6, sizeof(int), &num_height); |
| | | error |= clSetKernelArg(kernel, 7, sizeof(int), &ele_count_per_line); |
| | | error |= clSetKernelArg(kernel, 8, sizeof(int), &length_per_num); |
| | | error |= clSetKernelArg(kernel, 9, sizeof(cl_mem), &memObject4); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error setting kernel arguments!\n"); |
| | | try { |
| | | |
| | | //设置内核参数 |
| | | error = clSetKernelArg(kernel, 0, sizeof(cl_mem), &memObject1); |
| | | error |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &memObject2); |
| | | error |= clSetKernelArg(kernel, 2, sizeof(cl_mem), &memObject3); |
| | | error |= clSetKernelArg(kernel, 3, sizeof(cl_mem), &memObject5); |
| | | error |= clSetKernelArg(kernel, 4, sizeof(int), &img.cols); |
| | | error |= clSetKernelArg(kernel, 5, sizeof(int), &num_width); |
| | | error |= clSetKernelArg(kernel, 6, sizeof(int), &num_height); |
| | | error |= clSetKernelArg(kernel, 7, sizeof(int), &ele_count_per_line); |
| | | error |= clSetKernelArg(kernel, 8, sizeof(int), &length_per_num); |
| | | error |= clSetKernelArg(kernel, 9, sizeof(cl_mem), &memObject4); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error setting kernel arguments!\n"); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { pos.length }; |
| | | size_t localWorkSize[1] = { 1 }; |
| | | |
| | | const int work_dim = 1; |
| | | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject4, CL_TRUE, 0, resultSize * sizeof(unsigned char), |
| | | result.data, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | clReleaseMemObject(memObject3); |
| | | clReleaseMemObject(memObject4); |
| | | clReleaseMemObject(memObject5); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { pos.length }; |
| | | size_t localWorkSize[1] = { 1 }; |
| | | |
| | | const int work_dim = 1; |
| | | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | catch (string st) { |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | clReleaseMemObject(memObject3); |
| | | clReleaseMemObject(memObject4); |
| | | clReleaseMemObject(memObject5); |
| | | throw st; |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject4, CL_TRUE, 0, resultSize * sizeof(unsigned char), |
| | | result.data, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | |
| | | |
| | | |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | clReleaseMemObject(memObject3); |
| | | clReleaseMemObject(memObject4); |
| | | clReleaseMemObject(memObject5); |
| | | std::cout << " 耗时:" << (clock() - time_0) << std::endl; |
| | | } |
| | | |
| | | |
| | | void OpenCLExcuter::splitTradeQueueNum(cv::Mat img, IntDataInfo pos, UcharDataInfo result, UcharDataInfo types, unsigned char* zero, int num_width, int num_height, int ele_count_per_line, int length_per_num) { |
| | | |
| | | |
| | | clock_t time_0 = clock(); |
| | | |
| | | kernel = clCreateKernel(program, "split_trade_queue_num", &error); |
| | | if (kernel == NULL) { |
| | | throw string("Couldn't create kernel!\n"); |
| | | } |
| | | |
| | | int inputSize = (img.cols * img.rows); |
| | | |
| | | int resultSize = pos.length * (length_per_num * 10 * num_width * num_height); |
| | | |
| | | |
| | | //创建缓存对象 |
| | | |
| | | cl_mem memObject1 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(unsigned char) * inputSize, img.data, &error); |
| | | if (error < 0) { |
| | | throw string("Creat memObject1 failed!\n"); |
| | | } |
| | | |
| | | cl_mem memObject2 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, |
| | | sizeof(int) * pos.length * 4, pos.data, &error); |
| | | if (error < 0) { |
| | | throw string("Creat memObject2 failed!\n"); |
| | | } |
| | | |
| | | cl_mem memObject3 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, |
| | | sizeof(unsigned char) * num_width * num_height, zero, &error); |
| | | if (error < 0) { |
| | | throw string("Creat memObject3 failed!\n"); |
| | | } |
| | | |
| | | cl_mem memObject4 = clCreateBuffer(context, CL_MEM_WRITE_ONLY, |
| | | sizeof(unsigned char) * resultSize, NULL, &error); |
| | | if (error < 0) { |
| | | throw string("Creat memObject4 failed!\n"); |
| | | } |
| | | |
| | | |
| | | |
| | | cl_mem memObject5 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, |
| | | sizeof(unsigned char) * types.length, types.data, &error); |
| | | if (error < 0) { |
| | | throw string("Creat memObject5 failed!\n"); |
| | | } |
| | | |
| | | try { |
| | | //设置内核参数 |
| | | error = clSetKernelArg(kernel, 0, sizeof(cl_mem), &memObject1); |
| | | error |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &memObject2); |
| | | error |= clSetKernelArg(kernel, 2, sizeof(cl_mem), &memObject3); |
| | | error |= clSetKernelArg(kernel, 3, sizeof(cl_mem), &memObject5); |
| | | error |= clSetKernelArg(kernel, 4, sizeof(int), &img.cols); |
| | | error |= clSetKernelArg(kernel, 5, sizeof(int), &num_width); |
| | | error |= clSetKernelArg(kernel, 6, sizeof(int), &num_height); |
| | | error |= clSetKernelArg(kernel, 7, sizeof(int), &ele_count_per_line); |
| | | error |= clSetKernelArg(kernel, 8, sizeof(int), &length_per_num); |
| | | error |= clSetKernelArg(kernel, 9, sizeof(cl_mem), &memObject4); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error setting kernel arguments!\n"); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { pos.length }; |
| | | size_t localWorkSize[1] = { 1 }; |
| | | |
| | | const int work_dim = 1; |
| | | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject4, CL_TRUE, 0, resultSize * sizeof(unsigned char), |
| | | result.data, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | clReleaseMemObject(memObject3); |
| | | clReleaseMemObject(memObject4); |
| | | clReleaseMemObject(memObject5); |
| | | } |
| | | catch (string st) { |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | clReleaseMemObject(memObject3); |
| | | clReleaseMemObject(memObject4); |
| | | clReleaseMemObject(memObject5); |
| | | throw st; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | std::cout << " 耗时:" << (clock() - time_0) << std::endl; |
| | | } |
| | | |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | int ele_count_line = 4; |
| | | try { |
| | | //设置内核参数 |
| | | error = clSetKernelArg(kernel, 0, sizeof(cl_mem), &memObject1); |
| | | error |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &memObject2); |
| | | error |= clSetKernelArg(kernel, 2, sizeof(cl_mem), &memObject3); |
| | | error |= clSetKernelArg(kernel, 3, sizeof(cl_mem), &memObject5); |
| | | error |= clSetKernelArg(kernel, 4, sizeof(int), &img_width); |
| | | error |= clSetKernelArg(kernel, 5, sizeof(int), &num_width); |
| | | error |= clSetKernelArg(kernel, 6, sizeof(int), &num_height); |
| | | error |= clSetKernelArg(kernel, 7, sizeof(int), &ele_count_line); |
| | | error |= clSetKernelArg(kernel, 8, sizeof(int), &length_per_num); |
| | | error |= clSetKernelArg(kernel, 9, sizeof(cl_mem), &memObject4); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error setting kernel arguments!\n"); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { pos_count }; |
| | | size_t localWorkSize[1] = { 1 }; |
| | | |
| | | //设置内核参数 |
| | | error = clSetKernelArg(kernel, 0, sizeof(cl_mem), &memObject1); |
| | | error |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &memObject2); |
| | | error |= clSetKernelArg(kernel, 2, sizeof(cl_mem), &memObject3); |
| | | error |= clSetKernelArg(kernel, 3, sizeof(cl_mem), &memObject5); |
| | | error |= clSetKernelArg(kernel, 4, sizeof(int), &img_width); |
| | | error |= clSetKernelArg(kernel, 5, sizeof(int), &num_width); |
| | | error |= clSetKernelArg(kernel, 6, sizeof(int), &num_height); |
| | | error |= clSetKernelArg(kernel, 7, sizeof(int), &ele_count_line); |
| | | error |= clSetKernelArg(kernel, 8, sizeof(int), &length_per_num); |
| | | error |= clSetKernelArg(kernel, 9, sizeof(cl_mem), &memObject4); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error setting kernel arguments!\n"); |
| | | const int work_dim = 1; |
| | | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject4, CL_TRUE, 0, resultSize * sizeof(unsigned char), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | clReleaseMemObject(memObject3); |
| | | clReleaseMemObject(memObject4); |
| | | clReleaseMemObject(memObject5); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { pos_count }; |
| | | size_t localWorkSize[1] = { 1 }; |
| | | |
| | | const int work_dim = 1; |
| | | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject4, CL_TRUE, 0, resultSize * sizeof(unsigned char), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error reading result buffer!\n"); |
| | | catch (string st) { |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | clReleaseMemObject(memObject3); |
| | | clReleaseMemObject(memObject4); |
| | | clReleaseMemObject(memObject5); |
| | | throw st; |
| | | } |
| | | |
| | | |
| | | |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | clReleaseMemObject(memObject3); |
| | | clReleaseMemObject(memObject4); |
| | | clReleaseMemObject(memObject5); |
| | | |
| | | std::cout << " 耗时:" << (clock() - time_0) << std::endl; |
| | | } |
| | | |
| | |
| | | throw string("Creat memObject4 failed!\n"); |
| | | } |
| | | |
| | | //设置内核参数 |
| | | error = clSetKernelArg(kernel, 0, sizeof(cl_mem), &memObject1); |
| | | error |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &memObject2); |
| | | error |= clSetKernelArg(kernel, 2, sizeof(cl_mem), &memObject3); |
| | | error |= clSetKernelArg(kernel, 3, sizeof(int), &img_width); |
| | | error |= clSetKernelArg(kernel, 4, sizeof(int), &num_width); |
| | | error |= clSetKernelArg(kernel, 5, sizeof(int), &num_height); |
| | | error |= clSetKernelArg(kernel, 6, sizeof(int), &num_count); |
| | | error |= clSetKernelArg(kernel, 7, sizeof(cl_mem), &memObject4); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error setting kernel arguments!\n"); |
| | | try { |
| | | //设置内核参数 |
| | | error = clSetKernelArg(kernel, 0, sizeof(cl_mem), &memObject1); |
| | | error |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &memObject2); |
| | | error |= clSetKernelArg(kernel, 2, sizeof(cl_mem), &memObject3); |
| | | error |= clSetKernelArg(kernel, 3, sizeof(int), &img_width); |
| | | error |= clSetKernelArg(kernel, 4, sizeof(int), &num_width); |
| | | error |= clSetKernelArg(kernel, 5, sizeof(int), &num_height); |
| | | error |= clSetKernelArg(kernel, 6, sizeof(int), &num_count); |
| | | error |= clSetKernelArg(kernel, 7, sizeof(cl_mem), &memObject4); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error setting kernel arguments!\n"); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { pos_count }; |
| | | size_t localWorkSize[1] = { 1 }; |
| | | |
| | | const int work_dim = 1; |
| | | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject4, CL_TRUE, 0, resultSize * sizeof(unsigned char), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | clReleaseMemObject(memObject3); |
| | | clReleaseMemObject(memObject4); |
| | | std::cout << " 耗时:" << (clock() - time_0) << std::endl; |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { pos_count }; |
| | | size_t localWorkSize[1] = { 1 }; |
| | | |
| | | const int work_dim = 1; |
| | | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | catch (string st) { |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | clReleaseMemObject(memObject3); |
| | | clReleaseMemObject(memObject4); |
| | | throw st; |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject4, CL_TRUE, 0, resultSize * sizeof(unsigned char), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | |
| | | |
| | | |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | clReleaseMemObject(memObject3); |
| | | clReleaseMemObject(memObject4); |
| | | std::cout << " 耗时:" << (clock() - time_0) << std::endl; |
| | | } |
| | | |
| | | |
| | |
| | | throw string("Creat memObject2 failed!\n"); |
| | | } |
| | | |
| | | try { |
| | | //设置内核参数 |
| | | error = clSetKernelArg(kernel, 0, sizeof(cl_mem), &memObject1); |
| | | error |= clSetKernelArg(kernel, 1, sizeof(int), &num_width); |
| | | error |= clSetKernelArg(kernel, 2, sizeof(int), &num_height); |
| | | error |= clSetKernelArg(kernel, 3, sizeof(int), &num_count); |
| | | error |= clSetKernelArg(kernel, 4, sizeof(cl_mem), &memObject2); |
| | | |
| | | //设置内核参数 |
| | | error = clSetKernelArg(kernel, 0, sizeof(cl_mem), &memObject1); |
| | | error |= clSetKernelArg(kernel, 1, sizeof(int), &num_width); |
| | | error |= clSetKernelArg(kernel, 2, sizeof(int), &num_height); |
| | | error |= clSetKernelArg(kernel, 3, sizeof(int), &num_count); |
| | | error |= clSetKernelArg(kernel, 4, sizeof(cl_mem), &memObject2); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error setting kernel arguments!\n"); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { lines }; |
| | | size_t localWorkSize[1] = { 1 }; |
| | | |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error setting kernel arguments!\n"); |
| | | const int work_dim = 1; |
| | | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject2, CL_TRUE, 0, resultSize * sizeof(unsigned char), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { lines }; |
| | | size_t localWorkSize[1] = { 1 }; |
| | | |
| | | const int work_dim = 1; |
| | | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | catch (string st) { |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | throw st; |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject2, CL_TRUE, 0, resultSize * sizeof(unsigned char), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | } |
| | | |
| | | |
| | | |
| | | void OpenCLExcuter::splitL2RowData(unsigned char* imgs, int imgWidth, int imgHeight, int* rowIndexs, int lines, |
| | | void OpenCLExcuter::splitL2RowData(cv::Mat img, int* rowIndexs, int lines, |
| | | int* result) { |
| | | |
| | | kernel = clCreateKernel(program, "splitL2RowData", &error); |
| | |
| | | } |
| | | |
| | | |
| | | int inputSize = imgWidth * imgHeight; |
| | | int inputSize = img.cols * img.rows; |
| | | int resultSize = lines * 7 * 4; |
| | | |
| | | |
| | | //创建缓存对象 |
| | | |
| | | cl_mem memObject1 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(uchar) * inputSize, imgs, &error); |
| | | cl_mem memObject1 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(uchar) * inputSize, img.data, &error); |
| | | if (error < 0) { |
| | | throw string("Creat memObject1 failed!\n"); |
| | | } |
| | |
| | | throw string("Creat memObject3 failed!\n"); |
| | | } |
| | | |
| | | try { |
| | | //设置内核参数 |
| | | error = clSetKernelArg(kernel, 0, sizeof(cl_mem), &memObject1); |
| | | error = clSetKernelArg(kernel, 1, sizeof(cl_mem), &memObject2); |
| | | error |= clSetKernelArg(kernel, 2, sizeof(int), &img.cols); |
| | | error |= clSetKernelArg(kernel, 3, sizeof(cl_mem), &memObject3); |
| | | |
| | | //设置内核参数 |
| | | error = clSetKernelArg(kernel, 0, sizeof(cl_mem), &memObject1); |
| | | error = clSetKernelArg(kernel, 1, sizeof(cl_mem), &memObject2); |
| | | error |= clSetKernelArg(kernel, 2, sizeof(int), &imgWidth); |
| | | error |= clSetKernelArg(kernel, 3, sizeof(cl_mem), &memObject3); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error setting kernel arguments!\n"); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { lines }; |
| | | size_t localWorkSize[1] = { 1 }; |
| | | |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error setting kernel arguments!\n"); |
| | | const int work_dim = 1; |
| | | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject3, CL_TRUE, 0, resultSize * sizeof(int), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | clReleaseMemObject(memObject3); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { lines }; |
| | | size_t localWorkSize[1] = { 1 }; |
| | | |
| | | const int work_dim = 1; |
| | | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject3, CL_TRUE, 0, resultSize * sizeof(int), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error reading result buffer!\n"); |
| | | catch (string st) { |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | clReleaseMemObject(memObject3); |
| | | throw st; |
| | | } |
| | | |
| | | //printf("%d %d %d %d \n", result[0], result[1], result[2], result[3]); |
| | | |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | clReleaseMemObject(memObject3); |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | throw string("Creat memObject3 failed!\n"); |
| | | } |
| | | |
| | | try { |
| | | //设置内核参数 |
| | | error = clSetKernelArg(kernel, 0, sizeof(cl_mem), &memObject1); |
| | | error = clSetKernelArg(kernel, 1, sizeof(cl_mem), &memObject2); |
| | | error |= clSetKernelArg(kernel, 2, sizeof(int), &imgWidth); |
| | | error |= clSetKernelArg(kernel, 3, sizeof(int), &fromIndex); |
| | | error |= clSetKernelArg(kernel, 4, sizeof(int), &toIndex); |
| | | error |= clSetKernelArg(kernel, 5, sizeof(cl_mem), &memObject3); |
| | | |
| | | //设置内核参数 |
| | | error = clSetKernelArg(kernel, 0, sizeof(cl_mem), &memObject1); |
| | | error = clSetKernelArg(kernel, 1, sizeof(cl_mem), &memObject2); |
| | | error |= clSetKernelArg(kernel, 2, sizeof(int), &imgWidth); |
| | | error |= clSetKernelArg(kernel, 3, sizeof(int), &fromIndex); |
| | | error |= clSetKernelArg(kernel, 4, sizeof(int), &toIndex); |
| | | error |= clSetKernelArg(kernel, 5, sizeof(cl_mem), &memObject3); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error setting kernel arguments!\n"); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { lines }; |
| | | size_t localWorkSize[1] = { 1 }; |
| | | |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error setting kernel arguments!\n"); |
| | | const int work_dim = 1; |
| | | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject3, CL_TRUE, 0, resultSize * sizeof(int), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | clReleaseMemObject(memObject3); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { lines }; |
| | | size_t localWorkSize[1] = { 1 }; |
| | | |
| | | const int work_dim = 1; |
| | | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject3, CL_TRUE, 0, resultSize * sizeof(int), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error reading result buffer!\n"); |
| | | catch (string st) { |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | clReleaseMemObject(memObject3); |
| | | throw st; |
| | | } |
| | | |
| | | //printf("%d %d %d %d \n", result[0], result[1], result[2], result[3]); |
| | | |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | clReleaseMemObject(memObject3); |
| | | |
| | | } |
| | | |
| | | void OpenCLExcuter::recognitionNotNum(unsigned char* imgs, int imgWidth, int imgHeight, int* rowIndexs, int colCount, int lines, |
| | |
| | | throw string("Creat memObject3 failed!\n"); |
| | | } |
| | | |
| | | try { |
| | | //设置内核参数 |
| | | error = clSetKernelArg(kernel, 0, sizeof(cl_mem), &memObject1); |
| | | error = clSetKernelArg(kernel, 1, sizeof(cl_mem), &memObject2); |
| | | error |= clSetKernelArg(kernel, 2, sizeof(int), &imgWidth); |
| | | error |= clSetKernelArg(kernel, 3, sizeof(cl_mem), &memObject3); |
| | | |
| | | //设置内核参数 |
| | | error = clSetKernelArg(kernel, 0, sizeof(cl_mem), &memObject1); |
| | | error = clSetKernelArg(kernel, 1, sizeof(cl_mem), &memObject2); |
| | | error |= clSetKernelArg(kernel, 2, sizeof(int), &imgWidth); |
| | | error |= clSetKernelArg(kernel, 3, sizeof(cl_mem), &memObject3); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error setting kernel arguments!\n"); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { resultSize }; |
| | | size_t localWorkSize[1] = { 1 }; |
| | | |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error setting kernel arguments!\n"); |
| | | const int work_dim = 1; |
| | | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject3, CL_TRUE, 0, resultSize * sizeof(int), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | clReleaseMemObject(memObject3); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { resultSize }; |
| | | size_t localWorkSize[1] = { 1 }; |
| | | |
| | | const int work_dim = 1; |
| | | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject3, CL_TRUE, 0, resultSize * sizeof(int), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error reading result buffer!\n"); |
| | | catch (string st) { |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | clReleaseMemObject(memObject3); |
| | | throw st; |
| | | } |
| | | |
| | | //printf("%d %d %d %d \n", result[0], result[1], result[2], result[3]); |
| | | |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | clReleaseMemObject(memObject3); |
| | | |
| | | |
| | | } |
| | | |
| | |
| | | throw string("Creat memObject3 failed!\n"); |
| | | } |
| | | |
| | | try { |
| | | //设置内核参数 |
| | | error = clSetKernelArg(kernel, 0, sizeof(cl_mem), &memObject1); |
| | | error = clSetKernelArg(kernel, 1, sizeof(cl_mem), &memObject2); |
| | | error |= clSetKernelArg(kernel, 2, sizeof(int), &imgWidth); |
| | | error |= clSetKernelArg(kernel, 3, sizeof(cl_mem), &memObject3); |
| | | |
| | | //设置内核参数 |
| | | error = clSetKernelArg(kernel, 0, sizeof(cl_mem), &memObject1); |
| | | error = clSetKernelArg(kernel, 1, sizeof(cl_mem), &memObject2); |
| | | error |= clSetKernelArg(kernel, 2, sizeof(int), &imgWidth); |
| | | error |= clSetKernelArg(kernel, 3, sizeof(cl_mem), &memObject3); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error setting kernel arguments!\n"); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { resultSize }; |
| | | size_t localWorkSize[1] = { 1 }; |
| | | |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error setting kernel arguments!\n"); |
| | | const int work_dim = 1; |
| | | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject3, CL_TRUE, 0, resultSize * sizeof(int), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | clReleaseMemObject(memObject3); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { resultSize }; |
| | | size_t localWorkSize[1] = { 1 }; |
| | | |
| | | const int work_dim = 1; |
| | | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject3, CL_TRUE, 0, resultSize * sizeof(int), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error reading result buffer!\n"); |
| | | catch (string st) { |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | clReleaseMemObject(memObject3); |
| | | throw st; |
| | | } |
| | | |
| | | //printf("%d %d %d %d \n", result[0], result[1], result[2], result[3]); |
| | | |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | clReleaseMemObject(memObject3); |
| | | |
| | | } |
| | | |
| | | void OpenCLExcuter::rgb2Gray(unsigned char* imgs, int imgWidth, int imgHeight, |
| | | void OpenCLExcuter::rgb2Gray(cv::Mat img, |
| | | unsigned char* result) { |
| | | |
| | | kernel = clCreateKernel(program, "rgb2GrayImg", &error); |
| | |
| | | } |
| | | |
| | | |
| | | int inputSize = imgWidth * imgHeight * 3; |
| | | int resultSize = imgWidth * imgHeight; |
| | | int inputSize = img.cols * img.rows * 3; |
| | | int resultSize = img.cols * img.rows; |
| | | |
| | | |
| | | //创建缓存对象 |
| | | |
| | | cl_mem memObject1 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(uchar) * inputSize, imgs, &error); |
| | | cl_mem memObject1 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(uchar) * inputSize, img.data, &error); |
| | | if (error < 0) { |
| | | throw string("Creat memObject1 failed!\n"); |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | //设置内核参数 |
| | | error = clSetKernelArg(kernel, 0, sizeof(cl_mem), &memObject1); |
| | | error |= clSetKernelArg(kernel, 1, sizeof(int), &imgWidth); |
| | | error = clSetKernelArg(kernel, 2, sizeof(cl_mem), &memObject2); |
| | | try { |
| | | |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error setting kernel arguments!\n"); |
| | | //设置内核参数 |
| | | error = clSetKernelArg(kernel, 0, sizeof(cl_mem), &memObject1); |
| | | error |= clSetKernelArg(kernel, 1, sizeof(int), &img.cols); |
| | | error = clSetKernelArg(kernel, 2, sizeof(cl_mem), &memObject2); |
| | | |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error setting kernel arguments!\n"); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { img.rows }; |
| | | size_t localWorkSize[1] = { 1 }; |
| | | |
| | | const int work_dim = 1; |
| | | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject2, CL_TRUE, 0, resultSize * sizeof(uchar), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { imgHeight }; |
| | | size_t localWorkSize[1] = { 1 }; |
| | | |
| | | const int work_dim = 1; |
| | | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | catch (string st) { |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | throw st; |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject2, CL_TRUE, 0, resultSize * sizeof(uchar), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | |
| | | } |
| | | |
| | | |
| | | void OpenCLExcuter::rgba2Gray(unsigned char* imgs, int imgWidth, int imgHeight, |
| | | void OpenCLExcuter::rgba2Gray(cv::Mat img, |
| | | unsigned char* result) { |
| | | |
| | | kernel = clCreateKernel(program, "rgba2GrayImg", &error); |
| | |
| | | } |
| | | |
| | | |
| | | int inputSize = imgWidth * imgHeight * 4; |
| | | int resultSize = imgWidth * imgHeight; |
| | | int inputSize = img.cols * img.rows * 4; |
| | | int resultSize = img.cols * img.rows; |
| | | |
| | | |
| | | //创建缓存对象 |
| | | |
| | | cl_mem memObject1 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(uchar) * inputSize, imgs, &error); |
| | | cl_mem memObject1 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(uchar) * inputSize, img.data, &error); |
| | | if (error < 0) { |
| | | throw string("Creat memObject1 failed!\n"); |
| | | } |
| | |
| | | throw string("Creat memObject2 failed!\n"); |
| | | } |
| | | |
| | | try { |
| | | |
| | | //设置内核参数 |
| | | error = clSetKernelArg(kernel, 0, sizeof(cl_mem), &memObject1); |
| | | error |= clSetKernelArg(kernel, 1, sizeof(int), &imgWidth); |
| | | error = clSetKernelArg(kernel, 2, sizeof(cl_mem), &memObject2); |
| | | //设置内核参数 |
| | | error = clSetKernelArg(kernel, 0, sizeof(cl_mem), &memObject1); |
| | | error |= clSetKernelArg(kernel, 1, sizeof(int), &img.cols); |
| | | error = clSetKernelArg(kernel, 2, sizeof(cl_mem), &memObject2); |
| | | |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error setting kernel arguments!\n"); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error setting kernel arguments!\n"); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { img.rows }; |
| | | size_t localWorkSize[1] = { 1 }; |
| | | |
| | | const int work_dim = 1; |
| | | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject2, CL_TRUE, 0, resultSize * sizeof(uchar), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { imgHeight }; |
| | | size_t localWorkSize[1] = { 1 }; |
| | | |
| | | const int work_dim = 1; |
| | | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | catch (string st) { |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | throw st; |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject2, CL_TRUE, 0, resultSize * sizeof(uchar), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | |
| | | |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | try { |
| | | //设置内核参数 |
| | | error = clSetKernelArg(kernel, 0, sizeof(cl_mem), &memObject1); |
| | | error |= clSetKernelArg(kernel, 1, sizeof(int), &imgWidth); |
| | | error |= clSetKernelArg(kernel, 2, sizeof(cl_mem), &memObject2); |
| | | error |= clSetKernelArg(kernel, 3, sizeof(int), &threadhold); |
| | | |
| | | //设置内核参数 |
| | | error = clSetKernelArg(kernel, 0, sizeof(cl_mem), &memObject1); |
| | | error |= clSetKernelArg(kernel, 1, sizeof(int), &imgWidth); |
| | | error |= clSetKernelArg(kernel, 2, sizeof(cl_mem), &memObject2); |
| | | error |= clSetKernelArg(kernel, 3, sizeof(int), &threadhold); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error setting kernel arguments!\n"); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { imgHeight }; |
| | | size_t localWorkSize[1] = { 1 }; |
| | | |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error setting kernel arguments!\n"); |
| | | const int work_dim = 1; |
| | | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject2, CL_TRUE, 0, resultSize * sizeof(uchar), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { imgHeight }; |
| | | size_t localWorkSize[1] = { 1 }; |
| | | |
| | | const int work_dim = 1; |
| | | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | catch (string st) { |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | throw st; |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject2, CL_TRUE, 0, resultSize * sizeof(uchar), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | |
| | | } |
| | | |
| | |
| | | throw string("Creat memObject2 failed!\n"); |
| | | } |
| | | |
| | | try { |
| | | //设置内核参数 |
| | | error = clSetKernelArg(kernel, 0, sizeof(cl_mem), &memObject1); |
| | | error |= clSetKernelArg(kernel, 1, sizeof(int), &imgWidth); |
| | | error = clSetKernelArg(kernel, 2, sizeof(cl_mem), &memObject2); |
| | | error |= clSetKernelArg(kernel, 3, sizeof(int), &threadhold); |
| | | |
| | | //设置内核参数 |
| | | error = clSetKernelArg(kernel, 0, sizeof(cl_mem), &memObject1); |
| | | error |= clSetKernelArg(kernel, 1, sizeof(int), &imgWidth); |
| | | error = clSetKernelArg(kernel, 2, sizeof(cl_mem), &memObject2); |
| | | error |= clSetKernelArg(kernel, 3, sizeof(int), &threadhold); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error setting kernel arguments!\n"); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { imgHeight }; |
| | | size_t localWorkSize[1] = { 1 }; |
| | | |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error setting kernel arguments!\n"); |
| | | const int work_dim = 1; |
| | | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject2, CL_TRUE, 0, resultSize * sizeof(uchar), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { imgHeight }; |
| | | size_t localWorkSize[1] = { 1 }; |
| | | |
| | | const int work_dim = 1; |
| | | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | catch (string st) { |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | throw st; |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject2, CL_TRUE, 0, resultSize * sizeof(uchar), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | |
| | | clReleaseKernel(kernel); |
| | | clReleaseMemObject(memObject1); |
| | | clReleaseMemObject(memObject2); |
| | | |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | //将RGB图片转为灰度图片 |
| | | void rgb2Gray(unsigned char* imgs, int imgWidth, int imgHeight, |
| | | void rgb2Gray(cv::Mat img, |
| | | unsigned char* result); |
| | | |
| | | //将RGBA图片转为灰度图片 |
| | | void rgba2Gray(unsigned char* imgs, int imgWidth, int imgHeight, |
| | | void rgba2Gray(cv::Mat img, |
| | | unsigned char* result); |
| | | |
| | | //将RGB图片反转二值化灰度图片 |
| | |
| | | |
| | | void splitL2NumNew(cv::Mat img, IntDataInfo pos, UcharDataInfo result, UcharDataInfo types, unsigned char* zero, int num_width, int num_height, int ele_count_per_line, int length_per_num); |
| | | |
| | | void splitTradeQueueNum(cv::Mat img, IntDataInfo pos, UcharDataInfo result, UcharDataInfo types, unsigned char* zero, int num_width, int num_height, int ele_count_per_line, int length_per_num); |
| | | |
| | | |
| | | |
| | | //分隔板块数字 |
| | |
| | | |
| | | //分隔行数据 |
| | | //每一行的数据分隔成7个区域 |
| | | void splitL2RowData(unsigned char* imgs, int imgWidth, int imgHeight, int* rowIndexs, int lines, |
| | | void splitL2RowData(cv::Mat img, int* rowIndexs, int lines, |
| | | int* result); |
| | | |
| | | void splitPlateContentRowData(unsigned char* imgs, int imgWidth, int imgHeight, int* rowIndexs, int lines, int lineEleCount,int fromIndex,int toIndex, |
| | |
| | | |
| | | |
| | | uchar* templateNums = (unsigned char*)malloc(sizeof(unsigned char) * (_NUMBER_GP_CODE_HEIGHT * 1) * _NUMBER_GP_CODE_WIDTH * 10 * imgList.size()); |
| | | openCLExcuter->createNumberTemplates(1, _NUMBER_GP_CODE_WIDTH, _NUMBER_GP_CODE_HEIGHT, imgList.size(),ImgUtil::numsOneLevel_gpcode, templateNums); |
| | | |
| | | try { |
| | | openCLExcuter->createNumberTemplates(1, _NUMBER_GP_CODE_WIDTH, _NUMBER_GP_CODE_HEIGHT, imgList.size(), ImgUtil::numsOneLevel_gpcode, templateNums); |
| | | } |
| | | catch (string st) { |
| | | free(totalNumberData); |
| | | free(templateNums); |
| | | throw st; |
| | | } |
| | | |
| | | |
| | | uchar** numberResult = openCLExcuter->recognition_numbers(totalNumberData, templateNums, 1 * _NUMBER_GP_CODE_HEIGHT, _NUMBER_GP_CODE_WIDTH * 10* imgList.size(), _NUMBER_GP_CODE_WIDTH, _NUMBER_GP_CODE_HEIGHT, imgList.size()); |
| | |
| | | |
| | | } |
| | | |
| | | std::list<uchar> resultList = recognitionManager->recognitionGPCode(list2); |
| | | std::list<uchar>::iterator ele1; |
| | | string code = ""; |
| | | for (ele1 = resultList.begin();ele1 != resultList.end();++ele1) { |
| | | code.append(to_string(*ele1)); |
| | | std::list<uchar> resultList; |
| | | try { |
| | | resultList = recognitionManager->recognitionGPCode(list2); |
| | | std::list<uchar>::iterator ele1; |
| | | string code = ""; |
| | | for (ele1 = resultList.begin(); ele1 != resultList.end(); ++ele1) { |
| | | code.append(to_string(*ele1)); |
| | | } |
| | | codeArea.code = code; |
| | | //cout << code << endl; |
| | | codeList.push_back(codeArea); |
| | | } |
| | | codeArea.code = code; |
| | | //cout << code << endl; |
| | | codeList.push_back(codeArea); |
| | | catch (...) { |
| | | |
| | | |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | if (!recognitionManager) { |
| | | recognitionManager = new RecognitionManager(); |
| | | } |
| | | try { |
| | | list<uchar> rresult = recognitionManager->recognitionGPCode(nums); |
| | | string num; |
| | | for (std::list<uchar>::iterator e = rresult.begin(); e != rresult.end(); e++) { |
| | | num.append(to_string(*e)); |
| | | } |
| | | (*ele1).code = num; |
| | | (*ele1).cateIndex = index - 1; |
| | | |
| | | list<uchar> rresult = recognitionManager->recognitionGPCode(nums); |
| | | string num; |
| | | for (std::list<uchar>::iterator e = rresult.begin();e != rresult.end();e++) { |
| | | num.append(to_string(*e)); |
| | | fresultList.push_back(*ele1); |
| | | } |
| | | (*ele1).code = num; |
| | | (*ele1).cateIndex = index - 1; |
| | | |
| | | fresultList.push_back(*ele1); |
| | | catch (...) { |
| | | |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | uchar* imgData = (uchar*)malloc(sizeof(uchar) * oimg.rows * oimg.cols); |
| | | if (oimg.channels() == 3) |
| | | { |
| | | openCLExcuter->rgb2Gray(oimg.data, oimg.cols, oimg.rows, imgData); |
| | | openCLExcuter->rgb2Gray(oimg, imgData); |
| | | } |
| | | else { |
| | | openCLExcuter->rgba2Gray(oimg.data, oimg.cols, oimg.rows, imgData); |
| | | openCLExcuter->rgba2Gray(oimg, imgData); |
| | | } |
| | | grayImg.data = imgData; |
| | | |
| | |
| | | |
| | | |
| | | |
| | | int* TradeQueueCapture::split(cv::Mat img) { |
| | | |
| | | int full_row_start = -1; |
| | | int full_row_end = -1; |
| | | |
| | | list<int*> TradeQueueCapture::split(cv::Mat img) { |
| | | list<int*> dataItemList; |
| | | //获取中间的分割线 |
| | | for (int r = 5;r < img.rows;r++) { |
| | | if (ImgDivider::isRowFull(img, r, 5, img.cols - 5, 2)) { |
| | | if (full_row_start < 0) { |
| | | full_row_start = r; |
| | | full_row_end = r; |
| | | } |
| | | else { |
| | | full_row_end = r; |
| | | } |
| | | } |
| | | else { |
| | | if (full_row_start > -1 && full_row_end > -1) { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | int start_row = full_row_end + 1; |
| | | // 从图片中间分隔 |
| | | int start_row = img.rows / 2 + 1; |
| | | //从分割线开始获取第一行的数据 |
| | | int start_index = -1; |
| | | int end_index = -1; |
| | |
| | | } |
| | | } |
| | | } |
| | | int start_col = -1; |
| | | int end_col = -1; |
| | | for (int c = img.cols - 1;c >= 0;c--) { |
| | | if (!ImgDivider::isColEmpty(img, c, start_index, end_index)) { |
| | | if (start_col < 0) { |
| | | start_col = c; |
| | | } |
| | | end_col = c; |
| | | } |
| | | else { |
| | | if (end_col > -1 && end_col - c > 5) { |
| | | int start_col = 0; |
| | | //已经下单的 |
| | | if (end_index - start_index + 1 > _NUMBER_TRADE_QUEUE_HEIGHT + 4) { |
| | | //切割开始点 |
| | | for (int c = img.cols - 5; c >= 0; c--) { |
| | | if (ImgDivider::isColFull(img,c,start_index,end_index,1)) { |
| | | start_col = c + 1; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | int* pos = (int*)malloc(sizeof(int) * 4); |
| | | pos[0] = end_col; |
| | | pos[1] = start_index; |
| | | pos[2] = start_col; |
| | | pos[3] = end_index; |
| | | start_row = -1; |
| | | int end_row = -1; |
| | | if (start_col > 0) { |
| | | //去除上下的黑边 |
| | | for (int r = start_index; r <= end_index; r++) { |
| | | if (!ImgDivider::isRowEmpty(img, r, start_col, img.cols - 1)) { |
| | | if (start_row < 0) { |
| | | start_row = r; |
| | | end_row = r; |
| | | } |
| | | end_row = r; |
| | | } |
| | | else { |
| | | if (start_row > 0 && end_row > 0) { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | }else { |
| | | start_col = 0; |
| | | start_row = start_index; |
| | | end_row = end_index; |
| | | } |
| | | |
| | | return pos; |
| | | std::list<int*> posList; |
| | | if (start_row < 0 || end_row < 0) { |
| | | return posList; |
| | | } |
| | | |
| | | |
| | | int start_col_ = -1; |
| | | int end_col_ = -1; |
| | | for (int c = img.cols - 1;c >= start_col;c--) { |
| | | if (!ImgDivider::isColEmpty(img, c, start_row, end_row)) { |
| | | if (start_col_ < 0) { |
| | | start_col_ = c; |
| | | } |
| | | end_col_ = c; |
| | | } |
| | | else { |
| | | if (end_col_ > -1 && end_col_ - c > 5) { |
| | | int* pos = (int*)malloc(sizeof(int) * 4); |
| | | pos[0] = end_col_; |
| | | pos[1] = start_row; |
| | | pos[2] = start_col_; |
| | | pos[3] = end_row; |
| | | posList.push_back(pos); |
| | | start_col_ = -1; |
| | | end_col_ = -1; |
| | | if (posList.size() >= 2) { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (start_col_ > -1 && end_col_ > -1 && posList.size()<2) { |
| | | int* pos = (int*)malloc(sizeof(int) * 4); |
| | | pos[0] = end_col_; |
| | | pos[1] = start_row; |
| | | pos[2] = start_col_; |
| | | pos[3] = end_row; |
| | | posList.push_back(pos); |
| | | } |
| | | |
| | | return posList; |
| | | |
| | | } |
| | | |
| | | |
| | | int TradeQueueCapture::recognition_buy_1_volumn(cv::Mat img, int* pos) { |
| | | cv::Mat nums = cv::Mat(img, cv::Rect(pos[0], pos[1], pos[2] - pos[0] + 1, pos[3] - pos[1] + 1)); |
| | | //cv::imwrite("C:\\Users\\Administrator\\Desktop\\ocr\\num.png", nums); |
| | | |
| | | list<cv::Mat> matList = ImgUtil::splitNum(nums); |
| | | //string basePath = "C:\\Users\\Administrator\\Desktop\\ocr\\number_trade\\"; |
| | | //for (list<cv::Mat>::iterator ele = matList.begin();ele != matList.end();ele++) { |
| | | // string path = basePath; |
| | | // path.append(to_string(clock())); |
| | | // path.append(".jpg"); |
| | | // cv::imwrite(path,*ele); |
| | | //} |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | TradeQueueResult TradeQueueCapture::recognition_buy_1_volumn(cv::Mat img, list<int*> posList) { |
| | | int c = 0; |
| | | unsigned char* zeroData = (unsigned char*)malloc(sizeof(unsigned char) * _NUMBER_TRADE_QUEUE_WIDTH * _NUMBER_TRADE_QUEUE_HEIGHT); |
| | | for (int r = 0;r < _NUMBER_TRADE_QUEUE_HEIGHT;r++) { |
| | | for (int c = 0;c < _NUMBER_TRADE_QUEUE_WIDTH;c++) |
| | | { |
| | | zeroData[r * _NUMBER_TRADE_QUEUE_WIDTH + c] = ImgUtil::NUMS_LEVEL2[0].data.ptr<uchar>(r)[c]; |
| | | zeroData[r * _NUMBER_TRADE_QUEUE_WIDTH + c] = ImgUtil::NUMS_TRADE_QUEUE[0].data.ptr<uchar>(r)[c]; |
| | | } |
| | | } |
| | | |
| | | int length_per_num = matList.size(); |
| | | int ele_count = 1; |
| | | unsigned char* totalNumberData = (unsigned char*)malloc(sizeof(unsigned char) * (_NUMBER_TRADE_QUEUE_HEIGHT * ele_count) * _NUMBER_TRADE_QUEUE_WIDTH * 10 * length_per_num); |
| | | //模板赋值 |
| | | int index = 0; |
| | | for (list<cv::Mat>::iterator ele = matList.begin();ele != matList.end();ele++) { |
| | | cv::Mat mat = *ele; |
| | | mat = ImgUtil::formatNumTradeQueue(mat); |
| | | |
| | | int x0 = index * 10 * _NUMBER_TRADE_QUEUE_WIDTH; |
| | | |
| | | for (int n = 0;n < 10;n++) |
| | | { |
| | | int x1 = n * _NUMBER_TRADE_QUEUE_WIDTH; |
| | | for (int r = 0;r < mat.rows;r++) { |
| | | int y = r; |
| | | for (int c = 0;c < mat.cols;c++) { |
| | | int x = x0 + x1 + c; |
| | | int pos = y * _NUMBER_TRADE_QUEUE_WIDTH * 10 * length_per_num + x; |
| | | totalNumberData[pos] = mat.ptr<uchar>(r)[c]; |
| | | } |
| | | } |
| | | } |
| | | index++; |
| | | } |
| | | |
| | | |
| | | uchar* templateNums = (unsigned char*)malloc(sizeof(unsigned char) * (_NUMBER_TRADE_QUEUE_HEIGHT * 1) * _NUMBER_TRADE_QUEUE_WIDTH * 10 * length_per_num); |
| | | |
| | | |
| | | |
| | | openCLExcuter->createNumberTemplates(1, _NUMBER_TRADE_QUEUE_WIDTH, _NUMBER_TRADE_QUEUE_HEIGHT, length_per_num, ImgUtil::numsOneLevel_trade_queue, templateNums); |
| | | |
| | | |
| | | |
| | | uchar** numberResult = openCLExcuter->recognition_numbers(totalNumberData, templateNums, 1 * _NUMBER_TRADE_QUEUE_HEIGHT, _NUMBER_TRADE_QUEUE_WIDTH * 10 * length_per_num, _NUMBER_TRADE_QUEUE_WIDTH, _NUMBER_TRADE_QUEUE_HEIGHT, length_per_num); |
| | | |
| | | |
| | | |
| | | |
| | | string st = ""; |
| | | for (int j = 0;j < length_per_num;j++) |
| | | int length_per_num = 8; |
| | | int ele_count = 2; |
| | | |
| | | int* splitResult = (int*)malloc(sizeof(int) * 1 * 4 * ele_count); |
| | | |
| | | list<int*>::iterator ele = posList.begin(); |
| | | int index = 1; |
| | | for (list<int*>::iterator ele = posList.begin(); ele != posList.end(); ++ele) |
| | | { |
| | | st.append(to_string(numberResult[0][j])); |
| | | splitResult[index * 4 + 0] = (*ele)[0]; |
| | | splitResult[index * 4 + 1] = (*ele)[1]; |
| | | splitResult[index * 4 + 2] = (*ele)[2]; |
| | | splitResult[index * 4 + 3] = (*ele)[3]; |
| | | index--; |
| | | } |
| | | |
| | | int line_number_count = ele_count * length_per_num; |
| | | unsigned char* totalNumberData = (unsigned char*)malloc(sizeof(unsigned char) * (_NUMBER_TRADE_QUEUE_HEIGHT * 1) * _NUMBER_TRADE_QUEUE_WIDTH * 10 * line_number_count); |
| | | unsigned char types[] = { NUM_TYPE_PRICE, NUM_TYPE_NUM}; |
| | | UcharDataInfo typesData = UcharDataInfo(); |
| | | typesData.length = ele_count; |
| | | typesData.data = types; |
| | | |
| | | openCLExcuter->splitTradeQueueNum(img, IntDataInfo({ splitResult,(int)(ele_count * 1) }), UcharDataInfo({ totalNumberData, -1 }), typesData, zeroData, _NUMBER_TRADE_QUEUE_WIDTH, _NUMBER_TRADE_QUEUE_HEIGHT, ele_count, length_per_num); |
| | | |
| | | |
| | | uchar* templateNums = (unsigned char*)malloc(sizeof(unsigned char) * (_NUMBER_TRADE_QUEUE_HEIGHT * 1) * _NUMBER_TRADE_QUEUE_WIDTH * 10 * line_number_count); |
| | | |
| | | |
| | | |
| | | openCLExcuter->createNumberTemplates(1, _NUMBER_TRADE_QUEUE_WIDTH, _NUMBER_TRADE_QUEUE_HEIGHT, line_number_count, ImgUtil::numsOneLevel_trade_queue, templateNums); |
| | | |
| | | |
| | | |
| | | uchar** numberResult = openCLExcuter->recognition_numbers(totalNumberData, templateNums, 1 * _NUMBER_TRADE_QUEUE_HEIGHT, _NUMBER_TRADE_QUEUE_WIDTH * 10 * line_number_count, _NUMBER_TRADE_QUEUE_WIDTH, _NUMBER_TRADE_QUEUE_HEIGHT, line_number_count); |
| | | |
| | | |
| | | |
| | | |
| | | TradeQueueResult result; |
| | | |
| | | for (int i = 0; i < ele_count; i++) |
| | | { |
| | | string st = ""; |
| | | for (int j = 0; j < length_per_num; j++) |
| | | { |
| | | if (j == length_per_num - 2 && i==0) { |
| | | st.append("."); |
| | | } |
| | | st.append(to_string(numberResult[0][length_per_num* i + j])); |
| | | |
| | | } |
| | | |
| | | if (i == 0) { |
| | | result.buy_1_price = st; |
| | | } |
| | | else if (i == 1) { |
| | | result.buy_1_volumn = stoi(st); |
| | | } |
| | | } |
| | | |
| | | free(numberResult[0]); |
| | | int volumn = stoi(st); |
| | | int volumn = 0;//stoi(st); |
| | | //printf("结果:%d\n", volumn); |
| | | |
| | | free(totalNumberData); |
| | |
| | | free(zeroData); |
| | | free(templateNums); |
| | | img.release(); |
| | | return volumn; |
| | | |
| | | |
| | | return result; |
| | | } |
| | | TradeQueueResult TradeQueueCapture::recognition_buy_1_volumn(HWND hwnd) { |
| | | //判断窗口是否显示 |
| | |
| | | uchar* data = (uchar*)malloc(sizeof(uchar) * img.cols * img.rows); |
| | | if (img.channels() == 3) |
| | | { |
| | | openCLExcuter->rgb2ThresholdInvert(img.data, img.cols, img.rows, data, 210); |
| | | openCLExcuter->rgb2ThresholdInvert(img.data, img.cols, img.rows, data, 150); |
| | | } |
| | | else if (img.channels() == 4) { |
| | | openCLExcuter->rgba2ThresholdInvert(img.data, img.cols, img.rows, data, 210); |
| | | openCLExcuter->rgba2ThresholdInvert(img.data, img.cols, img.rows, data, 150); |
| | | } |
| | | cv::Mat grayImg = cv::Mat::zeros(img.rows, img.cols, CV_8UC1); |
| | | grayImg.data = data; |
| | |
| | | //string path = "C:\\Users\\Administrator\\Desktop\\ocr\\gray.jpg"; |
| | | //cv::imwrite(path, grayImg); |
| | | |
| | | int* pos = split(grayImg); |
| | | int volumn = recognition_buy_1_volumn(grayImg, pos); |
| | | free(pos); |
| | | list<int*> posList = split(grayImg); |
| | | if (posList.size() < 2) { |
| | | free(data); |
| | | throw string("数据分隔出错"); |
| | | } |
| | | |
| | | TradeQueueResult result = recognition_buy_1_volumn(grayImg, posList); |
| | | for (list<int*>::iterator ele = posList.begin(); ele != posList.end(); ele++) { |
| | | free(*ele); |
| | | } |
| | | free(data); |
| | | |
| | | |
| | | TradeQueueResult result = TradeQueueResult(); |
| | | result.buy_1_volumn = volumn; |
| | | |
| | | //std::wstring_convert<std::codecvt_utf8<wchar_t>> converter; |
| | | // wstring 转string,支持中文 |
| | |
| | | } |
| | | |
| | | |
| | | int TradeQueueCapture::recognition_buy_1_volumn(cv::Mat grayImg) { |
| | | int* rowDataList = split(grayImg); |
| | | TradeQueueResult TradeQueueCapture::recognition_buy_1_volumn(cv::Mat grayImg) { |
| | | list<int*> rowDataList = split(grayImg); |
| | | return recognition_buy_1_volumn(grayImg, rowDataList); |
| | | } |
| | |
| | | string code_name; |
| | | //买1量 |
| | | int buy_1_volumn; |
| | | //时间 |
| | | // 买1价格 |
| | | string buy_1_price; |
| | | // 时间 |
| | | string time; |
| | | |
| | | }; |
| | | |
| | | class TradeQueueCapture |
| | | { |
| | | private: |
| | | OpenCLExcuter *openCLExcuter; |
| | | int* split(cv::Mat grayImg); |
| | | int recognition_buy_1_volumn(cv::Mat grayImg, int* pos); |
| | | list<int*> split(cv::Mat grayImg); |
| | | TradeQueueResult recognition_buy_1_volumn(cv::Mat grayImg, list<int*> posList); |
| | | |
| | | public: |
| | | bool isRunning(); |
| | | TradeQueueCapture(); |
| | | //trade_win_hwnd 整个交易面板的句柄 |
| | | TradeQueueResult recognition_buy_1_volumn(HWND trade_win_hwnd); |
| | | int recognition_buy_1_volumn(cv::Mat grayImg); |
| | | TradeQueueResult recognition_buy_1_volumn(cv::Mat grayImg); |
| | | }; |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | //分隔板块数字 |
| | | __kernel void split_trade_queue_num(__global const unsigned char* img_in, __global const int* pos_in, __global const unsigned char* zero, __global const unsigned char* types, int width, int num_width, int num_height, int ele_count_per_line, int length_per_num, |
| | | __global unsigned char* result) { |
| | | |
| | | int index = get_global_id(0); |
| | | //区域坐标 |
| | | int startP = index * 4; |
| | | int startx = pos_in[startP]; |
| | | int starty = pos_in[startP + 1]; |
| | | int endx = pos_in[startP + 2]; |
| | | int endy = pos_in[startP + 3]; |
| | | |
| | | if (startx > 0) |
| | | { |
| | | int startNy = -1; |
| | | int endNy = -1; |
| | | //去除上下的白边 |
| | | int y = 0; |
| | | for (y = starty; y <= endy; y++) { |
| | | bool empty = 1; |
| | | for (int x = startx; x <= endx; x++) |
| | | { |
| | | int p = get_one_level_position(width, x, y); |
| | | unsigned char value = get_binary_value(img_in[p]); |
| | | //有数据 |
| | | if (value > 0) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | if (!empty) { |
| | | startNy = y; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | for (y = endy; y >= starty; y--) { |
| | | bool empty = 1; |
| | | for (int x = startx; x <= endx; x++) |
| | | { |
| | | int p = get_one_level_position(width, x, y); |
| | | unsigned char value = get_binary_value(img_in[p]); |
| | | //有数据 |
| | | if (value > 0) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | if (!empty) { |
| | | endNy = y; |
| | | break; |
| | | } |
| | | } |
| | | starty = startNy; |
| | | endy = endNy; |
| | | } |
| | | int cols = endx - startx + 1; |
| | | int rows = endy - starty + 1; |
| | | |
| | | //每个元素占用6个数字的空间,不够的前面填充0 |
| | | int num_count = ele_count_per_line * length_per_num; |
| | | |
| | | int nps[12]; |
| | | //只能识别4种数字 |
| | | unsigned char type = types[index % ele_count_per_line]; |
| | | //printf("ele_count_line:%d\n", ele_count_line); |
| | | //是否只有一位小数 |
| | | bool one_point_num = false; |
| | | //时间 |
| | | if (type == 0) { |
| | | //时间 |
| | | int s = cols / 2; |
| | | int i; |
| | | //往前查找冒号 |
| | | int m1_s = -1, m1_e = -1, m2_s = -1, m2_e = -1; |
| | | uchar temp[10]; |
| | | for (i = s; i > -1; i--) { |
| | | if (i < 5) { |
| | | break; |
| | | } |
| | | temp[0] = get_binary_value(img_in[get_one_level_position(width, startx + i, endy)]); |
| | | |
| | | temp[1] = get_binary_value(img_in[get_one_level_position(width, startx + i - 1, endy)]); |
| | | |
| | | |
| | | temp[2] = get_binary_value(img_in[get_one_level_position(width, startx + i - 2, endy)]); |
| | | temp[3] = get_binary_value(img_in[get_one_level_position(width, startx + i - 3, endy)]); |
| | | temp[4] = get_binary_value(img_in[get_one_level_position(width, startx + i - 4, endy)]); |
| | | temp[5] = get_binary_value(img_in[get_one_level_position(width, startx + i - 5, endy)]); |
| | | temp[6] = get_binary_value(img_in[get_one_level_position(width, startx + i - 2, endy - 1)]); |
| | | temp[7] = get_binary_value(img_in[get_one_level_position(width, startx + i - 3, endy - 1)]); |
| | | temp[8] = get_binary_value(img_in[get_one_level_position(width, startx + i - 2, endy - 2)]); |
| | | temp[9] = get_binary_value(img_in[get_one_level_position(width, startx + i - 3, endy - 2)]); |
| | | if (temp[3] > 0 && temp[2] > 0 && temp[6] > 0 && temp[7] > 0) { |
| | | int t = temp[0] + temp[1] + temp[4] + temp[5] + temp[8] + temp[9]; |
| | | if (t == 0) { |
| | | m1_s = i - 5; |
| | | m1_e = i; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | //往后查找冒号 |
| | | |
| | | for (i = s; i < cols; i++) { |
| | | if (i > cols - 5) { |
| | | break; |
| | | } |
| | | |
| | | temp[0] = get_binary_value(img_in[get_one_level_position(width, startx + i, endy)]); |
| | | temp[1] = get_binary_value(img_in[get_one_level_position(width, startx + i + 1, endy)]); |
| | | temp[2] = get_binary_value(img_in[get_one_level_position(width, startx + i + 2, endy)]); |
| | | temp[3] = get_binary_value(img_in[get_one_level_position(width, startx + i + 3, endy)]); |
| | | temp[4] = get_binary_value(img_in[get_one_level_position(width, startx + i + 4, endy)]); |
| | | temp[5] = get_binary_value(img_in[get_one_level_position(width, startx + i + 5, endy)]); |
| | | temp[6] = get_binary_value(img_in[get_one_level_position(width, startx + i + 2, endy - 1)]); |
| | | temp[7] = get_binary_value(img_in[get_one_level_position(width, startx + i + 3, endy - 1)]); |
| | | temp[8] = get_binary_value(img_in[get_one_level_position(width, startx + i + 2, endy - 2)]); |
| | | temp[9] = get_binary_value(img_in[get_one_level_position(width, startx + i + 3, endy - 2)]); |
| | | if (temp[2] > 0 && temp[3] > 0 && temp[6] > 0 && temp[7] > 0) { |
| | | int t = temp[0] + temp[1] + temp[4] + temp[5] + temp[8] + temp[9]; |
| | | if (t == 0) { |
| | | m2_s = i; |
| | | m2_e = i + 5; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | if (m1_s < 0 || m1_e < 0 || m2_s < 0 || m2_e < 0) { |
| | | //没有分割成功的话填充0 |
| | | nps[0] = -1; |
| | | nps[1] = -1; |
| | | nps[2] = -1; |
| | | nps[3] = -1; |
| | | |
| | | nps[4] = -1; |
| | | nps[5] = -1; |
| | | nps[6] = -1; |
| | | nps[7] = -1; |
| | | |
| | | nps[8] = -1; |
| | | nps[9] = -1; |
| | | nps[10] = -1; |
| | | nps[11] = -1; |
| | | } |
| | | else { |
| | | //3个时间的坐标 |
| | | nps[0] = startx; |
| | | nps[1] = starty; |
| | | nps[2] = startx + m1_s - 1; |
| | | nps[3] = endy; |
| | | |
| | | nps[4] = startx + m1_e + 1; |
| | | nps[5] = starty; |
| | | nps[6] = startx + m2_s - 1; |
| | | nps[7] = endy; |
| | | |
| | | nps[8] = startx + m2_e + 1; |
| | | nps[9] = starty; |
| | | nps[10] = endx; |
| | | nps[11] = endy; |
| | | } |
| | | |
| | | |
| | | } |
| | | //金额 |
| | | else if (type == 1) { |
| | | //查找单位前的空格 |
| | | int num_end = -1; |
| | | int i; |
| | | //获取是否有单位 |
| | | int last_empty_index = -1; |
| | | for (i = endx; i >= startx; i--) { |
| | | bool empty = 1; |
| | | for (int y = starty; y < endy; y++) { |
| | | if (get_binary_value(img_in[get_one_level_position(width, i, y)]) > 0) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | if (empty) { |
| | | last_empty_index = i; |
| | | break; |
| | | } |
| | | } |
| | | bool hasUnit = false; |
| | | if (endx - last_empty_index > num_width) { |
| | | hasUnit = true; |
| | | } |
| | | |
| | | //带有单位 |
| | | if (hasUnit) { |
| | | for (i = endx - 11; i >= startx; i--) { |
| | | bool empty = 1; |
| | | for (int y = starty; y < endy; y++) { |
| | | if (get_binary_value(img_in[get_one_level_position(width, i, y)]) > 0) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | if (empty) { |
| | | num_end = i - 1; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (num_end >= 0) { |
| | | endx = num_end; |
| | | } |
| | | |
| | | //去除上下的空白 |
| | | int startNy = -1; |
| | | int endNy = -1; |
| | | //去除上下的白边 |
| | | int y = 0; |
| | | for (y = starty; y <= endy; y++) { |
| | | bool empty = 1; |
| | | for (int x = startx; x <= endx; x++) |
| | | { |
| | | int p = get_one_level_position(width, x, y); |
| | | unsigned char value = get_binary_value(img_in[p]); |
| | | //有数据 |
| | | if (value > 0) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | if (!empty) { |
| | | startNy = y; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | for (y = endy; y >= starty; y--) { |
| | | bool empty = 1; |
| | | for (int x = startx; x <= endx; x++) |
| | | { |
| | | int p = get_one_level_position(width, x, y); |
| | | unsigned char value = get_binary_value(img_in[p]); |
| | | //有数据 |
| | | if (value > 0) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | if (!empty) { |
| | | endNy = y; |
| | | break; |
| | | } |
| | | } |
| | | starty = startNy; |
| | | endy = endNy; |
| | | |
| | | |
| | | |
| | | cols = endx - startx + 1; |
| | | |
| | | |
| | | |
| | | |
| | | int m_s = -1, m_e = -1; |
| | | uchar temp[8]; |
| | | |
| | | for (i = 0; i < cols; i++) { |
| | | if (i > cols - 5) { |
| | | break; |
| | | } |
| | | temp[0] = get_binary_value(img_in[get_one_level_position(width, startx + i, endy)]); |
| | | temp[1] = get_binary_value(img_in[get_one_level_position(width, startx + i + 1, endy)]); |
| | | temp[2] = get_binary_value(img_in[get_one_level_position(width, startx + i + 2, endy)]); |
| | | temp[3] = get_binary_value(img_in[get_one_level_position(width, startx + i + 3, endy)]); |
| | | temp[4] = get_binary_value(img_in[get_one_level_position(width, startx + i + 4, endy)]); |
| | | temp[5] = get_binary_value(img_in[get_one_level_position(width, startx + i + 5, endy)]); |
| | | temp[6] = get_binary_value(img_in[get_one_level_position(width, startx + i + 2, endy - 1)]); |
| | | temp[7] = get_binary_value(img_in[get_one_level_position(width, startx + i + 3, endy - 1)]); |
| | | if (temp[2] > 0 && temp[3] > 0 && temp[6] > 0 && temp[7] > 0) { |
| | | |
| | | if (temp[0] + temp[1] + temp[4] + temp[5] == 0) |
| | | { |
| | | |
| | | bool empty = 1; |
| | | for (int y = starty; y < endy - 1; y++) { |
| | | if (get_binary_value(img_in[get_one_level_position(width, startx + i + 2, y)]) > 0) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | //小数点上方为空值 |
| | | if (empty) { |
| | | m_s = i; |
| | | m_e = i + 5; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (m_s == -1 || m_e == -1) { |
| | | //printf("没找到小数点:%d", index); |
| | | if (hasUnit) |
| | | { |
| | | nps[0] = -1; |
| | | nps[1] = -1; |
| | | nps[2] = -1; |
| | | nps[3] = -1; |
| | | } |
| | | else { |
| | | nps[0] = startx; |
| | | nps[1] = starty; |
| | | nps[2] = endx; |
| | | nps[3] = endy; |
| | | } |
| | | |
| | | nps[4] = -1; |
| | | nps[5] = -1; |
| | | nps[6] = -1; |
| | | nps[7] = -1; |
| | | |
| | | |
| | | } |
| | | else { |
| | | //printf("找到了小数点:%d", index); |
| | | nps[0] = startx; |
| | | nps[1] = starty; |
| | | nps[2] = startx + m_s - 1; |
| | | nps[3] = endy; |
| | | |
| | | nps[4] = startx + m_e + 1; |
| | | nps[5] = starty; |
| | | nps[6] = num_end; |
| | | nps[7] = endy; |
| | | if (nps[6] - nps[4] + 1 <= num_width) { |
| | | one_point_num = true; |
| | | } |
| | | } |
| | | |
| | | nps[8] = -1; |
| | | nps[9] = -1; |
| | | nps[10] = -1; |
| | | nps[11] = -1; |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | //价格 |
| | | else if (type == 2) { |
| | | //股价 |
| | | |
| | | //printf("startx:%d starty:%d endx:%d endy:%d\n",startx,starty,endx,endy); |
| | | |
| | | //往前查找小数点 |
| | | int m_s = -1, m_e = -1; |
| | | uchar temp[8]; |
| | | int i; |
| | | for (i = 0; i < cols; i++) { |
| | | if (i > cols - 5) { |
| | | break; |
| | | } |
| | | temp[0] = get_binary_value(img_in[get_one_level_position(width, startx + i, endy)]); |
| | | temp[1] = get_binary_value(img_in[get_one_level_position(width, startx + i + 1, endy)]); |
| | | temp[2] = get_binary_value(img_in[get_one_level_position(width, startx + i + 2, endy)]); |
| | | temp[3] = get_binary_value(img_in[get_one_level_position(width, startx + i + 3, endy)]); |
| | | temp[4] = get_binary_value(img_in[get_one_level_position(width, startx + i + 4, endy)]); |
| | | temp[5] = get_binary_value(img_in[get_one_level_position(width, startx + i + 5, endy)]); |
| | | temp[6] = get_binary_value(img_in[get_one_level_position(width, startx + i + 2, endy - 1)]); |
| | | temp[7] = get_binary_value(img_in[get_one_level_position(width, startx + i + 3, endy - 1)]); |
| | | if (temp[2] > 0 && temp[3] > 0 ) { |
| | | |
| | | if (temp[0] + temp[1] + temp[4] + temp[5] + temp[6] + temp[7] == 0) |
| | | { |
| | | |
| | | bool empty = 1; |
| | | for (int y = starty; y < endy - 1; y++) { |
| | | if (get_binary_value(img_in[get_one_level_position(width, startx + i + 2, y)]) > 0) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | //小数点上方为空值 |
| | | if (empty) { |
| | | m_s = i; |
| | | m_e = i + 5; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (m_s == -1 || m_e == -1) { |
| | | nps[0] = -1; |
| | | nps[1] = -1; |
| | | nps[2] = -1; |
| | | nps[3] = -1; |
| | | |
| | | nps[4] = -1; |
| | | nps[5] = -1; |
| | | nps[6] = -1; |
| | | nps[7] = -1; |
| | | } |
| | | else { |
| | | nps[0] = startx; |
| | | nps[1] = starty; |
| | | nps[2] = startx + m_s - 1; |
| | | nps[3] = endy; |
| | | |
| | | nps[4] = startx + m_e + 1; |
| | | nps[5] = starty; |
| | | nps[6] = endx; |
| | | nps[7] = endy; |
| | | } |
| | | |
| | | nps[8] = -1; |
| | | nps[9] = -1; |
| | | nps[10] = -1; |
| | | nps[11] = -1; |
| | | |
| | | } |
| | | //代码与数字 |
| | | else if (type == 3 || type == 4) { |
| | | //手数 |
| | | nps[0] = startx; |
| | | nps[1] = starty; |
| | | nps[2] = endx; |
| | | nps[3] = endy; |
| | | |
| | | nps[4] = -1; |
| | | nps[5] = -1; |
| | | nps[6] = -1; |
| | | nps[7] = -1; |
| | | |
| | | nps[8] = -1; |
| | | nps[9] = -1; |
| | | nps[10] = -1; |
| | | nps[11] = -1; |
| | | } |
| | | //百分比 |
| | | else if (type == 5) { |
| | | |
| | | //百分比数字起始位置 |
| | | int percent_start = -1; |
| | | int emptyIndex = -1; |
| | | int i; |
| | | for (i = startx; i <= endx; i++) { |
| | | bool empty = 1; |
| | | for (int y = starty; y < endy; y++) { |
| | | if (get_binary_value(img_in[get_one_level_position(width, i, y)]) > 0) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | if (empty) { |
| | | emptyIndex = i; |
| | | } |
| | | else if (emptyIndex > 0) { |
| | | percent_start = i; |
| | | break; |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | //百分比数字的结束位置 |
| | | int percent_end = -1; |
| | | emptyIndex = -1; |
| | | |
| | | for (i = endx; i >= startx; i--) { |
| | | bool empty = 1; |
| | | for (int y = starty; y < endy; y++) { |
| | | if (get_binary_value(img_in[get_one_level_position(width, i, y)]) > 0) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | if (empty) { |
| | | emptyIndex = i; |
| | | } |
| | | else if (emptyIndex > 0) { |
| | | percent_end = i; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | if (percent_start > -1) { |
| | | startx = percent_start; |
| | | } |
| | | |
| | | if (percent_end > -1) { |
| | | endx = percent_end; |
| | | } |
| | | |
| | | |
| | | //按照价格的形式做识别 |
| | | int m_s = -1, m_e = -1; |
| | | uchar temp[8]; |
| | | for (i = 0; i < cols; i++) { |
| | | if (i > cols - 5) { |
| | | break; |
| | | } |
| | | temp[0] = get_binary_value(img_in[get_one_level_position(width, startx + i, endy)]); |
| | | temp[1] = get_binary_value(img_in[get_one_level_position(width, startx + i + 1, endy)]); |
| | | temp[2] = get_binary_value(img_in[get_one_level_position(width, startx + i + 2, endy)]); |
| | | temp[3] = get_binary_value(img_in[get_one_level_position(width, startx + i + 3, endy)]); |
| | | temp[4] = get_binary_value(img_in[get_one_level_position(width, startx + i + 4, endy)]); |
| | | temp[5] = get_binary_value(img_in[get_one_level_position(width, startx + i + 5, endy)]); |
| | | temp[6] = get_binary_value(img_in[get_one_level_position(width, startx + i + 2, endy - 1)]); |
| | | temp[7] = get_binary_value(img_in[get_one_level_position(width, startx + i + 3, endy - 1)]); |
| | | if (temp[2] > 0 && temp[3] > 0 && temp[6] > 0 && temp[7] > 0) { |
| | | |
| | | if (temp[0] + temp[1] + temp[4] + temp[5] == 0) |
| | | { |
| | | |
| | | bool empty = 1; |
| | | for (int y = starty; y < endy - 1; y++) { |
| | | if (get_binary_value(img_in[get_one_level_position(width, startx + i + 2, y)]) > 0) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | //小数点上方为空值 |
| | | if (empty) { |
| | | m_s = i; |
| | | m_e = i + 5; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (m_s == -1 || m_e == -1) { |
| | | |
| | | nps[0] = -1; |
| | | nps[1] = -1; |
| | | nps[2] = -1; |
| | | nps[3] = -1; |
| | | |
| | | nps[4] = -1; |
| | | nps[5] = -1; |
| | | nps[6] = -1; |
| | | nps[7] = -1; |
| | | } |
| | | else { |
| | | nps[0] = startx; |
| | | nps[1] = starty; |
| | | nps[2] = startx + m_s - 1; |
| | | nps[3] = endy; |
| | | |
| | | nps[4] = startx + m_e + 1; |
| | | nps[5] = starty; |
| | | nps[6] = endx; |
| | | nps[7] = endy; |
| | | } |
| | | |
| | | nps[8] = -1; |
| | | nps[9] = -1; |
| | | nps[10] = -1; |
| | | nps[11] = -1; |
| | | |
| | | } |
| | | |
| | | //分隔数据 |
| | | |
| | | |
| | | //最大分割20个数 |
| | | int numCount = 0; |
| | | //记录分割得到的数据 |
| | | int numberCols[20 * 2]; |
| | | |
| | | int i; |
| | | for (i = 0; i < 3; i++) { |
| | | if (nps[i * 4] == -1) { |
| | | break; |
| | | } |
| | | int _startx = nps[i * 4]; |
| | | int _starty = nps[i * 4 + 1]; |
| | | int _endx = nps[i * 4 + 2]; |
| | | int _endy = nps[i * 4 + 3]; |
| | | int _cols = _endx - _startx + 1; |
| | | |
| | | |
| | | |
| | | int c, startC = -1, endC = -1; |
| | | for (c = 0; c < _cols; c++) { |
| | | |
| | | bool empty = 1; |
| | | for (int y = _starty; y <= _endy; y++) { |
| | | unsigned char value = get_binary_value(img_in[get_one_level_position(width, _startx + c, y)]); |
| | | if (value > 0) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (empty) { |
| | | if (startC > -1 && endC > -1) { |
| | | numberCols[numCount * 2] = _startx + startC; |
| | | numberCols[numCount * 2 + 1] = _startx + endC; |
| | | numCount++; |
| | | } |
| | | startC = -1; |
| | | endC = -1; |
| | | } |
| | | else { |
| | | if (startC == -1) { |
| | | startC = c; |
| | | endC = c; |
| | | } |
| | | else { |
| | | endC = c; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (startC > -1 && endC > -1) { |
| | | numberCols[numCount * 2] = _startx + startC; |
| | | numberCols[numCount * 2 + 1] = _startx + endC; |
| | | numCount++; |
| | | } |
| | | } |
| | | |
| | | int zeroCount = length_per_num - numCount - (one_point_num ? 1 : 0); |
| | | //最大为20位数 |
| | | int fresult[20 * 2]; |
| | | for (i = 0; i < zeroCount; i++) { |
| | | fresult[i * 2] = -1; |
| | | fresult[i * 2 + 1] = -1; |
| | | } |
| | | |
| | | for (i = 0; i < numCount; i++) { |
| | | fresult[(i + zeroCount) * 2] = numberCols[i * 2]; |
| | | fresult[(i + zeroCount) * 2 + 1] = numberCols[i * 2 + 1]; |
| | | } |
| | | //一位小数需要在末尾填充0 |
| | | if (type == 1 && one_point_num) { |
| | | fresult[(numCount + zeroCount) * 2] = -1; |
| | | fresult[(numCount + zeroCount) * 2 + 1] = -1; |
| | | } |
| | | |
| | | //开始填充数据 |
| | | for (i = 0; i < length_per_num; i++) { |
| | | |
| | | unsigned char numData[100 * 100]; |
| | | |
| | | if (fresult[i * 2] == -1) { |
| | | //填充0 |
| | | for (int r = 0; r < num_height; r++) { |
| | | for (int c = 0; c < num_width; c++) { |
| | | unsigned char value = get_binary_value(zero[r * num_width + c]); |
| | | //设置输出坐标的值 |
| | | numData[r * num_width + c] = value; |
| | | } |
| | | } |
| | | |
| | | } |
| | | else { |
| | | int _startx = fresult[i * 2]; |
| | | int _endx = fresult[i * 2 + 1]; |
| | | for (int r = starty; r <= endy; r++) { |
| | | for (int c = 0; c < num_width; c++) { |
| | | unsigned char value = 0; |
| | | if (_startx + c <= _endx) { |
| | | //填充空白0 |
| | | value = get_binary_value(img_in[get_one_level_position(width, _startx + c, r)]); |
| | | //设置输出坐标的值 |
| | | numData[(r - starty) * num_width + c] = value; |
| | | } |
| | | else { |
| | | numData[(r - starty) * num_width + c] = 0; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | int rowDataCount = num_height * num_width * 10 * num_count; |
| | | int rowIndex = index / ele_count_per_line; |
| | | int index_0 = rowDataCount * rowIndex; |
| | | //行偏移量 |
| | | int index_2 = (num_width * 10) * (length_per_num * (index % ele_count_per_line) + i); |
| | | |
| | | for (int re = 0; re < 10; re++) { |
| | | int index_3 = re * num_width; |
| | | for (int r = 0; r < num_height; r++) { |
| | | int index_1 = r * (num_width * 10 * num_count); |
| | | for (int c = 0; c < num_width; c++) { |
| | | int findex = index_0 + index_1 + index_2 + index_3 + c; |
| | | //printf("index:%d-findex:%d value:%d \n", index, findex, numData[r * num_width + c]); |
| | | result[findex] = numData[r * num_width + c]; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | //printf("\n"); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | //分割L2数字 |
| | |
| | | |
| | | |
| | | //RGB图转为灰度图 |
| | | __kernel void rgb2GrayImg(__global unsigned char* imgs, int width, |
| | | __kernel void rgb2GrayImg(const __global unsigned char* imgs, int width, |
| | | __global unsigned char* result) { |
| | | |
| | | int rowIndex = get_global_id(0); |
| | |
| | | } |
| | | } |
| | | |
| | | __kernel void rgb2ThresholdInvert(__global unsigned char* imgs, int width, |
| | | __kernel void rgb2ThresholdInvert(const __global unsigned char* imgs, int width, |
| | | __global unsigned char* result, int threadhold) { |
| | | |
| | | int rowIndex = get_global_id(0); |
| | |
| | | } |
| | | } |
| | | |
| | | __kernel void rgba2GrayImg(__global unsigned char* imgs, int width, |
| | | __kernel void rgba2GrayImg(const __global unsigned char* imgs, int width, |
| | | __global unsigned char* result) { |
| | | |
| | | int rowIndex = get_global_id(0); |
| | |
| | | } |
| | | |
| | | |
| | | __kernel void rgba2ThresholdInvert(__global unsigned char* imgs, int width, |
| | | __kernel void rgba2ThresholdInvert(const __global unsigned char* imgs, int width, |
| | | __global unsigned char* result,int threadhold) { |
| | | |
| | | int rowIndex = get_global_id(0); |
| | |
| | | |
| | | cout << "开始程序" << endl; |
| | | ImgUtil::init(); |
| | | //THSActionUtil::updateMainSite(); |
| | | THSActionUtil::updateMainSite(); |
| | | TradeQueueCaptureManager *manager = new TradeQueueCaptureManager(); |
| | | manager->init(NULL, NULL); |
| | | manager->start(); |
| | | Sleep(10000); |
| | | //TradeQueueCapture* manager = new TradeQueueCapture(); |
| | | //manager->recognition_buy_1_volumn(HWND(0x00020F28)); |
| | | |
| | | Sleep(1000); |
| | | cv::waitKey(0); |
| | | cv::destroyAllWindows(); |
| | | return 0; |
| | |
| | | return toJsonStr(root); |
| | | } |
| | | |
| | | static std::string loadTradeQueue(int index, string codeName,int volumn,string time) { |
| | | static std::string loadTradeQueue(int index, string codeName,int volumn,string price,string time) { |
| | | Json::Value root; |
| | | root["type"] = 50; |
| | | Json::Value data; |
| | | data["index"] = index; |
| | | data["codeName"] = codeName; |
| | | data["price"] = price; |
| | | data["volumn"] = volumn; |
| | | data["time"] = time; |
| | | root["data"] = data; |
New file |
| | |
| | | #include "pch.h" |
| | | #include "StringUtils.h" |
| | | |
| | | |
| | | std::string StringUtils::trim(const std::string source, const std::string chars) { |
| | | std::string other(source); |
| | | auto start = other.find_first_of(chars); |
| | | auto end = other.find_first_not_of(chars, start); |
| | | while (start > -1) { |
| | | other.erase(start, end - start); |
| | | start = other.find_first_of(chars); |
| | | end = other.find_first_not_of(chars, start); |
| | | } |
| | | return other; |
| | | } |
| | | |
| | | |
| | | std::string StringUtils::trim(const std::string source) { |
| | | return trim(source, " \t\n\r"); |
| | | } |
New file |
| | |
| | | #pragma once |
| | | #include <string> |
| | | class StringUtils |
| | | { |
| | | public: |
| | | static std::string trim(const std::string source); |
| | | |
| | | private: |
| | | static std::string trim(const std::string source, const std::string chars); |
| | | |
| | | }; |
| | | |
| | |
| | | <SubSystem>Windows</SubSystem> |
| | | <AdditionalLibraryDirectories>D:\opencv\build\x64\vc15\lib;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.7\lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> |
| | | <AdditionalDependencies>opencv_world455d.lib;OpenCL.lib;ws2_32.lib;libxls.lib;..\crashpad\lib\win64\based.lib;..\crashpad\lib\win64\clientd.lib;..\crashpad\lib\win64\utild.lib;..\crashpad\lib\win64\client.lib;..\crashpad\lib\win64\util.lib;%(AdditionalDependencies)</AdditionalDependencies> |
| | | <StackReserveSize>1000000</StackReserveSize> |
| | | </Link> |
| | | <Midl> |
| | | <MkTypLibCompatible>false</MkTypLibCompatible> |
| | |
| | | <ClInclude Include="pch.h" /> |
| | | <ClInclude Include="Resource.h" /> |
| | | <ClInclude Include="SocketManager.h" /> |
| | | <ClInclude Include="StringUtils.h" /> |
| | | <ClInclude Include="targetver.h" /> |
| | | <ClInclude Include="tool.h" /> |
| | | </ItemGroup> |
| | |
| | | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader> |
| | | </ClCompile> |
| | | <ClCompile Include="SocketManager.cpp" /> |
| | | <ClCompile Include="StringUtils.cpp" /> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <ResourceCompile Include="app.rc" /> |
| | |
| | | <ClInclude Include="crashpad.h"> |
| | | <Filter>头文件</Filter> |
| | | </ClInclude> |
| | | <ClInclude Include="StringUtils.h"> |
| | | <Filter>头文件</Filter> |
| | | </ClInclude> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <ClCompile Include="app.cpp"> |
| | |
| | | <ClCompile Include="loginDlg.cpp"> |
| | | <Filter>源文件</Filter> |
| | | </ClCompile> |
| | | <ClCompile Include="StringUtils.cpp"> |
| | | <Filter>源文件</Filter> |
| | | </ClCompile> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <ResourceCompile Include="app.rc"> |
| | |
| | | <RESOURCE_FILE>app.rc</RESOURCE_FILE> |
| | | </PropertyGroup> |
| | | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> |
| | | <DebuggerFlavor>WindowsRemoteDebugger</DebuggerFlavor> |
| | | <RemoteDebuggerCommand>\\192.168.3.241\FXDMounter\Debug\DataCapture.exe</RemoteDebuggerCommand> |
| | | <RemoteDebuggerWorkingDirectory>\\192.168.3.241\FXDMounter\</RemoteDebuggerWorkingDirectory> |
| | | <RemoteDebuggerServerName>192.168.3.241</RemoteDebuggerServerName> |
| | | <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> |
| | | <RemoteDebuggerCommand>\\192.168.3.250\FXDMounter\Debug\DataCapture.exe</RemoteDebuggerCommand> |
| | | <RemoteDebuggerWorkingDirectory>\\192.168.3.250\FXDMounter\</RemoteDebuggerWorkingDirectory> |
| | | <RemoteDebuggerServerName>192.168.3.250</RemoteDebuggerServerName> |
| | | <RemoteDebuggerConnection>RemoteWithoutAuthentication</RemoteDebuggerConnection> |
| | | </PropertyGroup> |
| | | </Project> |
| | |
| | | DDX_Control(pDX, IDC_BUTTON_UPLOAD_EXCEL_CODE, uploadExcelGPBtn); |
| | | DDX_Control(pDX, IDC_CHECK_BUY1_VOLUMN_TIME_LIMIT, buy1VolumnTimeLimitCheck); |
| | | DDX_Control(pDX, IDC_BUTTON_BUY_1_VOLUMN, buy1VolumnBtn); |
| | | DDX_Control(pDX, IDC_CHECK_ONLINE, onlineCheck); |
| | | DDX_Control(pDX, IDC_BUTTON_UPLOAD_GPCODE, uploadGPCodeBtn); |
| | | } |
| | | |
| | | BEGIN_MESSAGE_MAP(CappDlg, CDialogEx) |
| | |
| | | ON_BN_CLICKED(IDC_CHECK_PRICE_TIME_LIMIT, &CappDlg::OnBnClickedCheckPriceTimeLimit) |
| | | ON_BN_CLICKED(IDC_BUTTON_UPLOAD_EXCEL_CODE, &CappDlg::OnBnClickedButtonUploadExcelCode) |
| | | ON_BN_CLICKED(IDC_BUTTON_BUY_1_VOLUMN, &CappDlg::OnBnClickedButtonBuy1Volumn) |
| | | ON_BN_CLICKED(IDC_BUTTON_UPLOAD_GPCODE, &CappDlg::OnBnClickedButtonUploadGpcode) |
| | | END_MESSAGE_MAP() |
| | | |
| | | |
| | |
| | | buy1VolumnTimeLimitCheck.SetCheck(TRUE); |
| | | TradeQueueCaptureManager::setTradeTimeCapture(priceTimeLimitCheck.GetCheck()); |
| | | |
| | | |
| | | onlineCheck.SetCheck(TRUE); |
| | | |
| | | |
| | | |
| | |
| | | |
| | | |
| | | if (authoritySet.count(AUTHORITY_L2) > 0) { |
| | | onlineCheck.SetCheck(FALSE); |
| | | btnL2.EnableWindow(TRUE); |
| | | resetTHSBtn.EnableWindow(TRUE); |
| | | refreshHWNDBtn.EnableWindow(TRUE); |
| | | onlineCheck.EnableWindow(TRUE); |
| | | list<string> settings = Tool::getSettings("setting.txt"); |
| | | if (settings.size() > 0) { |
| | | string c = *(settings.begin()); |
| | |
| | | btnL2.EnableWindow(FALSE); |
| | | resetTHSBtn.EnableWindow(FALSE); |
| | | refreshHWNDBtn.EnableWindow(FALSE); |
| | | onlineCheck.EnableWindow(FALSE); |
| | | } |
| | | |
| | | if (authoritySet.count(AUTHORITY_LIMIT_UP) > 0) { |
| | |
| | | } |
| | | |
| | | if (authoritySet.count(AUTHORITY_UPLOAD_CODE) > 0) { |
| | | uploadGPBtn.EnableWindow(TRUE); |
| | | uploadExcelGPBtn.EnableWindow(TRUE); |
| | | uploadGPBtn.EnableWindow(FALSE); |
| | | uploadExcelGPBtn.EnableWindow(FALSE); |
| | | uploadGPCodeBtn.EnableWindow(TRUE); |
| | | } |
| | | else { |
| | | uploadGPBtn.EnableWindow(FALSE); |
| | | uploadExcelGPBtn.EnableWindow(FALSE); |
| | | uploadGPCodeBtn.EnableWindow(FALSE); |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | //转为json |
| | | CappDlg* app = (CappDlg*)context; |
| | | string data = JsonUtil::loadTradeQueue(index, result.code_name, result.buy_1_volumn, result.time); |
| | | string data = JsonUtil::loadTradeQueue(index, result.code_name, result.buy_1_volumn, result.buy_1_price,result.time); |
| | | try { |
| | | app->socketManager->sendMsg(8, data.c_str()); |
| | | //AfxMessageBox(_T("上传成功")); |
| | |
| | | { |
| | | //转为json |
| | | CappDlg* app = (CappDlg*)context; |
| | | if (! app->onlineCheck) { |
| | | return "未知错误"; |
| | | } |
| | | if (!app->onlineCheck.GetCheck()) |
| | | { |
| | | throw string("客户端离线"); |
| | | } |
| | | cout << "action回调:" << std::this_thread::get_id() << ":" << data << endl; |
| | | //解析命令 |
| | | Json::Value root = JsonUtil::parseJson(data); |
| | |
| | | try { |
| | | checkTHSEnv(app); |
| | | app->autoMsgStatic.SetWindowTextW(_T("同花顺环境检测通过...")); |
| | | //执行一次重置 |
| | | Sleep(500); |
| | | app->OnBnClickedButton21(); |
| | | break; |
| | | } |
| | | catch (string st) { |
| | |
| | | app->OnBnClickedButton5(); |
| | | app->autoMsgStatic.SetWindowTextW(_T("L2行情识别启动完成...")); |
| | | //启动交易成功识别 |
| | | app->OnBnClickedButtonTrade(); |
| | | //app->OnBnClickedButtonTrade(); |
| | | //启动涨停识别 |
| | | //OnBnClickedButton12(); |
| | | |
| | | //可以接受命令 |
| | | app->onlineCheck.SetCheck(TRUE); |
| | | } |
| | | |
| | | |
| | |
| | | buy1VolumnBtn.SetWindowTextW(_T("暂停买1识别")); |
| | | } |
| | | } |
| | | |
| | | |
| | | void CappDlg::OnBnClickedButtonUploadGpcode() |
| | | { |
| | | std::list<IndustryData> fresult; |
| | | codesDataDlog::codeData = fresult; |
| | | codesDataDlog::upload = TRUE; |
| | | codesDataDlog dlg; |
| | | dlg.DoModal(); |
| | | } |
| | |
| | | CButton buy1VolumnTimeLimitCheck; |
| | | CButton buy1VolumnBtn; |
| | | afx_msg void OnBnClickedButtonBuy1Volumn(); |
| | | CButton onlineCheck; |
| | | CButton uploadGPCodeBtn; |
| | | afx_msg void OnBnClickedButtonUploadGpcode(); |
| | | }; |
| | |
| | | // codesDataDlog.cpp: 实现文件 |
| | | // |
| | | |
| | | #include <iostream> |
| | | #include <string> |
| | | #include "StringUtils.h" |
| | | #include "pch.h" |
| | | #include "codesDataDlog.h" |
| | | #include "afxdialogex.h" |
| | |
| | | #include "app.h" |
| | | #include "SocketManager.h" |
| | | #include "JsonUtil.h" |
| | | #include "tool.h" |
| | | |
| | | |
| | | |
| | |
| | | DDX_Control(pDX, IDC_BUTTON1, uploadBtn); |
| | | |
| | | |
| | | DDX_Control(pDX, IDC_EDIT2, codesEdit); |
| | | } |
| | | |
| | | BOOL codesDataDlog::OnInitDialog() |
| | |
| | | // codesDataDlog 消息处理程序 |
| | | |
| | | |
| | | std::string trim(const std::string source, const std::string chars) { |
| | | std::string other(source); |
| | | int start = other.find_first_of(chars); |
| | | int end = other.find_first_not_of(chars, start); |
| | | while (start > -1) { |
| | | other.erase(start, end - start); |
| | | start = other.find_first_of(chars); |
| | | end = other.find_first_not_of(chars, start); |
| | | } |
| | | return other; |
| | | } |
| | | |
| | | |
| | | void codesDataDlog::OnBnClickedButton1() |
| | | { |
| | | |
| | | if (codeData.size() == 0 ) { |
| | | CString text; |
| | | codesEdit.GetWindowTextW(text); |
| | | string datas = Tool::cstring2String( text); |
| | | //分隔 |
| | | int p = 0; |
| | | do { |
| | | int start = p; |
| | | p = datas.find("\n", p + 1); |
| | | string temp = datas.substr(start, p - start); |
| | | if (temp.length() > 2) { |
| | | |
| | | int splitIndex = temp.find("\t"); |
| | | if (splitIndex < 0) { |
| | | splitIndex = temp.find(" "); |
| | | } |
| | | string zylt = trim(temp.substr(0, splitIndex),"\t\r\n "); |
| | | string code= trim( temp.substr(splitIndex, temp.length() - splitIndex),"\t\r\n "); |
| | | code = code.substr(2, code.length()-2); |
| | | |
| | | IndustryData data; |
| | | data.code = code; |
| | | |
| | | if (zylt.find("亿",0) > 0) { |
| | | data.zyltMoneyUnit = MONEY_UNIT_Y; |
| | | data.zyltMoney = zylt.substr(0, zylt.length() - 2); |
| | | } |
| | | else if (zylt.find("万",0) > 0) { |
| | | data.zyltMoneyUnit = MONEY_UNIT_W; |
| | | data.zyltMoney = zylt.substr(0, zylt.length() - 2); |
| | | } |
| | | codeData.push_back(data); |
| | | } |
| | | if (p < 0) { |
| | | break; |
| | | } |
| | | } while (TRUE); |
| | | |
| | | } |
| | | if (codeData.size() == 0) { |
| | | AfxMessageBox(_T("没有可上传的代码")); |
| | | return; |
| | |
| | | public: |
| | | afx_msg void OnBnClickedButton1(); |
| | | CButton uploadBtn; |
| | | CEdit codesEdit; |
| | | }; |
| | |
| | | } |
| | | |
| | | |
| | | //分隔板块数字 |
| | | __kernel void split_trade_queue_num(__global const unsigned char* img_in, __global const int* pos_in, __global const unsigned char* zero, __global const unsigned char* types, int width, int num_width, int num_height, int ele_count_per_line, int length_per_num, |
| | | __global unsigned char* result) { |
| | | |
| | | int index = get_global_id(0); |
| | | //区域坐标 |
| | | int startP = index * 4; |
| | | int startx = pos_in[startP]; |
| | | int starty = pos_in[startP + 1]; |
| | | int endx = pos_in[startP + 2]; |
| | | int endy = pos_in[startP + 3]; |
| | | |
| | | if (startx > 0) |
| | | { |
| | | int startNy = -1; |
| | | int endNy = -1; |
| | | //去除上下的白边 |
| | | int y = 0; |
| | | for (y = starty; y <= endy; y++) { |
| | | bool empty = 1; |
| | | for (int x = startx; x <= endx; x++) |
| | | { |
| | | int p = get_one_level_position(width, x, y); |
| | | unsigned char value = get_binary_value(img_in[p]); |
| | | //有数据 |
| | | if (value > 0) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | if (!empty) { |
| | | startNy = y; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | for (y = endy; y >= starty; y--) { |
| | | bool empty = 1; |
| | | for (int x = startx; x <= endx; x++) |
| | | { |
| | | int p = get_one_level_position(width, x, y); |
| | | unsigned char value = get_binary_value(img_in[p]); |
| | | //有数据 |
| | | if (value > 0) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | if (!empty) { |
| | | endNy = y; |
| | | break; |
| | | } |
| | | } |
| | | starty = startNy; |
| | | endy = endNy; |
| | | } |
| | | int cols = endx - startx + 1; |
| | | int rows = endy - starty + 1; |
| | | |
| | | //每个元素占用6个数字的空间,不够的前面填充0 |
| | | int num_count = ele_count_per_line * length_per_num; |
| | | |
| | | int nps[12]; |
| | | //只能识别4种数字 |
| | | unsigned char type = types[index % ele_count_per_line]; |
| | | //printf("ele_count_line:%d\n", ele_count_line); |
| | | //是否只有一位小数 |
| | | bool one_point_num = false; |
| | | //时间 |
| | | if (type == 0) { |
| | | //时间 |
| | | int s = cols / 2; |
| | | int i; |
| | | //往前查找冒号 |
| | | int m1_s = -1, m1_e = -1, m2_s = -1, m2_e = -1; |
| | | uchar temp[10]; |
| | | for (i = s; i > -1; i--) { |
| | | if (i < 5) { |
| | | break; |
| | | } |
| | | temp[0] = get_binary_value(img_in[get_one_level_position(width, startx + i, endy)]); |
| | | |
| | | temp[1] = get_binary_value(img_in[get_one_level_position(width, startx + i - 1, endy)]); |
| | | |
| | | |
| | | temp[2] = get_binary_value(img_in[get_one_level_position(width, startx + i - 2, endy)]); |
| | | temp[3] = get_binary_value(img_in[get_one_level_position(width, startx + i - 3, endy)]); |
| | | temp[4] = get_binary_value(img_in[get_one_level_position(width, startx + i - 4, endy)]); |
| | | temp[5] = get_binary_value(img_in[get_one_level_position(width, startx + i - 5, endy)]); |
| | | temp[6] = get_binary_value(img_in[get_one_level_position(width, startx + i - 2, endy - 1)]); |
| | | temp[7] = get_binary_value(img_in[get_one_level_position(width, startx + i - 3, endy - 1)]); |
| | | temp[8] = get_binary_value(img_in[get_one_level_position(width, startx + i - 2, endy - 2)]); |
| | | temp[9] = get_binary_value(img_in[get_one_level_position(width, startx + i - 3, endy - 2)]); |
| | | if (temp[3] > 0 && temp[2] > 0 && temp[6] > 0 && temp[7] > 0) { |
| | | int t = temp[0] + temp[1] + temp[4] + temp[5] + temp[8] + temp[9]; |
| | | if (t == 0) { |
| | | m1_s = i - 5; |
| | | m1_e = i; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | //往后查找冒号 |
| | | |
| | | for (i = s; i < cols; i++) { |
| | | if (i > cols - 5) { |
| | | break; |
| | | } |
| | | |
| | | temp[0] = get_binary_value(img_in[get_one_level_position(width, startx + i, endy)]); |
| | | temp[1] = get_binary_value(img_in[get_one_level_position(width, startx + i + 1, endy)]); |
| | | temp[2] = get_binary_value(img_in[get_one_level_position(width, startx + i + 2, endy)]); |
| | | temp[3] = get_binary_value(img_in[get_one_level_position(width, startx + i + 3, endy)]); |
| | | temp[4] = get_binary_value(img_in[get_one_level_position(width, startx + i + 4, endy)]); |
| | | temp[5] = get_binary_value(img_in[get_one_level_position(width, startx + i + 5, endy)]); |
| | | temp[6] = get_binary_value(img_in[get_one_level_position(width, startx + i + 2, endy - 1)]); |
| | | temp[7] = get_binary_value(img_in[get_one_level_position(width, startx + i + 3, endy - 1)]); |
| | | temp[8] = get_binary_value(img_in[get_one_level_position(width, startx + i + 2, endy - 2)]); |
| | | temp[9] = get_binary_value(img_in[get_one_level_position(width, startx + i + 3, endy - 2)]); |
| | | if (temp[2] > 0 && temp[3] > 0 && temp[6] > 0 && temp[7] > 0) { |
| | | int t = temp[0] + temp[1] + temp[4] + temp[5] + temp[8] + temp[9]; |
| | | if (t == 0) { |
| | | m2_s = i; |
| | | m2_e = i + 5; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | if (m1_s < 0 || m1_e < 0 || m2_s < 0 || m2_e < 0) { |
| | | //没有分割成功的话填充0 |
| | | nps[0] = -1; |
| | | nps[1] = -1; |
| | | nps[2] = -1; |
| | | nps[3] = -1; |
| | | |
| | | nps[4] = -1; |
| | | nps[5] = -1; |
| | | nps[6] = -1; |
| | | nps[7] = -1; |
| | | |
| | | nps[8] = -1; |
| | | nps[9] = -1; |
| | | nps[10] = -1; |
| | | nps[11] = -1; |
| | | } |
| | | else { |
| | | //3个时间的坐标 |
| | | nps[0] = startx; |
| | | nps[1] = starty; |
| | | nps[2] = startx + m1_s - 1; |
| | | nps[3] = endy; |
| | | |
| | | nps[4] = startx + m1_e + 1; |
| | | nps[5] = starty; |
| | | nps[6] = startx + m2_s - 1; |
| | | nps[7] = endy; |
| | | |
| | | nps[8] = startx + m2_e + 1; |
| | | nps[9] = starty; |
| | | nps[10] = endx; |
| | | nps[11] = endy; |
| | | } |
| | | |
| | | |
| | | } |
| | | //金额 |
| | | else if (type == 1) { |
| | | //查找单位前的空格 |
| | | int num_end = -1; |
| | | int i; |
| | | //获取是否有单位 |
| | | int last_empty_index = -1; |
| | | for (i = endx; i >= startx; i--) { |
| | | bool empty = 1; |
| | | for (int y = starty; y < endy; y++) { |
| | | if (get_binary_value(img_in[get_one_level_position(width, i, y)]) > 0) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | if (empty) { |
| | | last_empty_index = i; |
| | | break; |
| | | } |
| | | } |
| | | bool hasUnit = false; |
| | | if (endx - last_empty_index > num_width) { |
| | | hasUnit = true; |
| | | } |
| | | |
| | | //带有单位 |
| | | if (hasUnit) { |
| | | for (i = endx - 11; i >= startx; i--) { |
| | | bool empty = 1; |
| | | for (int y = starty; y < endy; y++) { |
| | | if (get_binary_value(img_in[get_one_level_position(width, i, y)]) > 0) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | if (empty) { |
| | | num_end = i - 1; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (num_end >= 0) { |
| | | endx = num_end; |
| | | } |
| | | |
| | | //去除上下的空白 |
| | | int startNy = -1; |
| | | int endNy = -1; |
| | | //去除上下的白边 |
| | | int y = 0; |
| | | for (y = starty; y <= endy; y++) { |
| | | bool empty = 1; |
| | | for (int x = startx; x <= endx; x++) |
| | | { |
| | | int p = get_one_level_position(width, x, y); |
| | | unsigned char value = get_binary_value(img_in[p]); |
| | | //有数据 |
| | | if (value > 0) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | if (!empty) { |
| | | startNy = y; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | for (y = endy; y >= starty; y--) { |
| | | bool empty = 1; |
| | | for (int x = startx; x <= endx; x++) |
| | | { |
| | | int p = get_one_level_position(width, x, y); |
| | | unsigned char value = get_binary_value(img_in[p]); |
| | | //有数据 |
| | | if (value > 0) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | if (!empty) { |
| | | endNy = y; |
| | | break; |
| | | } |
| | | } |
| | | starty = startNy; |
| | | endy = endNy; |
| | | |
| | | |
| | | |
| | | cols = endx - startx + 1; |
| | | |
| | | |
| | | |
| | | |
| | | int m_s = -1, m_e = -1; |
| | | uchar temp[8]; |
| | | |
| | | for (i = 0; i < cols; i++) { |
| | | if (i > cols - 5) { |
| | | break; |
| | | } |
| | | temp[0] = get_binary_value(img_in[get_one_level_position(width, startx + i, endy)]); |
| | | temp[1] = get_binary_value(img_in[get_one_level_position(width, startx + i + 1, endy)]); |
| | | temp[2] = get_binary_value(img_in[get_one_level_position(width, startx + i + 2, endy)]); |
| | | temp[3] = get_binary_value(img_in[get_one_level_position(width, startx + i + 3, endy)]); |
| | | temp[4] = get_binary_value(img_in[get_one_level_position(width, startx + i + 4, endy)]); |
| | | temp[5] = get_binary_value(img_in[get_one_level_position(width, startx + i + 5, endy)]); |
| | | temp[6] = get_binary_value(img_in[get_one_level_position(width, startx + i + 2, endy - 1)]); |
| | | temp[7] = get_binary_value(img_in[get_one_level_position(width, startx + i + 3, endy - 1)]); |
| | | if (temp[2] > 0 && temp[3] > 0 && temp[6] > 0 && temp[7] > 0) { |
| | | |
| | | if (temp[0] + temp[1] + temp[4] + temp[5] == 0) |
| | | { |
| | | |
| | | bool empty = 1; |
| | | for (int y = starty; y < endy - 1; y++) { |
| | | if (get_binary_value(img_in[get_one_level_position(width, startx + i + 2, y)]) > 0) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | //小数点上方为空值 |
| | | if (empty) { |
| | | m_s = i; |
| | | m_e = i + 5; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (m_s == -1 || m_e == -1) { |
| | | //printf("没找到小数点:%d", index); |
| | | if (hasUnit) |
| | | { |
| | | nps[0] = -1; |
| | | nps[1] = -1; |
| | | nps[2] = -1; |
| | | nps[3] = -1; |
| | | } |
| | | else { |
| | | nps[0] = startx; |
| | | nps[1] = starty; |
| | | nps[2] = endx; |
| | | nps[3] = endy; |
| | | } |
| | | |
| | | nps[4] = -1; |
| | | nps[5] = -1; |
| | | nps[6] = -1; |
| | | nps[7] = -1; |
| | | |
| | | |
| | | } |
| | | else { |
| | | //printf("找到了小数点:%d", index); |
| | | nps[0] = startx; |
| | | nps[1] = starty; |
| | | nps[2] = startx + m_s - 1; |
| | | nps[3] = endy; |
| | | |
| | | nps[4] = startx + m_e + 1; |
| | | nps[5] = starty; |
| | | nps[6] = num_end; |
| | | nps[7] = endy; |
| | | if (nps[6] - nps[4] + 1 <= num_width) { |
| | | one_point_num = true; |
| | | } |
| | | } |
| | | |
| | | nps[8] = -1; |
| | | nps[9] = -1; |
| | | nps[10] = -1; |
| | | nps[11] = -1; |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | //价格 |
| | | else if (type == 2) { |
| | | //股价 |
| | | |
| | | //printf("startx:%d starty:%d endx:%d endy:%d\n",startx,starty,endx,endy); |
| | | |
| | | //往前查找小数点 |
| | | int m_s = -1, m_e = -1; |
| | | uchar temp[8]; |
| | | int i; |
| | | for (i = 0; i < cols; i++) { |
| | | if (i > cols - 5) { |
| | | break; |
| | | } |
| | | temp[0] = get_binary_value(img_in[get_one_level_position(width, startx + i, endy)]); |
| | | temp[1] = get_binary_value(img_in[get_one_level_position(width, startx + i + 1, endy)]); |
| | | temp[2] = get_binary_value(img_in[get_one_level_position(width, startx + i + 2, endy)]); |
| | | temp[3] = get_binary_value(img_in[get_one_level_position(width, startx + i + 3, endy)]); |
| | | temp[4] = get_binary_value(img_in[get_one_level_position(width, startx + i + 4, endy)]); |
| | | temp[5] = get_binary_value(img_in[get_one_level_position(width, startx + i + 5, endy)]); |
| | | temp[6] = get_binary_value(img_in[get_one_level_position(width, startx + i + 2, endy - 1)]); |
| | | temp[7] = get_binary_value(img_in[get_one_level_position(width, startx + i + 3, endy - 1)]); |
| | | if (temp[2] > 0 && temp[3] > 0 ) { |
| | | |
| | | if (temp[0] + temp[1] + temp[4] + temp[5] + temp[6] + temp[7] == 0) |
| | | { |
| | | |
| | | bool empty = 1; |
| | | for (int y = starty; y < endy - 1; y++) { |
| | | if (get_binary_value(img_in[get_one_level_position(width, startx + i + 2, y)]) > 0) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | //小数点上方为空值 |
| | | if (empty) { |
| | | m_s = i; |
| | | m_e = i + 5; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (m_s == -1 || m_e == -1) { |
| | | nps[0] = -1; |
| | | nps[1] = -1; |
| | | nps[2] = -1; |
| | | nps[3] = -1; |
| | | |
| | | nps[4] = -1; |
| | | nps[5] = -1; |
| | | nps[6] = -1; |
| | | nps[7] = -1; |
| | | } |
| | | else { |
| | | nps[0] = startx; |
| | | nps[1] = starty; |
| | | nps[2] = startx + m_s - 1; |
| | | nps[3] = endy; |
| | | |
| | | nps[4] = startx + m_e + 1; |
| | | nps[5] = starty; |
| | | nps[6] = endx; |
| | | nps[7] = endy; |
| | | } |
| | | |
| | | nps[8] = -1; |
| | | nps[9] = -1; |
| | | nps[10] = -1; |
| | | nps[11] = -1; |
| | | |
| | | } |
| | | //代码与数字 |
| | | else if (type == 3 || type == 4) { |
| | | //手数 |
| | | nps[0] = startx; |
| | | nps[1] = starty; |
| | | nps[2] = endx; |
| | | nps[3] = endy; |
| | | |
| | | nps[4] = -1; |
| | | nps[5] = -1; |
| | | nps[6] = -1; |
| | | nps[7] = -1; |
| | | |
| | | nps[8] = -1; |
| | | nps[9] = -1; |
| | | nps[10] = -1; |
| | | nps[11] = -1; |
| | | } |
| | | //百分比 |
| | | else if (type == 5) { |
| | | |
| | | //百分比数字起始位置 |
| | | int percent_start = -1; |
| | | int emptyIndex = -1; |
| | | int i; |
| | | for (i = startx; i <= endx; i++) { |
| | | bool empty = 1; |
| | | for (int y = starty; y < endy; y++) { |
| | | if (get_binary_value(img_in[get_one_level_position(width, i, y)]) > 0) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | if (empty) { |
| | | emptyIndex = i; |
| | | } |
| | | else if (emptyIndex > 0) { |
| | | percent_start = i; |
| | | break; |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | //百分比数字的结束位置 |
| | | int percent_end = -1; |
| | | emptyIndex = -1; |
| | | |
| | | for (i = endx; i >= startx; i--) { |
| | | bool empty = 1; |
| | | for (int y = starty; y < endy; y++) { |
| | | if (get_binary_value(img_in[get_one_level_position(width, i, y)]) > 0) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | if (empty) { |
| | | emptyIndex = i; |
| | | } |
| | | else if (emptyIndex > 0) { |
| | | percent_end = i; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | if (percent_start > -1) { |
| | | startx = percent_start; |
| | | } |
| | | |
| | | if (percent_end > -1) { |
| | | endx = percent_end; |
| | | } |
| | | |
| | | |
| | | //按照价格的形式做识别 |
| | | int m_s = -1, m_e = -1; |
| | | uchar temp[8]; |
| | | for (i = 0; i < cols; i++) { |
| | | if (i > cols - 5) { |
| | | break; |
| | | } |
| | | temp[0] = get_binary_value(img_in[get_one_level_position(width, startx + i, endy)]); |
| | | temp[1] = get_binary_value(img_in[get_one_level_position(width, startx + i + 1, endy)]); |
| | | temp[2] = get_binary_value(img_in[get_one_level_position(width, startx + i + 2, endy)]); |
| | | temp[3] = get_binary_value(img_in[get_one_level_position(width, startx + i + 3, endy)]); |
| | | temp[4] = get_binary_value(img_in[get_one_level_position(width, startx + i + 4, endy)]); |
| | | temp[5] = get_binary_value(img_in[get_one_level_position(width, startx + i + 5, endy)]); |
| | | temp[6] = get_binary_value(img_in[get_one_level_position(width, startx + i + 2, endy - 1)]); |
| | | temp[7] = get_binary_value(img_in[get_one_level_position(width, startx + i + 3, endy - 1)]); |
| | | if (temp[2] > 0 && temp[3] > 0 && temp[6] > 0 && temp[7] > 0) { |
| | | |
| | | if (temp[0] + temp[1] + temp[4] + temp[5] == 0) |
| | | { |
| | | |
| | | bool empty = 1; |
| | | for (int y = starty; y < endy - 1; y++) { |
| | | if (get_binary_value(img_in[get_one_level_position(width, startx + i + 2, y)]) > 0) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | //小数点上方为空值 |
| | | if (empty) { |
| | | m_s = i; |
| | | m_e = i + 5; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (m_s == -1 || m_e == -1) { |
| | | |
| | | nps[0] = -1; |
| | | nps[1] = -1; |
| | | nps[2] = -1; |
| | | nps[3] = -1; |
| | | |
| | | nps[4] = -1; |
| | | nps[5] = -1; |
| | | nps[6] = -1; |
| | | nps[7] = -1; |
| | | } |
| | | else { |
| | | nps[0] = startx; |
| | | nps[1] = starty; |
| | | nps[2] = startx + m_s - 1; |
| | | nps[3] = endy; |
| | | |
| | | nps[4] = startx + m_e + 1; |
| | | nps[5] = starty; |
| | | nps[6] = endx; |
| | | nps[7] = endy; |
| | | } |
| | | |
| | | nps[8] = -1; |
| | | nps[9] = -1; |
| | | nps[10] = -1; |
| | | nps[11] = -1; |
| | | |
| | | } |
| | | |
| | | //分隔数据 |
| | | |
| | | |
| | | //最大分割20个数 |
| | | int numCount = 0; |
| | | //记录分割得到的数据 |
| | | int numberCols[20 * 2]; |
| | | |
| | | int i; |
| | | for (i = 0; i < 3; i++) { |
| | | if (nps[i * 4] == -1) { |
| | | break; |
| | | } |
| | | int _startx = nps[i * 4]; |
| | | int _starty = nps[i * 4 + 1]; |
| | | int _endx = nps[i * 4 + 2]; |
| | | int _endy = nps[i * 4 + 3]; |
| | | int _cols = _endx - _startx + 1; |
| | | |
| | | |
| | | |
| | | int c, startC = -1, endC = -1; |
| | | for (c = 0; c < _cols; c++) { |
| | | |
| | | bool empty = 1; |
| | | for (int y = _starty; y <= _endy; y++) { |
| | | unsigned char value = get_binary_value(img_in[get_one_level_position(width, _startx + c, y)]); |
| | | if (value > 0) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (empty) { |
| | | if (startC > -1 && endC > -1) { |
| | | numberCols[numCount * 2] = _startx + startC; |
| | | numberCols[numCount * 2 + 1] = _startx + endC; |
| | | numCount++; |
| | | } |
| | | startC = -1; |
| | | endC = -1; |
| | | } |
| | | else { |
| | | if (startC == -1) { |
| | | startC = c; |
| | | endC = c; |
| | | } |
| | | else { |
| | | endC = c; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (startC > -1 && endC > -1) { |
| | | numberCols[numCount * 2] = _startx + startC; |
| | | numberCols[numCount * 2 + 1] = _startx + endC; |
| | | numCount++; |
| | | } |
| | | } |
| | | |
| | | int zeroCount = length_per_num - numCount - (one_point_num ? 1 : 0); |
| | | //最大为20位数 |
| | | int fresult[20 * 2]; |
| | | for (i = 0; i < zeroCount; i++) { |
| | | fresult[i * 2] = -1; |
| | | fresult[i * 2 + 1] = -1; |
| | | } |
| | | |
| | | for (i = 0; i < numCount; i++) { |
| | | fresult[(i + zeroCount) * 2] = numberCols[i * 2]; |
| | | fresult[(i + zeroCount) * 2 + 1] = numberCols[i * 2 + 1]; |
| | | } |
| | | //一位小数需要在末尾填充0 |
| | | if (type == 1 && one_point_num) { |
| | | fresult[(numCount + zeroCount) * 2] = -1; |
| | | fresult[(numCount + zeroCount) * 2 + 1] = -1; |
| | | } |
| | | |
| | | //开始填充数据 |
| | | for (i = 0; i < length_per_num; i++) { |
| | | |
| | | unsigned char numData[100 * 100]; |
| | | |
| | | if (fresult[i * 2] == -1) { |
| | | //填充0 |
| | | for (int r = 0; r < num_height; r++) { |
| | | for (int c = 0; c < num_width; c++) { |
| | | unsigned char value = get_binary_value(zero[r * num_width + c]); |
| | | //设置输出坐标的值 |
| | | numData[r * num_width + c] = value; |
| | | } |
| | | } |
| | | |
| | | } |
| | | else { |
| | | int _startx = fresult[i * 2]; |
| | | int _endx = fresult[i * 2 + 1]; |
| | | for (int r = starty; r <= endy; r++) { |
| | | for (int c = 0; c < num_width; c++) { |
| | | unsigned char value = 0; |
| | | if (_startx + c <= _endx) { |
| | | //填充空白0 |
| | | value = get_binary_value(img_in[get_one_level_position(width, _startx + c, r)]); |
| | | //设置输出坐标的值 |
| | | numData[(r - starty) * num_width + c] = value; |
| | | } |
| | | else { |
| | | numData[(r - starty) * num_width + c] = 0; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | int rowDataCount = num_height * num_width * 10 * num_count; |
| | | int rowIndex = index / ele_count_per_line; |
| | | int index_0 = rowDataCount * rowIndex; |
| | | //行偏移量 |
| | | int index_2 = (num_width * 10) * (length_per_num * (index % ele_count_per_line) + i); |
| | | |
| | | for (int re = 0; re < 10; re++) { |
| | | int index_3 = re * num_width; |
| | | for (int r = 0; r < num_height; r++) { |
| | | int index_1 = r * (num_width * 10 * num_count); |
| | | for (int c = 0; c < num_width; c++) { |
| | | int findex = index_0 + index_1 + index_2 + index_3 + c; |
| | | //printf("index:%d-findex:%d value:%d \n", index, findex, numData[r * num_width + c]); |
| | | result[findex] = numData[r * num_width + c]; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | //printf("\n"); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | //分割L2数字 |
| | |
| | | #define IDC_BUTTON_UPLOAD_EXCEL_CODE 1047 |
| | | #define IDC_BUTTON_BUY_1_VOLUMN 1048 |
| | | #define IDC_CHECK_BUY1_VOLUMN_TIME_LIMIT 1049 |
| | | #define IDC_CHECK_ONLINE 1050 |
| | | #define IDC_BUTTON_UPLOAD_GPCODE 1051 |
| | | |
| | | // Next default values for new objects |
| | | // |
| | |
| | | #ifndef APSTUDIO_READONLY_SYMBOLS |
| | | #define _APS_NEXT_RESOURCE_VALUE 136 |
| | | #define _APS_NEXT_COMMAND_VALUE 32771 |
| | | #define _APS_NEXT_CONTROL_VALUE 1050 |
| | | #define _APS_NEXT_CONTROL_VALUE 1052 |
| | | #define _APS_NEXT_SYMED_VALUE 101 |
| | | #endif |
| | | #endif |