From ae66a5e07a2ebb455e83c65ded12697fd0fece98 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期五, 08 七月 2022 18:43:49 +0800 Subject: [PATCH] 'bug修复' --- ConsoleApplication/THSActionUtil.cpp | 116 ++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 97 insertions(+), 19 deletions(-) diff --git a/ConsoleApplication/THSActionUtil.cpp b/ConsoleApplication/THSActionUtil.cpp index 017e87c..6f01774 100644 --- a/ConsoleApplication/THSActionUtil.cpp +++ b/ConsoleApplication/THSActionUtil.cpp @@ -2,8 +2,6 @@ #include "ImgDivider.h" #include "Win32Util.h" -RecognitionManager* THSActionUtil::recognitionManager; - bool isMainScreen(string str) { if (str.find("同花顺(") != string::npos) { cout << str << endl; @@ -17,7 +15,11 @@ } bool isSecondScreen(string str) { - return str.find("同花顺(") != string::npos && str.find("副屏") != string::npos; + return str.find("同花顺(") != string::npos && str.find("副屏1") != string::npos; +} + +bool isThirdScreen(string str) { + return str.find("同花顺(") != string::npos && str.find("副屏2") != string::npos; } std::list<cv::Mat> splitGPCodeNum(cv::Mat img) { @@ -41,9 +43,23 @@ return nums; } +//获取副屏2 +HWND getThirdWindow() { + list<HWND> wlist = Win32Util::searchWindow("同花顺("); + list<HWND>::iterator ele; + for (ele = wlist.begin();ele != wlist.end();ele++) { + HWND hwnd = *ele; + string str = Win32Util::getWindowName(hwnd); + if (isSecondScreen(str)) + { + return hwnd; + } + } + return 0; +} -//获取副屏 +//获取副屏1 HWND getSecondWindow() { list<HWND> wlist = Win32Util::searchWindow("同花顺("); list<HWND>::iterator ele; @@ -78,6 +94,7 @@ list<HWND> wlist = Win32Util::searchWindow("同花顺("); list<HWND>::iterator ele; bool fp = false; + bool fp2 = false; bool zp = false; for (ele = wlist.begin();ele != wlist.end();ele++) { HWND hwnd = *ele; @@ -85,6 +102,11 @@ if (isSecondScreen(str)) { fp = true; + } + + if (isThirdScreen(str)) + { + fp2 = true; } if (isMainScreen(str)) { @@ -99,7 +121,11 @@ if (!fp) { - throw string("同花顺副屏没有打开"); + throw string("同花顺副屏1没有打开"); + } + + if (!fp2) { + throw string("同花顺副屏2没有打开"); } return true; @@ -163,7 +189,7 @@ } } //添加股票 -bool THSActionUtil::setGP(std::string quickCode, list<std::string> codeList) { +bool THSActionUtil::setGP(std::string quickCode, list<std::string> codeList, RecognitionManager* recognitionManager) { list<std::string> tempCodeList; for (std::list<string>::iterator e = codeList.begin();e != codeList.end();e++) { @@ -209,7 +235,7 @@ std::list<string> addList; std::list<GPCodeArea> delList; - std::list<GPCodeArea> resultList = recognitionNum(img, areaList); + std::list<GPCodeArea> resultList = recognitionGPCodeNum(img, areaList,recognitionManager); for (std::list<GPCodeArea>::reverse_iterator ele = resultList.rbegin();ele != resultList.rend();++ele) { @@ -269,7 +295,7 @@ } img = ImgUtil::grayImage(oimg); areaList = recognitionGPArea(img); - resultList = recognitionNum(img, areaList); + resultList = recognitionGPCodeNum(img, areaList,recognitionManager); for (std::list<GPCodeArea>::iterator ele = resultList.begin();ele != resultList.end();++ele) { bool contains = false; std::list<string>::iterator e; @@ -596,11 +622,8 @@ return resultList; } -std::list<GPCodeArea> THSActionUtil::recognitionNum(cv::Mat img, std::list<GPCodeArea> areaList) { +std::list<GPCodeArea> THSActionUtil::recognitionGPCodeNum(cv::Mat img, std::list<GPCodeArea> areaList, RecognitionManager *recognitionManager) { - if (!recognitionManager) { - recognitionManager = new RecognitionManager(); - } //识别数字 std::list<GPCodeArea> codeList; @@ -652,10 +675,10 @@ } -std::list<string> THSActionUtil::recognitionGPCode(cv::Mat img) { +std::list<string> THSActionUtil::recognitionGPCode(cv::Mat img, RecognitionManager* recognitionManager) { cv::Mat grayImg = ImgUtil::grayImage(img); std::list<GPCodeArea> areaList = recognitionGPArea(grayImg); - std::list<GPCodeArea> list = recognitionNum(grayImg, areaList); + std::list<GPCodeArea> list = recognitionGPCodeNum(grayImg, areaList,recognitionManager); std::list<string> resultList; for (std::list<GPCodeArea>::iterator ele = list.begin();ele != list.end();ele++) { resultList.push_back((*ele).code); @@ -777,8 +800,8 @@ -std::map<int, string> THSActionUtil::getListenL2GPCodes() { - std::list<GPCodeArea> areaList = getListenL2GP(); +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++) { GPCodeArea data = (*ele); @@ -791,7 +814,7 @@ } -std::list<GPCodeArea> THSActionUtil::getListenL2GP() { +std::list<GPCodeArea> THSActionUtil::getListenL2GPAreaAndCode(RecognitionManager *recognitionManager) { //截图当前有哪些股票代码 list<HWND> wlist = Win32Util::searchWindow("同花顺("); HWND mainPage = 0; @@ -862,10 +885,10 @@ return fresultList; } -bool THSActionUtil::setListenL2GP(int p, string code) { +bool THSActionUtil::setListenL2GP(int p, string code, RecognitionManager* recognitionManager) { - std::list<GPCodeArea> resultList = getListenL2GP(); + std::list<GPCodeArea> resultList = getListenL2GPAreaAndCode(recognitionManager); HWND content = FindWindowExA(getL2Win(), NULL, "AfxFrameOrView100s", NULL); @@ -884,4 +907,59 @@ } } return false; +} + + +GPCodeArea THSActionUtil::recognitionPlateContentArea(cv::Mat grayImg) { + + int rows = grayImg.rows; + int cols = grayImg.cols; + int r; + int contentStartRow = -1; + for (r = 5;r < grayImg.rows;r++) { + if (ImgDivider::isRowFull(grayImg, r, cols - 100, cols - 5, 2)) { + contentStartRow = r; + } + + if (contentStartRow > -1) { + break; + } + } + + if (contentStartRow < 0) { + throw string("起始行分隔出错"); + } + + //分隔列 + int c = 0; + int startC = -1; + int endC = -1; + for (c = 50;c < cols;c++) { + if (ImgDivider::isColFull(grayImg, c, contentStartRow + 5, contentStartRow + 100, 2)) { + if (startC < 0) { + startC = c; + } + else { + if (c - startC < 20) { + startC = c; + } + else { + endC = c; + break; + } + } + } + } + + if (startC < 0 || endC < 0) { + throw string("内容框分隔出错"); + } + + GPCodeArea area = GPCodeArea(); + area.startx = startC; + area.starty = contentStartRow; + area.endx = endC; + area.endy = rows - 1; + + return area; } \ No newline at end of file -- Gitblit v1.8.0