| | |
| | | HWND THSActionUtil::getThirdWindow() { |
| | | list<HWND> wlist = Win32Util::searchWindow("同花顺("); |
| | | list<HWND>::iterator ele; |
| | | for (ele = wlist.begin();ele != wlist.end();ele++) { |
| | | for (ele = wlist.begin(); ele != wlist.end(); ele++) { |
| | | HWND hwnd = *ele; |
| | | string str = Win32Util::getWindowName(hwnd); |
| | | if (isThirdScreen(str)) |
| | |
| | | HWND THSActionUtil::getIndustryWindow() { |
| | | list<HWND> wlist = Win32Util::searchWindow("同花顺("); |
| | | list<HWND>::iterator ele; |
| | | for (ele = wlist.begin();ele != wlist.end();ele++) { |
| | | for (ele = wlist.begin(); ele != wlist.end(); ele++) { |
| | | HWND hwnd = *ele; |
| | | string str = Win32Util::getWindowName(hwnd); |
| | | if (str.find("行业") != string::npos) |
| | |
| | | HWND THSActionUtil::getTradeDelegateWindow() { |
| | | list<HWND> wlist = Win32Util::searchWindow("专业版下单"); |
| | | list<HWND>::iterator ele; |
| | | for (ele = wlist.begin();ele != wlist.end();ele++) { |
| | | for (ele = wlist.begin(); ele != wlist.end(); ele++) { |
| | | HWND hwnd = *ele; |
| | | return hwnd; |
| | | } |
| | |
| | | return 0; |
| | | } |
| | | |
| | | HWND THSActionUtil::getDXJLWindow() |
| | | { |
| | | HWND hwnd = getDXJLMainWindow(); |
| | | |
| | | hwnd = FindWindowExA(hwnd, NULL, "#32770", NULL); |
| | | if (Win32Util::isWindowShow(hwnd)) { |
| | | return hwnd; |
| | | } |
| | | |
| | | return 0; |
| | | } |
| | | |
| | | HWND THSActionUtil::getDXJLMainWindow() |
| | | { |
| | | list<HWND> wlist = Win32Util::searchWindow("短线精灵"); |
| | | list<HWND>::iterator ele; |
| | | for (ele = wlist.begin(); ele != wlist.end(); ele++) { |
| | | HWND hwnd = *ele; |
| | | if (Win32Util::isWindowShow(hwnd)) { |
| | | return hwnd; |
| | | } |
| | | |
| | | } |
| | | |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | HWND THSActionUtil::getTradeSuccessWindow() { |
| | | list<HWND> wlist = Win32Util::searchWindow("网上股票交易系统"); |
| | | list<HWND>::iterator ele; |
| | | for (ele = wlist.begin();ele != wlist.end();ele++) { |
| | | for (ele = wlist.begin(); ele != wlist.end(); ele++) { |
| | | HWND hwnd = *ele; |
| | | return hwnd; |
| | | } |
| | |
| | | HWND THSActionUtil::getSecondWindow() { |
| | | list<HWND> wlist = Win32Util::searchWindow("同花顺("); |
| | | list<HWND>::iterator ele; |
| | | for (ele = wlist.begin();ele != wlist.end();ele++) { |
| | | for (ele = wlist.begin(); ele != wlist.end(); ele++) { |
| | | HWND hwnd = *ele; |
| | | string str = Win32Util::getWindowName(hwnd); |
| | | if (isSecondScreen(str)) |
| | |
| | | HWND THSActionUtil::getMainWin() { |
| | | list<HWND> wlist = Win32Util::searchWindow("同花顺("); |
| | | list<HWND>::iterator ele; |
| | | for (ele = wlist.begin();ele != wlist.end();ele++) { |
| | | for (ele = wlist.begin(); ele != wlist.end(); ele++) { |
| | | HWND hwnd = *ele; |
| | | string str = Win32Util::getWindowName(hwnd); |
| | | |
| | |
| | | HWND THSActionUtil::getL2Win() { |
| | | list<HWND> wlist = Win32Util::searchWindow("同花顺("); |
| | | list<HWND>::iterator ele; |
| | | for (ele = wlist.begin();ele != wlist.end();ele++) { |
| | | for (ele = wlist.begin(); ele != wlist.end(); ele++) { |
| | | HWND hwnd = *ele; |
| | | string str = Win32Util::getWindowName(hwnd); |
| | | |
| | |
| | | HWND temp = NULL; |
| | | int content_count = 0; |
| | | while (TRUE) { |
| | | temp = FindWindowExA(mainWin, temp, "AfxWnd100s", NULL); |
| | | temp = FindWindowExA(mainWin, temp, "AfxWnd100s", NULL); |
| | | if (temp == NULL || temp <= 0) { |
| | | break; |
| | | } |
| | |
| | | content_count++; |
| | | } |
| | | } |
| | | if (content_count >= 16) |
| | | if (content_count >= L2_CHENNL_COUNT*2) |
| | | { |
| | | return hwnd; |
| | | } |
| | |
| | | bool fp = false; |
| | | bool fp2 = false; |
| | | bool zp = false; |
| | | for (ele = wlist.begin();ele != wlist.end();ele++) { |
| | | for (ele = wlist.begin(); ele != wlist.end(); ele++) { |
| | | HWND hwnd = *ele; |
| | | string str = Win32Util::getWindowName(hwnd); |
| | | if (isSecondScreen(str)) |
| | |
| | | int rows = area.endy - area.starty + 1; |
| | | int cols = area.endx - area.startx + 1; |
| | | cv::Mat mat = cv::Mat::zeros(rows, cols, CV_8UC1); |
| | | cv::Mat mat1 = cv::Mat(img,cv::Rect(area.startx, area.starty, cols, rows)); |
| | | uchar *datas =(uchar *) malloc(sizeof(uchar)*mat.rows* mat.cols); |
| | | cv::Mat mat1 = cv::Mat(img, cv::Rect(area.startx, area.starty, cols, rows)); |
| | | uchar* datas = (uchar*)malloc(sizeof(uchar) * mat.rows * mat.cols); |
| | | for (int r = 0; r < rows; r++) { |
| | | for (int c = 0; c < cols; c++) { |
| | | datas[r * cols + c] = mat1.ptr<uchar>(r)[c]; |
| | |
| | | for (list<OCRResult>::iterator ele = results.begin(); ele != results.end(); ++ele) |
| | | { |
| | | OCRResult result = *ele; |
| | | int x = area.startx + result.rect.left; |
| | | int x = area.startx + result.rect.left; |
| | | int y = area.starty + result.rect.top; |
| | | cv::Rect ocrRect = cv::Rect(x, y, result.rect.right - result.rect.left + 1, result.rect.bottom - result.rect.top + 1); |
| | | //判断是否选中,选中后背景颜色的色值为15,否则就未选中 |
| | |
| | | //ImgUtil::markMat(img,ocrRect,255,1); |
| | | Win32Util::showWindow(content); |
| | | Win32Util::focus(content); |
| | | |
| | | |
| | | // 未被选中 |
| | | if (selectColorCount < 20) |
| | | { |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | catch (string st) { |
| | |
| | | HWND mainPage = getMainWin(); |
| | | |
| | | list<HWND>::iterator ele; |
| | | for (ele = wlist.begin();ele != wlist.end();ele++) { |
| | | for (ele = wlist.begin(); ele != wlist.end(); ele++) { |
| | | HWND hwnd = *ele; |
| | | string str = Win32Util::getWindowName(hwnd); |
| | | if (isSecondScreen(str)) |
| | |
| | | HWND mainPage = 0; |
| | | |
| | | list<HWND>::iterator ele; |
| | | for (ele = wlist.begin();ele != wlist.end();ele++) { |
| | | for (ele = wlist.begin(); ele != wlist.end(); ele++) { |
| | | HWND hwnd = *ele; |
| | | string str = Win32Util::getWindowName(hwnd); |
| | | if (isThirdScreen(str)) |
| | |
| | | SendMessage(hwnd, WM_LBUTTONUP, 0x00000000, 0x00E70047); |
| | | } |
| | | |
| | | void THSActionUtil::openDXJLScreen() |
| | | { |
| | | HWND hw = getL2Win(); |
| | | if (hw <= 0) { |
| | | throw string("L2未打开"); |
| | | } |
| | | Win32Util::focus(hw); |
| | | Win32Util::keyboardNum("DXJL", 300); |
| | | Win32Util::keyboard(13, 10); |
| | | Sleep(1000); |
| | | DEVMODE device = Win32Util::getL2ScreenInfo(); |
| | | int device_width = device.dmPelsWidth; |
| | | int device_height = device.dmPelsHeight; |
| | | POINTL device_pos = device.dmPosition; |
| | | Win32Util::moveWin(THSActionUtil::getDXJLMainWindow(), device_pos.x + device_width / 2 + 30, device_pos.y + device_height / 2, 1120, 900); |
| | | } |
| | | |
| | | |
| | | //添加股票 |
| | | bool THSActionUtil::setGP(std::string quickCode, list<std::string> codeList, RecognitionManager* recognitionManager) { |
| | | bool THSActionUtil::setGP(std::string quickCode, list<std::string> codeList, RecognitionManager* recognitionManager, MatOcrFun ocrFun) { |
| | | |
| | | list<std::string> tempCodeList; |
| | | for (std::list<string>::iterator e = codeList.begin();e != codeList.end();e++) { |
| | | for (std::list<string>::iterator e = codeList.begin(); e != codeList.end(); e++) { |
| | | tempCodeList.push_back(*e); |
| | | } |
| | | |
| | |
| | | std::list<GPCodeArea> delList; |
| | | std::list<GPCodeArea> resultList = recognitionGPCodeNum(img, areaList, recognitionManager); |
| | | |
| | | for (std::list<GPCodeArea>::reverse_iterator ele = resultList.rbegin();ele != resultList.rend();++ele) { |
| | | for (std::list<GPCodeArea>::reverse_iterator ele = resultList.rbegin(); ele != resultList.rend(); ++ele) { |
| | | |
| | | bool contains = false; |
| | | std::list<string>::iterator e; |
| | | for (e = tempCodeList.begin();e != tempCodeList.end();e++) { |
| | | for (e = tempCodeList.begin(); e != tempCodeList.end(); e++) { |
| | | if (*e == (*ele).code) { |
| | | contains = true; |
| | | break; |
| | |
| | | Win32Util::mouseMove(rect.left + 10, rect.top + 5, 1); |
| | | Win32Util::click(10); |
| | | |
| | | for (std::list<GPCodeArea>::iterator ele = delList.begin();ele != delList.end();++ele) { |
| | | for (std::list<GPCodeArea>::iterator ele = delList.begin(); ele != delList.end(); ++ele) { |
| | | RECT rect; |
| | | GetWindowRect(content, &rect); |
| | | Win32Util::focus(sw); |
| | |
| | | |
| | | //----增加 |
| | | //截图,识别出增加按钮位置,点击增加,输入内容 |
| | | for (std::list<string>::iterator ele = tempCodeList.begin();ele != tempCodeList.end();++ele) { |
| | | for (std::list<string>::iterator ele = tempCodeList.begin(); ele != tempCodeList.end(); ++ele) { |
| | | if ((*ele).length() > 0) |
| | | { |
| | | addGP(*ele); |
| | | addGP(*ele, ocrFun); |
| | | Sleep(100); |
| | | } |
| | | } |
| | |
| | | img = ImgUtil::grayImage(oimg); |
| | | areaList = recognitionGPArea(img); |
| | | resultList = recognitionGPCodeNum(img, areaList, recognitionManager); |
| | | for (std::list<GPCodeArea>::iterator ele = resultList.begin();ele != resultList.end();++ele) { |
| | | for (std::list<GPCodeArea>::iterator ele = resultList.begin(); ele != resultList.end(); ++ele) { |
| | | bool contains = false; |
| | | std::list<string>::iterator e; |
| | | for (e = codeList.begin();e != codeList.end();e++) { |
| | | for (e = codeList.begin(); e != codeList.end(); e++) { |
| | | if (*e == (*ele).code) { |
| | | contains = true; |
| | | break; |
| | |
| | | } |
| | | |
| | | |
| | | void THSActionUtil::addGP(string code) { |
| | | bool THSActionUtil::addGP(string code, MatOcrFun ocrFun) { |
| | | clock_t start_time = clock(); |
| | | //打开副屏 |
| | | HWND sw = getSecondWindow(); |
| | | if (sw <= 0) |
| | |
| | | throw string("板块截屏内容为空(15)"); |
| | | } |
| | | std::list<GPCodeArea> areaList = recognitionGPArea(img); |
| | | for (std::list<GPCodeArea>::iterator ele = areaList.begin();ele != areaList.end();++ele) { |
| | | |
| | | |
| | | for (std::list<GPCodeArea>::iterator ele = areaList.begin(); ele != areaList.end(); ++ele) { |
| | | GPCodeArea codeArea = *ele; |
| | | if (codeArea.type == IMG_TYPE_ADD) { |
| | | Win32Util::focus(sw); |
| | |
| | | GetWindowRect(content, &rc); |
| | | int y = rc.top + codeArea.starty + (codeArea.endy - codeArea.starty) / 2; |
| | | int x = rc.left + codeArea.startx + (codeArea.endx - codeArea.startx) / 2; |
| | | Win32Util::click(x, y, 50); |
| | | Sleep(10); |
| | | Win32Util::click(x, y, 50); |
| | | Sleep(10); |
| | | Win32Util::click(x, y, 50); |
| | | //截图 |
| | | HWND addGPWin = 0; |
| | | for (int i = 0; i < 6; i++) { |
| | | Win32Util::click(x, y, 50); |
| | | for (int j = 0; j < 20; j++) { |
| | | list<HWND> winList = Win32Util::searchWindow("添加股票"); |
| | | if (winList.size() > 0) { |
| | | for (list<HWND>::iterator ele = winList.begin(); ele != winList.end(); ele++) { |
| | | if (Win32Util::isWindowShow(*ele)) { |
| | | addGPWin = *ele; |
| | | break; |
| | | } |
| | | else { |
| | | cout << "代码框没显示" << endl; |
| | | } |
| | | } |
| | | } |
| | | else { |
| | | cout << "没有获取到代码框" << endl; |
| | | Sleep(50); |
| | | } |
| | | } |
| | | if (addGPWin > 0) { |
| | | break; |
| | | } |
| | | else { |
| | | Sleep(50); |
| | | } |
| | | } |
| | | if (addGPWin <= 0) { |
| | | throw string("未打开添加代码Window(16)"); |
| | | } |
| | | |
| | | |
| | | //输入股票代码 |
| | | Win32Util::keyboardNum(code, 1000); |
| | | Win32Util::keyboard(VK_RETURN, 1500); |
| | | Win32Util::keyboardNum(code, 50); |
| | | // 识别第一个位置的内容 |
| | | |
| | | |
| | | bool set_success = FALSE; |
| | | for (int i = 0; i < 10; i++) { |
| | | cv::Mat img_ = CaptureUtil::capture(addGPWin); |
| | | cv::Mat grayImg_ = ImgUtil::grayImage(img_); |
| | | cv::Mat rectImg = cv::Mat(grayImg_, cv::Rect(40, 145, 50, 26)); |
| | | cv::Mat targetImg = rectImg.clone(); |
| | | rectImg.copyTo(targetImg); |
| | | try { |
| | | list<OCRResult> resultList = ocrFun(code, targetImg); |
| | | if (resultList.size() > 0) { |
| | | set_success = TRUE; |
| | | break; |
| | | } |
| | | else { |
| | | Sleep(100); |
| | | } |
| | | } |
| | | catch (...) { |
| | | Sleep(100); |
| | | } |
| | | } |
| | | if (set_success) |
| | | { |
| | | Win32Util::keyboard(VK_RETURN, 50); |
| | | } |
| | | //关闭按钮 |
| | | Sleep(100); |
| | | Sleep(50); |
| | | HWND close = FindWindowA(0, "添加股票"); |
| | | PostMessage(close, WM_CLOSE, 0, 0); |
| | | break; |
| | | return set_success; |
| | | } |
| | | } |
| | | |
| | | return FALSE; |
| | | } |
| | | |
| | | |
| | |
| | | int endf = -1; |
| | | std::list<int*> dataItemList; |
| | | |
| | | for (int i = start_row;i < end_row;i++) { |
| | | for (int i = start_row; i < end_row; i++) { |
| | | //TODO 100 |
| | | bool empty = ImgDivider::isRowEmpty(img, i, start_col, start_col + 50, 1, _IMG_BINARY_THRESHOLD) && ImgDivider::isRowEmpty(img, i, start_col + 50, start_col + 150, 2, _IMG_BINARY_THRESHOLD) && ImgDivider::isRowEmpty(img, i, start_col + (end_col - start_col) / 2 - 40, start_col + (end_col - start_col) / 2 + 40, 1, _IMG_BINARY_THRESHOLD); |
| | | if (empty) { |
| | |
| | | int r; |
| | | int contentStartRow = -1; |
| | | int contentEndRow = -1; |
| | | for (r = 5;r < img.rows;r++) { |
| | | for (r = 5; r < img.rows; r++) { |
| | | if (ImgDivider::isRowFull(img, r, 0, cols - 5, 3, 12, 30)) { |
| | | |
| | | if (contentStartRow < 0) |
| | |
| | | //分隔列 |
| | | int c = 0; |
| | | int startC = -1; |
| | | for (c = 0;c < cols;c++) { |
| | | for (c = 0; c < cols; c++) { |
| | | if (ImgDivider::isColFull(img, c, contentStartRow + 5, contentStartRow + 100, 2)) { |
| | | if (startC < 0 && c>50) { |
| | | startC = c; |
| | |
| | | int cols = img.cols; |
| | | int r; |
| | | int contentStartRow = -1; |
| | | for (r = 5;r < img.rows;r++) { |
| | | for (r = 5; r < img.rows; r++) { |
| | | if (ImgDivider::isRowFull(img, r, cols - 100, cols - 5, 2)) { |
| | | contentStartRow = r; |
| | | } |
| | |
| | | int c = 0; |
| | | int startC = -1; |
| | | int endC = -1; |
| | | for (c = 50;c < cols;c++) { |
| | | for (c = 50; c < cols; c++) { |
| | | if (ImgDivider::isColFull(img, c, contentStartRow + 5, contentStartRow + 100, 2)) { |
| | | if (startC < 0) { |
| | | startC = c; |
| | |
| | | |
| | | //再次分隔内容框,排除干扰 |
| | | int cut_index = -1; |
| | | for (int r = contentStartRow + 5;r < contentStartRow + 5 + 100;r++) { |
| | | for (int r = contentStartRow + 5; r < contentStartRow + 5 + 100; r++) { |
| | | |
| | | if (ImgDivider::isRowFull(img, r, startC, endC, 2, 25, 30)) { |
| | | cut_index = r; |
| | |
| | | //分隔每一列的数据 |
| | | std::list<int*>::iterator ele; |
| | | int index = 0; |
| | | for (ele = dataItemList.begin(); ele != dataItemList.end();ele++) { |
| | | for (ele = dataItemList.begin(); ele != dataItemList.end(); ele++) { |
| | | index++; |
| | | int startRow = *(*ele + 1); |
| | | int startCol = *(*ele + 0); |
| | |
| | | |
| | | std::list<int*> rowDataList; |
| | | |
| | | for (int i = startCol;i <= endCol;i++) { |
| | | for (int i = startCol; i <= endCol; i++) { |
| | | bool empty = ImgDivider::isColEmpty(img, i, startRow, endRow, 64); |
| | | if (empty) { |
| | | if (emptyStart < 0) { |
| | |
| | | resultList.push_back(area); |
| | | } |
| | | } |
| | | else if(rowDataList.size()>0) { |
| | | else if (rowDataList.size() > 0) { |
| | | std::list<int*>::iterator ele = rowDataList.begin(); |
| | | GPCodeArea area = GPCodeArea(); |
| | | area.type = IMG_TYPE_ADD; |
| | |
| | | //内存释放 |
| | | if (rowDataList.size() > 0) |
| | | { |
| | | for (std::list<int*>::iterator e = rowDataList.begin();e != rowDataList.end();e++) { |
| | | for (std::list<int*>::iterator e = rowDataList.begin(); e != rowDataList.end(); e++) { |
| | | free(*e); |
| | | } |
| | | } |
| | |
| | | { |
| | | std::list<int*>::iterator ele1; |
| | | int cc = 0; |
| | | for (ele1 = rowDataList.begin(); ele1 != rowDataList.end();ele1++) { |
| | | for (ele1 = rowDataList.begin(); ele1 != rowDataList.end(); ele1++) { |
| | | if (*ele1) |
| | | { |
| | | int startCRow = *(*ele1 + 1); |
| | |
| | | int cols = img.cols; |
| | | int r; |
| | | int contentStartRow = -1; |
| | | for (r = 5;r < img.rows;r++) { |
| | | for (r = 5; r < img.rows; r++) { |
| | | if (ImgDivider::isRowFull(img, r, cols - 100, cols - 5, 2)) { |
| | | contentStartRow = r; |
| | | } |
| | |
| | | int c = 0; |
| | | int startC = -1; |
| | | int endC = -1; |
| | | for (c = 50;c < cols;c++) { |
| | | for (c = 50; c < cols; c++) { |
| | | if (ImgDivider::isColFull(img, c, contentStartRow + 5, contentStartRow + 100, 2)) { |
| | | if (startC < 0) { |
| | | startC = c; |
| | |
| | | std::list<GPCodeArea>::iterator ele; |
| | | |
| | | int index = 0; |
| | | for (ele = areaList.begin();ele != areaList.end();ele++) { |
| | | for (ele = areaList.begin(); ele != areaList.end(); ele++) { |
| | | index++; |
| | | GPCodeArea codeArea = *ele; |
| | | if (codeArea.type == IMG_TYPE_GP) { |
| | |
| | | if (false) { |
| | | std::list<cv::Mat>::iterator e; |
| | | int ci = 0; |
| | | for (e = list2.begin();e != list2.end();e++) { |
| | | for (e = list2.begin(); e != list2.end(); e++) { |
| | | ci++; |
| | | string path = "C:\\Users\\Administrator\\Desktop\\ocr\\gpcode\\"; |
| | | path.append(to_string(index)).append("_").append(to_string(ci)); |
| | |
| | | codeList.push_back(codeArea); |
| | | } |
| | | catch (...) { |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | std::list<GPCodeArea> areaList = recognitionGPArea(grayImg); |
| | | std::list<GPCodeArea> list = recognitionGPCodeNum(grayImg, areaList, recognitionManager); |
| | | std::list<string> resultList; |
| | | for (std::list<GPCodeArea>::iterator ele = list.begin();ele != list.end();ele++) { |
| | | for (std::list<GPCodeArea>::iterator ele = list.begin(); ele != list.end(); ele++) { |
| | | resultList.push_back((*ele).code); |
| | | } |
| | | return resultList; |
| | |
| | | int cols = img.cols; |
| | | int contentStartRow = -1; |
| | | int contentEndRow = -1; |
| | | for (int r = 5;r < img.rows;r++) { |
| | | for (int r = 5; r < img.rows; r++) { |
| | | if (ImgDivider::isRowFull(img, r, 10, 200, 2, 10, 30) && ImgDivider::isRowFull(img, r, img.cols - 200, img.cols - 1, 2, 10, 30)) { |
| | | if (contentStartRow < 0) |
| | | { |
| | |
| | | int startf = -1; |
| | | int endf = -1; |
| | | int startIndex = -1; |
| | | for (int i = 10;i < cols;i++) { |
| | | for (int i = 10; i < cols; i++) { |
| | | if (startIndex == -1) { |
| | | startIndex = i; |
| | | } |
| | |
| | | |
| | | std::list<GPCodeArea> areaList; |
| | | list<int*>::iterator ele; |
| | | for (ele = dataColIndexs.begin();ele != dataColIndexs.end();ele++) { |
| | | for (ele = dataColIndexs.begin(); ele != dataColIndexs.end(); ele++) { |
| | | int* p = *ele; |
| | | int startx = *p; |
| | | int endx = *(p + 1); |
| | | |
| | | int endRow = 0; |
| | | //判断结束行 |
| | | for (int r = contentStartRow + 10;r < img.rows;r++) { |
| | | for (int r = contentStartRow + 10; r < img.rows; r++) { |
| | | bool full = ImgDivider::isRowFull(img, r, startx, endx, 2, 10, 30); |
| | | if (full) { |
| | | endRow = r; |
| | |
| | | int cols = img.cols; |
| | | int contentStartRow = -1; |
| | | int contentEndRow = -1; |
| | | for (int r = 5;r < img.rows;r++) { |
| | | for (int r = 5; r < img.rows; r++) { |
| | | if (ImgDivider::isRowFull(img, r, 0, img.cols / 3, 2, 10, 30) && ImgDivider::isRowFull(img, r, img.cols * 2 / 3, img.cols, 2, 10, 30)) { |
| | | if (contentStartRow < 0) |
| | | { |
| | |
| | | int startf = -1; |
| | | int endf = -1; |
| | | int startIndex = -1; |
| | | for (int i = 10;i < cols;i++) { |
| | | for (int i = 10; i < cols; i++) { |
| | | if (startIndex == -1) { |
| | | startIndex = i; |
| | | } |
| | |
| | | |
| | | std::list<GPCodeArea> areaList; |
| | | list<int*>::iterator ele; |
| | | for (ele = dataColIndexs.begin();ele != dataColIndexs.end();ele++) { |
| | | for (ele = dataColIndexs.begin(); ele != dataColIndexs.end(); ele++) { |
| | | int* p = *ele; |
| | | int startx = *p; |
| | | int endx = *(p + 1); |
| | | |
| | | int endRow = 0; |
| | | //判断结束行 |
| | | for (int r = contentStartRow + 10;r < img.rows;r++) { |
| | | for (int r = contentStartRow + 10; r < img.rows; r++) { |
| | | bool full = ImgDivider::isRowFull(img, r, startx, endx, 2, 10, 30); |
| | | if (full) { |
| | | endRow = r; |
| | |
| | | std::map<int, string> THSActionUtil::getListenL2GPCodes(RecognitionManager* recognitionManager) { |
| | | std::list<GPCodeArea> areaList = getListenL2GPAreaAndCode(recognitionManager); |
| | | std::map<int, string> map; |
| | | for (std::list<GPCodeArea>::iterator ele = areaList.begin();ele != areaList.end();ele++) { |
| | | for (std::list<GPCodeArea>::iterator ele = areaList.begin(); ele != areaList.end(); ele++) { |
| | | GPCodeArea data = (*ele); |
| | | if (map.count(data.cateIndex) == 0 && data.type == IMG_TYPE_GP) { |
| | | map[data.cateIndex] = data.code; |
| | |
| | | ofstream ofs; |
| | | ofs.open(path, ios::trunc); |
| | | int index = 0; |
| | | for (list<string>::iterator ele = codeList.begin();ele != codeList.end();++ele) |
| | | for (list<string>::iterator ele = codeList.begin(); ele != codeList.end(); ++ele) |
| | | { |
| | | index++; |
| | | ofs << *ele; |
| | |
| | | |
| | | |
| | | HWND hwnd = HWND(0); |
| | | for (int i = 0;i < 10;i++) |
| | | for (int i = 0; i < 10; i++) |
| | | { |
| | | HWND temp = FindWindowA("#32770", "打开"); |
| | | if (temp > 0) { |
| | |
| | | list<HWND> wlist = Win32Util::searchWindow("同花顺("); |
| | | HWND mainPage = 0; |
| | | list<HWND>::iterator ele; |
| | | for (ele = wlist.begin();ele != wlist.end();ele++) { |
| | | for (ele = wlist.begin(); ele != wlist.end(); ele++) { |
| | | HWND hwnd = *ele; |
| | | string str = Win32Util::getWindowName(hwnd); |
| | | if (isL2Screen(str)) { |
| | |
| | | std::list<GPCodeArea> fresultList; |
| | | |
| | | int index = 0; |
| | | for (std::list<GPCodeArea>::iterator ele = areaList.begin();ele != areaList.end();ele++) { |
| | | for (std::list<GPCodeArea>::iterator ele = areaList.begin(); ele != areaList.end(); ele++) { |
| | | GPCodeArea area = *ele; |
| | | if (false) { |
| | | string path = "C:\\Users\\Administrator\\Desktop\\ocr\\gpcode\\"; |
| | |
| | | std::list<GPCodeArea> resultList = splitGPCodeArea(img, area.starty + 20, area.startx, area.endy, area.endx); |
| | | |
| | | |
| | | for (std::list<GPCodeArea>::iterator ele1 = resultList.begin();ele1 != resultList.end();ele1++) { |
| | | for (std::list<GPCodeArea>::iterator ele1 = resultList.begin(); ele1 != resultList.end(); ele1++) { |
| | | GPCodeArea areaC = *ele1; |
| | | if (areaC.type == IMG_TYPE_GP) { |
| | | cv::Mat src = cv::Mat(img, cv::Rect(areaC.startx, areaC.starty, areaC.endx - areaC.startx + 1, areaC.endy - areaC.starty + 1)); |
| | |
| | | fresultList.push_back(*ele1); |
| | | } |
| | | catch (...) { |
| | | |
| | | |
| | | } |
| | | } |
| | | } |
| | |
| | | int index = 0; |
| | | for (std::list<GPCodeArea>::iterator ele = areaList.begin(); ele != areaList.end(); ele++) { |
| | | GPCodeArea area = *ele; |
| | | |
| | | |
| | | int startRow = -1; |
| | | int endRow = -1; |
| | | for (int r = area.endy; r >= area.starty; r--) { |
| | | |
| | | if (!ImgDivider::isRowEmpty(img, r, area.startx, (area.endx + area.startx)/2)) { |
| | | |
| | | if (!ImgDivider::isRowEmpty(img, r, area.startx, (area.endx + area.startx) / 2)) { |
| | | if (startRow < 0) |
| | | { |
| | | startRow = r; |
| | |
| | | //获取到分隔点 |
| | | GPCodeArea child; |
| | | child.startx = start_col; |
| | | child.endx = c -1; |
| | | child.endx = c - 1; |
| | | child.starty = area.starty; |
| | | child.endy = area.endy; |
| | | tempList.push_back(child); |
| | |
| | | index++; |
| | | ffresultList.push_back(tempList); |
| | | } |
| | | |
| | | |
| | | |
| | | return ffresultList; |
| | | |
| | |
| | | } |
| | | |
| | | //点击按钮 |
| | | Win32Util::visualClick(btn, MAKELONG(3,3)); |
| | | for (int i = 0;i < 10;i++) { |
| | | Win32Util::visualClick(btn, MAKELONG(3, 3)); |
| | | for (int i = 0; i < 10; i++) { |
| | | list<HWND> _list = Win32Util::searchWindow("选择最优行情主站"); |
| | | if (_list.size() > 0) { |
| | | HWND win = *(_list.begin()); |
| | | HWND loginBtn = 0; |
| | | for (int j = 0;j < 10;j++) |
| | | for (int j = 0; j < 10; j++) |
| | | { |
| | | loginBtn = FindWindowExA(win, NULL, "Button", "登 录"); |
| | | loginBtn = FindWindowExA(win, NULL, "Button", "登 录"); |
| | | if (loginBtn > 0) { |
| | | // 优先选择电信 |
| | | HWND dianXin = FindWindowExA(win, NULL, "Button", "中国电信"); |
| | | if (dianXin > 0) { |
| | | Win32Util::visualClick(dianXin, MAKELONG(2, 2)); |
| | | Sleep(100); |
| | | } |
| | | //点击登录按钮 |
| | | Win32Util::visualClick(loginBtn, MAKELONG(2, 2)); |
| | | break; |
| | |
| | | |
| | | |
| | | } |
| | | bool THSActionUtil::screenL2Money(HWND l2_hwnd, string money, MatOcrFun ocrFun) |
| | | { |
| | | if (!Win32Util::isWindowShow(l2_hwnd)) { |
| | | throw string("L2窗口句柄未展示"); |
| | | } |
| | | |
| | | HWND win = FindWindowExA(l2_hwnd, NULL, "#32770", NULL); |
| | | win = FindWindowExA(win, NULL, "stock_trade_info_dlg", "stock_trade_info"); |
| | | if (win <= 0) { |
| | | throw string("未找到L2窗口的内容"); |
| | | } |
| | | RECT rect; |
| | | Win32Util::getWindowRect(win, &rect); |
| | | //重试5次 |
| | | for (int i = 0; i < 5; i++) { |
| | | Win32Util::postMessage(win, WM_LBUTTONDOWN, MAKELONG(1, 0), MAKELONG(0x007E, 0x000A)); |
| | | Win32Util::sendMessage(win, WM_PARENTNOTIFY, MAKELONG(1, 0), MAKELONG(0x2FBC, 0x000B)); |
| | | Win32Util::postMessage(win, WM_LBUTTONUP, MAKELONG(1, 0), MAKELONG(0x007E, 0x000A)); |
| | | Sleep(10); |
| | | HWND child = FindWindowExA(win, NULL, "EditWnd", NULL); |
| | | if (child > 0) |
| | | { |
| | | RECT editRect; |
| | | Win32Util::getWindowRect(child, &editRect); |
| | | //Win32Util::focus(child); |
| | | Win32Util::input_num(child, money); |
| | | Win32Util::focus(child); |
| | | Sleep(50); |
| | | cv::Mat mat = CaptureUtil::capture(win); |
| | | cv::Mat grayImg = ImgUtil::grayImage(mat); |
| | | cv::Mat rectMat = cv::Mat(grayImg, cv::Rect(editRect.left - rect.left, editRect.top - rect.top, editRect.right - editRect.left, editRect.bottom - editRect.top)); |
| | | |
| | | //ImgUtil::markMat(grayImg, cv::Rect(editRect.left - rect.left, editRect.top - rect.top, editRect.right - editRect.left, editRect.bottom - editRect.top),255,1); |
| | | cv::Mat targetMat = rectMat.clone(); |
| | | rectMat.copyTo(targetMat); |
| | | |
| | | list<OCRResult> results = ocrFun(".", targetMat); |
| | | string newmoney = ""; |
| | | for (list<OCRResult>::iterator ele = results.begin(); ele != results.end(); ++ele) { |
| | | newmoney.append((*ele).text); |
| | | } |
| | | if (newmoney == money) { |
| | | return TRUE; |
| | | } |
| | | } |
| | | } |
| | | return FALSE; |
| | | } |
| | | void THSActionUtil::clearPlateCodes(HWND hwnd) |
| | | { |
| | | HWND content = FindWindowExA(hwnd, NULL, "AfxFrameOrView100s", NULL); |
| | | for (int i = 0;i < 15;i++) |
| | | for (int i = 0; i < 15; i++) |
| | | { |
| | | //截图识别是否还有代码 |
| | | cv::Mat oimg = CaptureUtil::capture(content); |
| | |
| | | break; |
| | | } |
| | | //执行删除事件 |
| | | for (int j = 0;j < 20;j++) { |
| | | for (int j = 0; j < 20; j++) { |
| | | Win32Util::focus(hwnd); |
| | | Win32Util::keyboard(VK_DELETE, 30); |
| | | } |
| | |
| | | cv::Mat img = ImgUtil::grayImage(oimg); |
| | | oimg.release(); |
| | | std::list<GPCodeArea> areaList = recognitionGPArea(img); |
| | | for (std::list<GPCodeArea>::iterator ele = areaList.begin();ele != areaList.end();ele++) { |
| | | for (std::list<GPCodeArea>::iterator ele = areaList.begin(); ele != areaList.end(); ele++) { |
| | | cout << "添加按钮位置:" << (*ele).startx << "," << (*ele).starty << "," << (*ele).endx << "," << (*ele).endy << endl; |
| | | if ((*ele).type == IMG_TYPE_ADD) { |
| | | RECT rect; |
| | |
| | | HWND content = FindWindowExA(getL2Win(), NULL, "AfxFrameOrView100s", NULL); |
| | | |
| | | int index = 0; |
| | | for (std::list<GPCodeArea>::iterator ele = resultList.begin();ele != resultList.end();ele++) { |
| | | for (std::list<GPCodeArea>::iterator ele = resultList.begin(); ele != resultList.end(); ele++) { |
| | | GPCodeArea result = *ele; |
| | | if (result.code == code) { |
| | | //点击 |
| | |
| | | int cols = grayImg.cols; |
| | | int r; |
| | | int contentStartRow = -1; |
| | | for (r = 5;r < grayImg.rows;r++) { |
| | | for (r = 5; r < grayImg.rows; r++) { |
| | | if (ImgDivider::isRowFull(grayImg, r, cols - 100, cols - 5, 2)) { |
| | | contentStartRow = r; |
| | | } |
| | |
| | | int c = 0; |
| | | int startC = -1; |
| | | int endC = -1; |
| | | for (c = 50;c < cols;c++) { |
| | | for (c = 50; c < cols; c++) { |
| | | if (ImgDivider::isColFull(grayImg, c, contentStartRow + 5, contentStartRow + 100, 2)) { |
| | | if (startC < 0) { |
| | | startC = c; |
| | |
| | | |
| | | //批量添加代码 |
| | | HWND addDLG; |
| | | for (int i = 0;i < 10;i++) { |
| | | for (int i = 0; i < 10; i++) { |
| | | addDLG = FindWindowA("#32770", "添加股票"); |
| | | if (addDLG > 0) { |
| | | break; |
| | |
| | | } |
| | | else { |
| | | //逐个添加 |
| | | for (list<std::string>::iterator ele = codeList.begin();ele != codeList.end();++ele) { |
| | | for (list<std::string>::iterator ele = codeList.begin(); ele != codeList.end(); ++ele) { |
| | | string code = *ele; |
| | | Win32Util::focus(addDLG); |
| | | for (int i = 0;i < 6;i++) |
| | | for (int i = 0; i < 6; i++) |
| | | { |
| | | Win32Util::keyboard(VK_BACK, 10); |
| | | } |