From 3680049029e6a193eae069596be04ce0fb2b1303 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期六, 05 十一月 2022 17:19:55 +0800
Subject: [PATCH] '增加l2稳定性'

---
 ConsoleApplication/THSActionUtil.cpp |  120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 120 insertions(+), 0 deletions(-)

diff --git a/ConsoleApplication/THSActionUtil.cpp b/ConsoleApplication/THSActionUtil.cpp
index 76e1ddc..f78a4e6 100644
--- a/ConsoleApplication/THSActionUtil.cpp
+++ b/ConsoleApplication/THSActionUtil.cpp
@@ -1337,6 +1337,7 @@
 	SendMessage(close, WM_CLOSE, 0, 0);
 }
 
+
 std::list<GPCodeArea> THSActionUtil::getListenL2GPAreaAndCode(RecognitionManager* recognitionManager) {
 	//截图当前有哪些股票代码
 	list<HWND> wlist = Win32Util::searchWindow("同花顺(");
@@ -1364,6 +1365,7 @@
 	//截图
 	cv::Mat oimg = CaptureUtil::capture(content);
 	cv::Mat img = ImgUtil::grayImage(oimg);
+
 	oimg.release();
 	//分隔图片
 
@@ -1420,6 +1422,124 @@
 
 }
 
+
+// 获取操作区域
+std::list<std::list<GPCodeArea>> THSActionUtil::getListenL2GPAreaActionBar() {
+	//截图当前有哪些股票代码
+	list<HWND> wlist = Win32Util::searchWindow("同花顺(");
+	HWND mainPage = 0;
+	list<HWND>::iterator ele;
+	for (ele = wlist.begin(); ele != wlist.end(); ele++) {
+		HWND hwnd = *ele;
+		string str = Win32Util::getWindowName(hwnd);
+		if (isL2Screen(str)) {
+			cout << hwnd << endl;
+			//获取尺寸
+			RECT rc;
+			GetWindowRect(hwnd, &rc);
+			if (rc.right - rc.left > 200 && rc.bottom - rc.top > 200) {
+				mainPage = hwnd;
+				break;
+			}
+		}
+	}
+	if (mainPage <= 0) {
+		throw string("L2监听未打开(25)");
+	}
+
+	HWND content = FindWindowExA(mainPage, NULL, "AfxFrameOrView100s", NULL);
+	//截图
+	cv::Mat oimg = CaptureUtil::capture(content);
+	cv::Mat img = ImgUtil::grayImage(oimg);
+
+	oimg.release();
+	//分隔图片
+
+	std::list<GPCodeArea>  areaList = splitL2Cate(img);
+	std::list<GPCodeArea> fresultList;
+
+	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 (startRow < 0)
+				{
+					startRow = r;
+					endRow = r;
+				}
+				endRow = r;
+			}
+			else {
+				if (startRow > 0 && endRow > 0) {
+					if (startRow - endRow > 10) {
+						GPCodeArea farea;
+						farea.startx = area.startx;
+						farea.endx = area.endx;
+						farea.starty = endRow;
+						farea.endy = startRow;
+						fresultList.push_back(farea);
+						// TODO 暂时打开
+						if (false) {
+							string path = "C:\\Users\\Administrator\\Desktop\\ocr\\gpcode\\";
+							path.append("cate_").append(to_string(index)).append(".jpg");
+							cv::imwrite(path, cv::Mat(img, cv::Rect(farea.startx, farea.starty, farea.endx - farea.startx + 1, farea.endy - farea.starty + 1)));
+						}
+						break;
+					}
+					else {
+						startRow = endRow;
+					}
+				}
+			}
+		}
+		index++;
+	}
+
+	index = 0;
+	std::list<list<GPCodeArea>> ffresultList;
+	//切割每一块的菜单
+	for (std::list<GPCodeArea>::iterator ele = fresultList.begin(); ele != fresultList.end(); ele++) {
+		GPCodeArea area = *ele;
+		int start_col = area.startx;
+
+		list<GPCodeArea> tempList;
+
+		for (int c = area.startx; c <= area.endx; c++) {
+			//通过第一行的纯黑点做分隔
+			if (img.ptr<uchar>(area.starty)[c] <= 5) {
+				if (c - start_col > 10) {
+					//获取到分隔点
+					GPCodeArea child;
+					child.startx = start_col;
+					child.endx = c -1;
+					child.starty = area.starty;
+					child.endy = area.endy;
+					tempList.push_back(child);
+					start_col = c;
+
+					if (false) {
+						string path = "C:\\Users\\Administrator\\Desktop\\ocr\\gpcode\\";
+						path.append("cate_").append(to_string(index)).append("_").append(to_string(c)).append(".jpg");
+						cv::imwrite(path, cv::Mat(img, cv::Rect(child.startx, child.starty, child.endx - child.startx + 1, child.endy - child.starty + 1)));
+					}
+
+				}
+			}
+		}
+		index++;
+		ffresultList.push_back(tempList);
+	}
+	
+
+	return ffresultList;
+
+}
+
 cv::Mat getTHSTimeCapture() {
 	HWND hwnd = THSActionUtil::getMainWin();
 	if (hwnd <= 0) {

--
Gitblit v1.8.0