From 60feedf43a35a9ca69d05095a01c5d1797b1bdc3 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期五, 09 九月 2022 18:47:14 +0800
Subject: [PATCH] '完善'

---
 ConsoleApplication/LimitUpCapture.cpp |  218 +++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 140 insertions(+), 78 deletions(-)

diff --git a/ConsoleApplication/LimitUpCapture.cpp b/ConsoleApplication/LimitUpCapture.cpp
index fdcd81c..ac34154 100644
--- a/ConsoleApplication/LimitUpCapture.cpp
+++ b/ConsoleApplication/LimitUpCapture.cpp
@@ -3,6 +3,8 @@
 #include <set>
 #include "Win32Util.h"
 #include "TaskChecker.h"
+#include "GPUtil.h"
+bool LimitUpCapture::tradeTimeCapture;
 OpenCLExcuter* LimitUpCapture::openCLExcuter;
 bool LimitUpCapture::inited;
 //是否正在执行
@@ -32,6 +34,12 @@
 	while (true) {
 		if (kill)
 			break;
+		if (tradeTimeCapture) {
+			if (!GPUtil::isTradeTime()) {
+				Sleep(100);
+				continue;
+			}
+		}
 		TaskChecker::clientLiveTime.limitUp = clock();
 		if (running && inited) {
 			clock_t start = clock();
@@ -47,7 +55,7 @@
 	}
 }
 
-
+bool LimitUpCapture::pause;
 
 void LimitUpCapture::init(CallbackFun_Limit_Up callback, void* contex) {
 	data_callback = callback;
@@ -60,7 +68,12 @@
 	thread rt(&(LimitUpCapture::_run));
 	rt.detach();
 	inited = true;
-	refreshHWND();
+	try {
+		refreshHWND();
+	}
+	catch (...) {
+	
+	}
 }
 void LimitUpCapture::reCreateRunning()
 {
@@ -74,6 +87,12 @@
 	HWND hwnd = getWindow();
 	if (hwnd <= 0)
 		throw string("同花顺副屏2未打开");
+	//输入快捷键51定位到我的版块
+	Win32Util::focus(hwnd);
+	Win32Util::keyboardNum("51", 200);
+	Win32Util::keyboard(VK_RETURN, 1000);
+	Sleep(500);
+
 
 	HWND content = FindWindowExA(hwnd, NULL, "AfxFrameOrView100s", NULL);
 
@@ -193,15 +212,15 @@
 	list<int*> rowData = THSActionUtil::splitPlateRowArea(grayImg);
 
 	//每行的元素个数
-	int ele_count_per_line = 4;
-	int* splitResult = (int*)malloc(sizeof(int) * 4 * 4 * rowData.size());
+	int ele_count_per_line = 5;
+	int num_length_per_ele = 6;
+	int* splitResult = (int*)malloc(sizeof(int) * 4 * ele_count_per_line * rowData.size());
 	int* rowIndex = (int*)malloc(sizeof(int) * 4 * rowData.size());
 	int count = 0;
 	for (std::list<int*>::iterator ele = rowData.begin();ele != rowData.end();ele++) {
 		string path = "C:\\Users\\Administrator\\Desktop\\ocr\\limit_up\\";
 		path.append(to_string(count)).append(".jpg");
 		//cv::imwrite(path, cv::Mat(grayImg, cv::Rect((*ele)[0], (*ele)[1], (*ele)[2] - (*ele)[0] + 1, (*ele)[3] - (*ele)[1] + 1)));
-
 		rowIndex[4 * count + 0] = (*ele)[0];
 		rowIndex[4 * count + 1] = (*ele)[1];
 		rowIndex[4 * count + 2] = (*ele)[2];
@@ -210,24 +229,32 @@
 		count++;
 	}
 
-	int line_number_count = 4 * 6;
+	int line_number_count = ele_count_per_line * num_length_per_ele;
 
-	openCLExcuter->splitPlateContentRowData(grayImg.data, grayImg.cols, grayImg.rows, rowIndex, rowData.size(), ele_count_per_line,1,4,splitResult);
+	openCLExcuter->splitPlateContentRowData(grayImg.data, grayImg.cols, grayImg.rows, rowIndex, rowData.size(), ele_count_per_line,1,5,splitResult);
 
-	/*
-	*测试
+	
+	//测试
+	set<int> excudeIndexs;
 	for (int i = 0;i < rowData.size();i++) {
-		for (int j = 0;j < line_number_count;j++) {
-			int sx = splitResult[(line_number_count * i + j) * 4 + 0];
-			int sy = splitResult[(line_number_count * i + j) * 4 + 1];
-			int ex = splitResult[(line_number_count * i + j) * 4 + 2];
-			int ey = splitResult[(line_number_count * i + j) * 4 + 3];
+		for (int j = 0;j < ele_count_per_line;j++) {
+			int sx = splitResult[(ele_count_per_line * i + j) * 4 + 0];
+			int sy = splitResult[(ele_count_per_line * i + j) * 4 + 1];
+			int ex = splitResult[(ele_count_per_line * i + j) * 4 + 2];
+			int ey = splitResult[(ele_count_per_line * i + j) * 4 + 3];
 			string path = "C:\\Users\\Administrator\\Desktop\\ocr\\limit_up\\";
 			path.append(to_string(i)).append("_").append(to_string(j)).append(".jpg");
 			//cv::imwrite(path, cv::Mat(grayImg, cv::Rect(sx, sy, ex - sx + 1, ey - sy + 1)));
 		}
+		int sx = splitResult[(ele_count_per_line * i + 0) * 4 + 0];
+		int ex = splitResult[(ele_count_per_line * i + 0) * 4 + 2];
+		if (ex - sx < 40) {
+		//噪点数据
+			excudeIndexs.insert(i);
+		}
+
 	}
-	*/
+
 
 
 
@@ -249,10 +276,12 @@
 		}
 	}
 	unsigned char* totalNumberData = (unsigned char*)malloc(sizeof(unsigned char) * (_NUMBER_GP_CODE_HEIGHT * rowData.size()) * _NUMBER_GP_CODE_WIDTH * 10 * line_number_count);
-	openCLExcuter->splitPlateNum(grayImg.data, grayImg.cols, grayImg.rows, splitResult, 4 * rowData.size(), zeroData, _NUMBER_GP_CODE_WIDTH, _NUMBER_GP_CODE_HEIGHT, line_number_count, totalNumberData);
+	unsigned char types[] = { NUM_TYPE_MONEY,NUM_TYPE_CODE,NUM_TYPE_TIME, NUM_TYPE_PRICE,NUM_TYPE_PERCENT};
+	UcharDataInfo typesData = UcharDataInfo();
+	typesData.length = 5;
+	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, num_length_per_ele);
 
 	//识别数字
 	uchar* templateNums = (unsigned char*)malloc(sizeof(unsigned char) * (_NUMBER_GP_CODE_HEIGHT * rowData.size()) * _NUMBER_GP_CODE_WIDTH * 10 * line_number_count);
@@ -261,86 +290,114 @@
 
 	list<LimitUpData> dataList;
 	for (int i = 0;i < rowData.size();i++) {
+		if (excudeIndexs.count(i) > 0) {
+			continue;
+		}
 		LimitUpData limitUpData = LimitUpData();
-		string code = "";
-		for (int j = 0;j < 6;j++)
-		{
-			code.append(to_string(numberResult[i][j]));
-		}
-		string time = "";
-		for (int j = 0;j < 6;j++)
-		{
-			if (j == 2 || j == 4) {
-				time.append(":");
-			}
-			time.append(to_string(numberResult[i][6 + j]));
-		}
-
-		string price = "";
-		for (int j = 0;j < 6;j++)
-		{
-			if (j == 4) {
-				price.append(".");
-			}
-			price.append(to_string(numberResult[i][6 * 2 + j]));
-		}
 
 		string money = "";
-		for (int j = 0;j < 6;j++)
+		for (int j = 0;j < num_length_per_ele;j++)
 		{
 			if (j == 4) {
 				money.append(".");
 			}
-			money.append(to_string(numberResult[i][6 * 3 + j]));
+			money.append(to_string(numberResult[i][num_length_per_ele*0  + j]));
+		}
+
+
+		string code = "";
+		for (int j = 0;j < num_length_per_ele;j++)
+		{
+			code.append(to_string(numberResult[i][num_length_per_ele * 1+j]));
+		}
+		string time = "";
+		for (int j = 0;j < num_length_per_ele;j++)
+		{
+			if (j == 2 || j == 4) {
+				time.append(":");
+			}
+			time.append(to_string(numberResult[i][num_length_per_ele*2 + j]));
+		}
+
+		string price = "";
+		for (int j = 0;j < num_length_per_ele;j++)
+		{
+			if (j == 4) {
+				price.append(".");
+			}
+			price.append(to_string(numberResult[i][num_length_per_ele * 3 + j]));
+		}
+
+		
+
+		string percent = "";
+		for (int j = 0;j < num_length_per_ele;j++)
+		{
+			if (j == 4) {
+				percent.append(".");
+			}
+			percent.append(to_string(numberResult[i][num_length_per_ele * 4 + j]));
+		}
+		if (percent == "0000.00") {
+			int sx = splitResult[(ele_count_per_line * i + 4) * 4 + 0];
+			int sy = splitResult[(ele_count_per_line * i + 4) * 4 + 1];
+			int ex = splitResult[(ele_count_per_line * i + 4) * 4 + 2];
+			int ey = splitResult[(ele_count_per_line * i + 4) * 4 + 3];
+			string path = "C:\\Users\\Administrator\\Desktop\\ocr\\limit_up\\";
+			path.append(to_string(i)).append("_").append(".jpg");
+			cv::imwrite(path, cv::Mat(grayImg, cv::Rect(sx, sy, ex - sx + 1, ey - sy + 1)));
 		}
 
 		limitUpData.index = i;
 		limitUpData.code = code;
 		limitUpData.time = time;
 		limitUpData.price = price;
+		limitUpData.limitUpPercent = percent;
 		limitUpData.limitMoney = money;
-		if (limitUpData.time != "00:00:00" && limitUpData.price != "0000.00" && limitUpData.limitMoney != "0000.00") {
+		if (limitUpData.code != "000000" && limitUpData.limitUpPercent != "0000.00") {
 			dataList.push_back(limitUpData);
 		}
 		free(numberResult[i]);
 	}
 	free(numberResult);
-	int* unitData = (int*)malloc(sizeof(int) * 4 * dataList.size());
 
-
-
-	//识别金额单位
-	int index = 0;
-	for (list<LimitUpData>::iterator ele = dataList.begin();ele != dataList.end();ele++) {
-		unitData[index * 4 + 0] = splitResult[(*ele).index * 4 * 4 + 4 * 3 + 0];
-		unitData[index * 4 + 1] = splitResult[(*ele).index * 4 * 4 + 4 * 3 + 1];
-		unitData[index * 4 + 2] = splitResult[(*ele).index * 4 * 4 + 4 * 3 + 2];
-		unitData[index * 4 + 3] = splitResult[(*ele).index * 4 * 4 + 4 * 3 + 3];
-		index++;
-	}
-	int* unitResult = (int*)malloc(sizeof(int) * dataList.size());
-	openCLExcuter->recognitionPlateMoneyUnit(grayImg.data, grayImg.cols, grayImg.rows, unitData, 1, dataList.size(), unitResult);
-	index = 0;
-	for (list<LimitUpData>::iterator ele = dataList.begin();ele != dataList.end();ele++) {
-		switch (unitResult[index])
-		{
-		case 0:
-			(*ele).limitMoneyUnit = MONEY_UNIT_Y;
-			break;
-		case 1:
-			(*ele).limitMoneyUnit = MONEY_UNIT_W;
-			break;
-		default:
-			break;
+	if (dataList.size() > 0)
+	{
+		int* unitData = (int*)malloc(sizeof(int) * 4 * dataList.size());
+		//识别金额单位
+		int index = 0;
+		for (list<LimitUpData>::iterator ele = dataList.begin();ele != dataList.end();ele++) {
+			unitData[index * 4 + 0] = splitResult[(*ele).index * 4 * ele_count_per_line + 4 * 0 + 0];
+			unitData[index * 4 + 1] = splitResult[(*ele).index * 4 * ele_count_per_line + 4 * 0 + 1];
+			unitData[index * 4 + 2] = splitResult[(*ele).index * 4 * ele_count_per_line + 4 * 0 + 2];
+			unitData[index * 4 + 3] = splitResult[(*ele).index * 4 * ele_count_per_line + 4 * 0 + 3];
+			index++;
 		}
-		index++;
+		int* unitResult = (int*)malloc(sizeof(int) * dataList.size());
+		openCLExcuter->recognitionPlateMoneyUnit(grayImg.data, grayImg.cols, grayImg.rows, unitData, 1, dataList.size(), unitResult);
+		index = 0;
+		for (list<LimitUpData>::iterator ele = dataList.begin();ele != dataList.end();ele++) {
+			switch (unitResult[index])
+			{
+			case 0:
+				(*ele).limitMoneyUnit = MONEY_UNIT_Y;
+				break;
+			case 1:
+				(*ele).limitMoneyUnit = MONEY_UNIT_W;
+				break;
+			default:
+				break;
+			}
+			index++;
+		}
+		free(unitData);
+		free(unitResult);
 	}
 	free(rowIndex);
 	free(splitResult);
 	free(zeroData);
 	free(templateNums);
-	free(unitData);
-	free(unitResult);
+
 	free(imgData);
 
 	grayImg.release();
@@ -366,26 +423,31 @@
 		if (kill) {
 			break;
 		}
+		//暂停
+		while (pause) {
+			cout <<"涨停识别暂停"<< endl;
+			Sleep(100);
+		}
 		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));
+	    PostMessage(menuWin, WM_LBUTTONDOWN, 0, MAKELONG(x, y));
 		Sleep(10);
-		SendMessage(menuWin, WM_LBUTTONUP, 0, MAKELONG(x, y));
+		PostMessage(menuWin, WM_LBUTTONUP, 0, MAKELONG(x, y));
 		//SendMessage(menuWin, WM_SETCURSOR,(int) menuWin, 0x02000001);
 		//Win32Util::focus(menuWin);
 		//Win32Util::click(x, y);
-		Sleep(100);
+		Sleep(50);
 		
-		for (int i = 0;i < 3;i++)
+		for (int i = 0;i < 2;i++)
 		{
 			if (kill) {
 				break;
 			}
 			int x = wrect.right - 50;
 			int y = wrect.top + 50;
-			SendMessage(win, WM_MOUSEWHEEL, 0, MAKEWORD(x, y));
-			Sleep(100);
+			PostMessage(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++) {

--
Gitblit v1.8.0