From d7e3f882feb9307c22b0cd2698e45d24804b6572 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 20 七月 2022 18:37:45 +0800
Subject: [PATCH] '完善'

---
 ConsoleApplication/LimitUpCapture.cpp |  160 +++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 141 insertions(+), 19 deletions(-)

diff --git a/ConsoleApplication/LimitUpCapture.cpp b/ConsoleApplication/LimitUpCapture.cpp
index 1b32b58..0e55f9c 100644
--- a/ConsoleApplication/LimitUpCapture.cpp
+++ b/ConsoleApplication/LimitUpCapture.cpp
@@ -1,6 +1,7 @@
 #include "LimitUpCapture.h"
 #include "THSActionUtil.h"
 #include <set>
+#include "Win32Util.h"
 OpenCLExcuter* LimitUpCapture::openCLExcuter;
 bool LimitUpCapture::inited;
 //是否正在执行
@@ -8,11 +9,21 @@
 
 CallbackFun_Limit_Up LimitUpCapture::data_callback;
 
+std::list<cv::Point> LimitUpCapture::pointList;
+
 void* LimitUpCapture::context;
 
 HWND LimitUpCapture::win;
 
+HWND LimitUpCapture::menuWin;
+
+
+
 RecognitionManager* LimitUpCapture::recognitionManager;
+
+HWND getWindow() {
+	return THSActionUtil::getThirdWindow();
+}
 
 void LimitUpCapture::_run() {
 	while (true) {
@@ -36,14 +47,13 @@
 	recognitionManager = new RecognitionManager();
 	openCLExcuter = new OpenCLExcuter();
 	openCLExcuter->init();
-
 	thread rt(&(LimitUpCapture::_run));
 	rt.detach();
 	inited = true;
 	refreshHWND();
 }
 void LimitUpCapture::refreshHWND() {
-	HWND hwnd = THSActionUtil::getThirdWindow();
+	HWND hwnd = getWindow();
 	if (hwnd <= 0)
 		throw string("同花顺副屏2未打开");
 
@@ -54,6 +64,93 @@
 		throw string("未获取到内容窗口句柄");
 
 	win = content;
+
+	HWND child = 0;
+	RECT tempRect;
+	int maxCount = 1;
+	do {
+		maxCount++;
+		child = FindWindowExA(content, child, "AfxWnd100s", NULL);
+		GetWindowRect(child, &tempRect);
+	} while ((!IsWindowVisible(child) || tempRect.right - tempRect.left > tempRect.bottom - tempRect.top) && maxCount < 10);//没显示或者宽大于高
+
+	HWND temp= FindWindowExA(child, NULL, NULL, NULL);
+	for (int i = 0;i < 10;i++) {
+		GetWindowRect(temp, &tempRect);
+		if (!IsWindowVisible(temp) || tempRect.bottom - tempRect.top < 100) {
+			temp= FindWindowExA(child, temp, NULL, NULL);
+		}
+		else {
+			break;
+		}
+	}
+	temp= FindWindowExA(temp, NULL, "block_list_page", NULL);
+
+
+
+	menuWin = temp;
+
+	if (menuWin <= 0)
+		throw string("未获取到内容窗口的菜单句柄");
+
+	//查找菜单的位置
+
+	cv::Mat grayImg = ImgUtil::grayImage(CaptureUtil::capture(menuWin));
+	int full_start = -1;
+	int full_end = -1;
+	int start_row = -1;
+	int end_row = -1;
+	int count = 0;
+	pointList.clear();
+	for (int r = grayImg.rows - 1;r>=0;r --) {
+		if (ImgDivider::isRowFull(grayImg,r,0, grayImg.cols-1,2,33,48)) {
+			if (full_start < 0)
+			{
+				full_start = r;
+				full_end = r;
+			}
+			else {
+				full_end = r;
+			}
+
+			if (start_row > 0 && end_row > 0 && (start_row - end_row) > 5) {
+				count++;
+				printf("%d-%d\n", start_row, end_row);
+			
+				full_start = r;
+				full_end = r;
+				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)));
+			
+				pointList.push_back(cv::Point(  ( 0 + grayImg.cols)/2, (start_row + end_row)/2));
+				if (pointList.size() >= 2) {
+					break;
+				}
+				start_row = -1;
+				end_row = -1;
+			}
+		}
+		else {
+			if (full_start >= 0)
+			{
+				if (start_row < 0)
+				{
+					start_row = r;
+					end_row = r;
+				}
+				else {
+					end_row = r;
+				}
+			}
+		}
+	}
+
+
+
+	//cv::imwrite("C:\\Users\\Administrator\\Desktop\\ocr\\menu.jpg", );
+
 }
 
 bool LimitUpCapture::isRunning() {
@@ -98,7 +195,7 @@
 
 	int line_number_count = 4 * 6;
 
-	openCLExcuter->splitLimitUpRowData(grayImg.data, grayImg.cols, grayImg.rows, rowIndex, rowData.size(), ele_count_per_line, splitResult);
+	openCLExcuter->splitPlateContentRowData(grayImg.data, grayImg.cols, grayImg.rows, rowIndex, rowData.size(), ele_count_per_line,1,4,splitResult);
 
 	/*
 	*测试
@@ -234,29 +331,54 @@
 }
 
 list<LimitUpData> LimitUpCapture::captureLimitUpCodes() {
+	cout << "开始运行" << endl;
+	HWND hwnd = getWindow();
+	cout << "同花顺句柄:"<< hwnd << endl;
+
 	RECT wrect;
 	GetWindowRect(win, &wrect);
 	list<LimitUpData> flist;
 	set<string> codesSet;
-	string codestr="";
-	for (int i = 0;i < 5;i++)
-	{
-		int x = wrect.right - 50;
-		int y = wrect.top + 50;
-		SendMessage(win, WM_MOUSEWHEEL, 0, MAKEWORD(x, y));
-		Sleep(200);
-		cv::Mat oimg = CaptureUtil::capture(win);
-		list<LimitUpData> codes = captureLimitUpCodes(oimg);
-		for (list<LimitUpData>::iterator ele = codes.begin();ele != codes.end();ele++) {
-			string code = (*ele).code;
-			if(codesSet.count(code)==0){
-				codesSet.insert(code);
-				flist.push_back(*ele);
+	string codestr = "";
+
+	RECT menuRect;
+	GetWindowRect(menuWin, &menuRect);
+
+	list<cv::Point>::iterator ele;
+	for (ele = pointList.begin();ele != pointList.end();ele++) {
+		int x = (*ele).x;//+ menuRect.left;
+		int y = (*ele).y;//+ menuRect.top;
+		printf("x:%d y:%d\n", x, y);
+		SendMessage(menuWin, WM_LBUTTONDOWN, 0, MAKELONG(x, y));
+		Sleep(10);
+		SendMessage(menuWin, WM_LBUTTONUP, 0, MAKELONG(x, y));
+		//SendMessage(menuWin, WM_SETCURSOR,(int) menuWin, 0x02000001);
+		//Win32Util::focus(menuWin);
+		//Win32Util::click(x, y);
+		Sleep(100);
+		
+		for (int i = 0;i < 3;i++)
+		{
+			int x = wrect.right - 50;
+			int y = wrect.top + 50;
+			SendMessage(win, WM_MOUSEWHEEL, 0, MAKEWORD(x, y));
+			Sleep(100);
+			cv::Mat oimg = CaptureUtil::capture(win);
+			list<LimitUpData> codes = captureLimitUpCodes(oimg);
+			for (list<LimitUpData>::iterator ele = codes.begin();ele != codes.end();ele++) {
+				string code = (*ele).code;
+				if (codesSet.count(code) == 0) {
+					codesSet.insert(code);
+					flist.push_back(*ele);
+				}
 			}
+			codes.clear();
+			Sleep(50);
 		}
-		codes.clear();
-		Sleep(50);
 	}
+
+
+	
 	return flist;
 
 }

--
Gitblit v1.8.0