| | |
| | | #include "IndustryCapture.h" |
| | | #include "THSActionUtil.h" |
| | | #include <set> |
| | | #include "Win32Util.h" |
| | | OpenCLExcuter* IndustryCapture::openCLExcuter; |
| | |
| | | |
| | | HWND IndustryCapture::win; |
| | | |
| | | CallbackFun_Industry IndustryCapture::data_callback; |
| | | void* IndustryCapture::context; |
| | | |
| | | bool IndustryCapture::terminated; |
| | | |
| | | |
| | | RecognitionManager* IndustryCapture::recognitionManager; |
| | |
| | | |
| | | |
| | | |
| | | void IndustryCapture::init() { |
| | | void IndustryCapture::init(CallbackFun_Industry callback, void* contex) { |
| | | terminated = false; |
| | | data_callback = callback; |
| | | context = contex; |
| | | recognitionManager = new RecognitionManager(); |
| | | openCLExcuter = new OpenCLExcuter(); |
| | | openCLExcuter->init(); |
| | | try { |
| | | refreshHWND(); |
| | | } |
| | | catch (...) { |
| | | |
| | | } |
| | | } |
| | | void IndustryCapture::refreshHWND() { |
| | | HWND hwnd = THSActionUtil::getIndustryWindow(); |
| | |
| | | |
| | | |
| | | list<list<IndustryData>> IndustryCapture::captureIndustryCodes(cv::Mat oimg) { |
| | | 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); |
| | | } |
| | | else { |
| | | openCLExcuter->rgba2Gray(oimg.data, oimg.cols, oimg.rows, imgData); |
| | | } |
| | | grayImg_.data = imgData; |
| | | //cv::imwrite("C:\\Users\\Administrator\\Desktop\\ocr\\industry.jpg", grayImg); |
| | | cv::Mat grayImg_ = grayImgs(oimg); |
| | | |
| | | GPCodeArea menu = THSActionUtil::splitPlateMenuArea(grayImg_); |
| | | list<int*> menus = splitMenu(menu, grayImg_); |
| | | |
| | | free(grayImg_.data); |
| | | grayImg_.release(); |
| | | |
| | | list<list<IndustryData>> flist; |
| | | |
| | | int menu_index = 0; |
| | | |
| | | for (list<int*>::iterator ele = menus.begin();ele != menus.end();ele++) { |
| | | menu_index++; |
| | | |
| | | int x = ((*ele)[0] + (*ele)[2]) / 2; |
| | | int y = ((*ele)[1] + (*ele)[3]) / 2; |
| | | if (menu_index > 1) |
| | | { |
| | | //点击 |
| | | SendMessage(win, WM_LBUTTONDOWN, 0, MAKELONG(x, y)); |
| | | Sleep(10); |
| | | SendMessage(win, WM_LBUTTONUP, 0, MAKELONG(x, y)); |
| | | list<IndustryData> dataList; |
| | | for (int i = 0;i < 3;i++) { |
| | | } |
| | | |
| | | list<IndustryData> dataList; |
| | | for (int i = 0;i < 10;i++) { |
| | | if (terminated) { |
| | | break; |
| | | } |
| | | Sleep(500); |
| | | //截图+灰度化 |
| | | |
| | | list<IndustryData> itemList; |
| | | |
| | | try { |
| | | |
| | | cv::Mat grayImg = grayImgs(CaptureUtil::capture(win)); |
| | | list<int*> rowData = THSActionUtil::splitPlateRowArea(grayImg); |
| | |
| | | count++; |
| | | } |
| | | |
| | | int line_number_count = ele_count_per_line * 6; |
| | | int length_per_num = 6; |
| | | |
| | | 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, 2, splitResult); |
| | | |
| | |
| | | unsigned char* totalNumberData = (unsigned char*)malloc(sizeof(unsigned char) * (_NUMBER_GP_CODE_HEIGHT * rowData.size()) * _NUMBER_GP_CODE_WIDTH * 10 * line_number_count); |
| | | |
| | | UcharDataInfo typesData = UcharDataInfo(); |
| | | unsigned char types[] = { NUM_TYPE_CODE,NUM_TYPE_MONEY}; |
| | | unsigned char types[] = { NUM_TYPE_MONEY,NUM_TYPE_CODE }; |
| | | typesData.length = 2; |
| | | typesData.data = types; |
| | | |
| | | openCLExcuter->splitPlateNum(grayImg, IntDataInfo({ splitResult,(int) (ele_count_per_line * rowData.size()) }), UcharDataInfo({ totalNumberData, -1 }), typesData, zeroData, _NUMBER_GP_CODE_WIDTH, _NUMBER_GP_CODE_HEIGHT, ele_count_per_line, 6); |
| | | openCLExcuter->splitPlateNum(grayImg, IntDataInfo({ splitResult,(int)(ele_count_per_line * rowData.size()) }), UcharDataInfo({ totalNumberData, -1 }), typesData, zeroData, _NUMBER_GP_CODE_WIDTH, _NUMBER_GP_CODE_HEIGHT, ele_count_per_line, length_per_num); |
| | | |
| | | |
| | | |
| | |
| | | for (int i = 0;i < rowData.size();i++) { |
| | | IndustryData industryData = IndustryData(); |
| | | string code = ""; |
| | | for (int j = 0;j < 6;j++) |
| | | for (int j = 0;j < length_per_num;j++) |
| | | { |
| | | code.append(to_string(numberResult[i][6*1+j])); |
| | | } |
| | | |
| | | string money = ""; |
| | | for (int j = 0;j < 6;j++) |
| | | for (int j = 0;j < length_per_num;j++) |
| | | { |
| | | if (j == 4) { |
| | | money.append("."); |
| | |
| | | } |
| | | index++; |
| | | } |
| | | |
| | | free(rowIndex); |
| | | free(splitResult); |
| | | free(zeroData); |
| | | free(totalNumberData); |
| | | free(templateNums); |
| | | free(unitData); |
| | | free(unitResult); |
| | |
| | | |
| | | for (list<IndustryData>::iterator el = itemList.begin();el != itemList.end();el++) { |
| | | dataList.push_back(*el); |
| | | } |
| | | } |
| | | catch (...) { |
| | | |
| | | } |
| | | |
| | | int x = oimg.cols - 50; |
| | |
| | | Sleep(10); |
| | | SendMessage(win, WM_MOUSEWHEEL, 0, MAKELONG(x, y)); |
| | | } |
| | | |
| | | data_callback(dataList, context); |
| | | flist.push_back(dataList); |
| | | //break; |
| | | if (terminated) { |
| | | break; |
| | | } |
| | | } |
| | | |
| | | return flist; |
| | |
| | | list<list<IndustryData>> IndustryCapture::captureIndustryCodes() { |
| | | list<list<IndustryData>> flist; |
| | | set<string> codesSet; |
| | | //测试 |
| | | for (int i = 0;i < 3;i++) { |
| | | Sleep(1000); |
| | | cv::Mat oimg = CaptureUtil::capture(win); |
| | |
| | | for (list<list<IndustryData>>::iterator el = codes.begin();el != codes.end();el++) { |
| | | flist.push_back(*el); |
| | | } |
| | | if (terminated) { |
| | | break; |
| | | } |
| | | //滑动到下一页 |
| | | RECT rect; |
| | | GetWindowRect(win, &rect); |
| | | SendMessage(win, WM_LBUTTONDOWN, 0, MAKELONG(20, 100)); |
| | | SendMessage(win, WM_LBUTTONDOWN, 0, MAKELONG(50, 100)); |
| | | Sleep(10); |
| | | SendMessage(win, WM_LBUTTONUP, 0, MAKELONG(20, 100)); |
| | | SendMessage(win, WM_LBUTTONUP, 0, MAKELONG(50, 100)); |
| | | Sleep(10); |
| | | SendMessage(win, WM_MOUSEWHEEL, 0, MAKEWORD(20, 100)); |
| | | SendMessage(win, WM_MOUSEWHEEL, 0, MAKEWORD(50, 100)); |
| | | } |
| | | terminated = false; |
| | | return flist; |
| | | } |
| | | |
| | | bool IndustryCapture::isInited() { |
| | | return inited; |
| | | } |
| | | |
| | | void IndustryCapture::stop() { |
| | | terminated = true; |
| | | } |