#include "LimitUpCapture.h"
|
#include "THSActionUtil.h"
|
#include <set>
|
#include "Win32Util.h"
|
#include "TaskChecker.h"
|
#include "GPUtil.h"
|
#include "OpenCLUtil.h"
|
bool LimitUpCapture::tradeTimeCapture;
|
OpenCLExcuter* LimitUpCapture::openCLExcuter;
|
bool LimitUpCapture::inited;
|
//ÊÇ·ñÕýÔÚÖ´ÐÐ
|
bool LimitUpCapture::running;
|
|
bool LimitUpCapture::kill;
|
|
CallbackFun_Limit_Up LimitUpCapture::data_callback;
|
CallbackFun_First_Limit_Up LimitUpCapture::first_data_callback;
|
|
MatOcrFun LimitUpCapture::ocr_fun;
|
|
cv::Point LimitUpCapture::limitUpPoint;
|
|
cv::Point LimitUpCapture::firstCodePoint;
|
|
void* LimitUpCapture::context;
|
|
HWND LimitUpCapture::win;
|
|
HWND LimitUpCapture::menuWin;
|
|
HWND getWindow() {
|
HWND win = THSActionUtil::getThirdWindow();
|
if (win <= 0) {
|
win = THSActionUtil::getSecondWindow();
|
}
|
return win;
|
}
|
|
void LimitUpCapture::_run() {
|
while (true) {
|
if (kill)
|
break;
|
if (tradeTimeCapture) {
|
if (!GPUtil::isTradeTime()) {
|
Sleep(100);
|
continue;
|
}
|
}
|
TaskChecker::clientLiveTime.limitUp = clock();
|
if (running && inited) {
|
clock_t start = clock();
|
try {
|
LimitUpFinalData finalData = captureLimitUpCodes();
|
cout << "ÕÇͣʶ±ðºÄʱ:" << clock() - start << endl;
|
data_callback(finalData.limitUpDatas, context);
|
first_data_callback(finalData.firstLimitUpDatas, context);
|
finalData.limitUpDatas.clear();
|
finalData.firstLimitUpDatas.clear();
|
}
|
catch (...) {
|
|
}
|
Sleep(50);
|
}
|
else {
|
Sleep(1000);
|
}
|
}
|
}
|
|
bool LimitUpCapture::pause;
|
|
void LimitUpCapture::init(CallbackFun_Limit_Up callback, CallbackFun_First_Limit_Up first_callback, MatOcrFun matMcrFun, void* contex) {
|
data_callback = callback;
|
first_data_callback = first_callback;
|
ocr_fun = matMcrFun;
|
context = contex;
|
running = false;
|
kill = false;
|
openCLExcuter = new OpenCLExcuter();
|
openCLExcuter->init();
|
thread rt(&(LimitUpCapture::_run));
|
rt.detach();
|
inited = true;
|
try {
|
if(matMcrFun!=NULL)
|
refreshHWND();
|
}
|
catch (...) {
|
|
}
|
}
|
void LimitUpCapture::reCreateRunning()
|
{
|
kill = TRUE;
|
Sleep(4000);
|
kill = FALSE;
|
thread rt(&(LimitUpCapture::_run));
|
rt.detach();
|
}
|
void LimitUpCapture::refreshHWND() {
|
HWND hwnd = getWindow();
|
if (hwnd <= 0)
|
throw string("ͬ»¨Ë³¸±ÆÁ1δ´ò¿ª");
|
//ÊäÈë¿ì½Ý¼ü51¶¨Î»µ½Îҵİæ¿é
|
Win32Util::showWindow(hwnd);
|
Win32Util::focus(hwnd);
|
Win32Util::keyboardNum("51", 200);
|
Win32Util::keyboard(VK_RETURN, 1000);
|
Sleep(500);
|
|
|
HWND content = FindWindowExA(hwnd, NULL, "AfxFrameOrView100s", NULL);
|
|
|
if (content <= 0)
|
throw string("δ»ñÈ¡µ½ÄÚÈÝ´°¿Ú¾ä±ú");
|
|
win = content;
|
|
HWND child = 0;
|
RECT tempRect;
|
int maxCount = 1;
|
do {
|
maxCount++;
|
child = FindWindowExA(content, child, "AfxWnd100s", NULL);
|
|
if (!Win32Util::isWindowShow(child)) {
|
continue;
|
}
|
GetWindowRect(child, &tempRect);
|
if (tempRect.right- tempRect.left>1000) {
|
continue;
|
}
|
|
if (tempRect.right - tempRect.left > tempRect.bottom - tempRect.top) {
|
continue;
|
}
|
|
HWND temp = FindWindowExA(child, NULL, "#32770", NULL);
|
if (temp > 0) {
|
temp = FindWindowExA(temp, NULL, "block_list_page", NULL);
|
if (temp > 0) {
|
menuWin = temp;
|
break;
|
}
|
|
}
|
|
} while (maxCount < 20);
|
|
if (menuWin <= 0)
|
throw string("δ»ñÈ¡µ½ÄÚÈÝ´°¿ÚµÄ²Ëµ¥¾ä±ú");
|
|
//²éÕҲ˵¥µÄλÖÃ
|
cv::Mat grayImg = ImgUtil::grayImage(CaptureUtil::capture(menuWin));
|
|
// »ñÈ¡ÕÇÍ£µÄ×ø±êλÖÃ
|
list<OCRResult> ocrResultList = ocr_fun("½ñÈÕ", grayImg);
|
if (ocrResultList.size() > 0) {
|
for (list<OCRResult>::iterator ele = ocrResultList.begin(); ele != ocrResultList.end(); ele++) {
|
OCRResult result = *ele;
|
limitUpPoint = (cv::Point((result.rect.left+result.rect.right)/2, (result.rect.top + result.rect.bottom) / 2));
|
ImgUtil::markMat(grayImg, cv::Rect(result.rect.left, result.rect.top, result.rect.right - result.rect.left +1, result.rect.bottom - result.rect.top + 1), 255, 1);
|
break;
|
}
|
}
|
//»ñÈ¡Ê×°åµÄ×ø±êλÖÃ
|
ocrResultList = ocr_fun("Ê×°å", grayImg);
|
if (ocrResultList.size() > 0) {
|
for (list<OCRResult>::iterator ele = ocrResultList.begin(); ele != ocrResultList.end(); ele++) {
|
OCRResult result = *ele;
|
firstCodePoint=(cv::Point((result.rect.left + result.rect.right) / 2, (result.rect.top + result.rect.bottom) / 2));
|
ImgUtil::markMat(grayImg, cv::Rect(result.rect.left, result.rect.top, result.rect.right - result.rect.left + 1, result.rect.bottom - result.rect.top + 1), 255, 1);
|
break;
|
}
|
}
|
|
//±£´æÁÙʱͼƬ
|
//cv::imwrite("C:\\Users\\Administrator\\Desktop\\ocr\\menu.jpg", grayImg);
|
}
|
|
bool LimitUpCapture::isRunning() {
|
return running;
|
}
|
|
list<LimitUpData> LimitUpCapture::captureLimitUpCodes(cv::Mat oimg) {
|
cv::Mat grayImg = cv::Mat::zeros(oimg.rows, oimg.cols, CV_8UC1);
|
|
try {
|
grayImg = OpenCLUtil::grayImg(openCLExcuter, oimg);
|
}
|
catch (...) {
|
//±£´æÔʼͼƬ
|
//string path = "D:\\imgs\\img.png";
|
//cv::imwrite(path, oimg);
|
oimg.release();
|
throw string("»Ò¶È³ö´í");
|
}
|
|
|
|
list<int*> rowData;
|
|
try {
|
rowData = THSActionUtil::splitPlateRowArea(grayImg);
|
}
|
catch (string st) {
|
throw st;
|
}
|
|
//ÿÐеÄÔªËØ¸öÊý
|
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];
|
rowIndex[4 * count + 3] = (*ele)[3];
|
free(*ele);
|
count++;
|
}
|
|
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,5,splitResult);
|
|
|
//²âÊÔ
|
set<int> excudeIndexs;
|
for (int i = 0;i < rowData.size();i++) {
|
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 + 1) * 4 + 0];
|
int ex = splitResult[(ele_count_per_line * i + 1) * 4 + 2];
|
if (ex - sx < 40) {
|
//ÔëµãÊý¾Ý
|
excudeIndexs.insert(i);
|
}
|
|
}
|
|
|
|
|
int start = 4 * 4 * 1 + 4 * 1;
|
|
string path = "C:\\Users\\Administrator\\Desktop\\ocr\\limit_up\\";
|
path.append(to_string(start)).append(".jpg");
|
|
//cv::imwrite(path, cv::Mat(grayImg,cv::Rect(splitResult[start], splitResult[start+1], splitResult[start+2]- splitResult[start]+1, splitResult[start+3]- splitResult[start+1]+1)));
|
|
//cv::imwrite(path, cv::Mat(grayImg, cv::Rect(447, 102, 454-447+1,111-102+1 )));
|
|
//·Ö¸îÊý×Ö
|
unsigned char* zeroData = (unsigned char*)malloc(sizeof(unsigned char) * _NUMBER_GP_CODE_WIDTH * _NUMBER_GP_CODE_HEIGHT);
|
for (int r = 0;r < _NUMBER_GP_CODE_HEIGHT;r++) {
|
for (int c = 0;c < _NUMBER_GP_CODE_WIDTH;c++)
|
{
|
zeroData[r * _NUMBER_GP_CODE_WIDTH + c] = ImgUtil::NUMS_GP_CODE[0].data.ptr<uchar>(r)[c];
|
}
|
}
|
unsigned char* totalNumberData = (unsigned char*)malloc(sizeof(unsigned char) * (_NUMBER_GP_CODE_HEIGHT * rowData.size()) * _NUMBER_GP_CODE_WIDTH * 10 * line_number_count);
|
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);
|
openCLExcuter->createNumberTemplates(rowData.size(), _NUMBER_GP_CODE_WIDTH, _NUMBER_GP_CODE_HEIGHT, line_number_count, ImgUtil::numsOneLevel_gpcode, templateNums);
|
uchar** numberResult = openCLExcuter->recognition_numbers(totalNumberData, templateNums, rowData.size() * _NUMBER_GP_CODE_HEIGHT, _NUMBER_GP_CODE_WIDTH * 10 * line_number_count, _NUMBER_GP_CODE_WIDTH, _NUMBER_GP_CODE_HEIGHT, line_number_count);
|
free(totalNumberData);
|
|
list<LimitUpData> dataList;
|
for (int i = 0;i < rowData.size();i++) {
|
if (excudeIndexs.count(i) > 0) {
|
continue;
|
}
|
LimitUpData limitUpData = LimitUpData();
|
|
string money = "";
|
for (int j = 0;j < num_length_per_ele;j++)
|
{
|
if (j == 4) {
|
money.append(".");
|
}
|
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.code != "000000" && limitUpData.limitUpPercent != "0000.00") {
|
dataList.push_back(limitUpData);
|
}
|
free(numberResult[i]);
|
}
|
free(numberResult);
|
|
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++;
|
}
|
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);
|
grayImg.release();
|
return dataList;
|
}
|
|
list<FirstLimitUpCodeData> LimitUpCapture::captureLimitUpFirstCodes(cv::Mat oimg)
|
{
|
cv::Mat grayImg = cv::Mat::zeros(oimg.rows, oimg.cols, CV_8UC1);
|
|
try {
|
grayImg = OpenCLUtil::grayImg(openCLExcuter, oimg);
|
}
|
catch (...) {
|
//±£´æÔʼͼƬ
|
//string path = "D:\\imgs\\img.png";
|
//cv::imwrite(path, oimg);
|
oimg.release();
|
throw string("»Ò¶È³ö´í");
|
}
|
|
|
|
list<int*> rowData;
|
|
try {
|
rowData = THSActionUtil::splitPlateRowArea(grayImg);
|
}
|
catch (string st) {
|
throw st;
|
}
|
|
//ÿÐеÄÔªËØ¸öÊý
|
int ele_count_per_line = 6;
|
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];
|
rowIndex[4 * count + 3] = (*ele)[3];
|
free(*ele);
|
count++;
|
}
|
|
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, ele_count_per_line, splitResult);
|
|
|
//²âÊÔ
|
set<int> excudeIndexs;
|
for (int i = 0; i < rowData.size(); i++) {
|
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 + 1) * 4 + 0];
|
int ex = splitResult[(ele_count_per_line * i + 1) * 4 + 2];
|
if (ex - sx < 20) {
|
//ÔëµãÊý¾Ý
|
excudeIndexs.insert(i);
|
}
|
|
}
|
|
|
|
|
int start = 4 * 4 * 1 + 4 * 1;
|
|
string path = "C:\\Users\\Administrator\\Desktop\\ocr\\limit_up\\";
|
path.append(to_string(start)).append(".jpg");
|
|
//cv::imwrite(path, cv::Mat(grayImg,cv::Rect(splitResult[start], splitResult[start+1], splitResult[start+2]- splitResult[start]+1, splitResult[start+3]- splitResult[start+1]+1)));
|
|
//cv::imwrite(path, cv::Mat(grayImg, cv::Rect(447, 102, 454-447+1,111-102+1 )));
|
|
//·Ö¸îÊý×Ö
|
unsigned char* zeroData = (unsigned char*)malloc(sizeof(unsigned char) * _NUMBER_GP_CODE_WIDTH * _NUMBER_GP_CODE_HEIGHT);
|
for (int r = 0; r < _NUMBER_GP_CODE_HEIGHT; r++) {
|
for (int c = 0; c < _NUMBER_GP_CODE_WIDTH; c++)
|
{
|
zeroData[r * _NUMBER_GP_CODE_WIDTH + c] = ImgUtil::NUMS_GP_CODE[0].data.ptr<uchar>(r)[c];
|
}
|
}
|
unsigned char* totalNumberData = (unsigned char*)malloc(sizeof(unsigned char) * (_NUMBER_GP_CODE_HEIGHT * rowData.size()) * _NUMBER_GP_CODE_WIDTH * 10 * line_number_count);
|
unsigned char types[] = { NUM_TYPE_MONEY,NUM_TYPE_MONEY,NUM_TYPE_CODE,NUM_TYPE_TIME, NUM_TYPE_PRICE,NUM_TYPE_PERCENT };
|
UcharDataInfo typesData = UcharDataInfo();
|
typesData.length = 6;
|
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);
|
openCLExcuter->createNumberTemplates(rowData.size(), _NUMBER_GP_CODE_WIDTH, _NUMBER_GP_CODE_HEIGHT, line_number_count, ImgUtil::numsOneLevel_gpcode, templateNums);
|
uchar** numberResult = openCLExcuter->recognition_numbers(totalNumberData, templateNums, rowData.size() * _NUMBER_GP_CODE_HEIGHT, _NUMBER_GP_CODE_WIDTH * 10 * line_number_count, _NUMBER_GP_CODE_WIDTH, _NUMBER_GP_CODE_HEIGHT, line_number_count);
|
free(totalNumberData);
|
|
list<FirstLimitUpCodeData> dataList;
|
for (int i = 0; i < rowData.size(); i++) {
|
if (excudeIndexs.count(i) > 0) {
|
continue;
|
}
|
FirstLimitUpCodeData limitUpData = FirstLimitUpCodeData();
|
|
string money = "";
|
for (int j = 0; j < num_length_per_ele; j++)
|
{
|
if (j == 4) {
|
money.append(".");
|
}
|
money.append(to_string(numberResult[i][num_length_per_ele * 0 + j]));
|
}
|
|
string volume = "";
|
for (int j = 0; j < num_length_per_ele; j++)
|
{
|
if (j == 4) {
|
volume.append(".");
|
}
|
volume.append(to_string(numberResult[i][num_length_per_ele * 1 + j]));
|
}
|
|
|
string code = "";
|
for (int j = 0; j < num_length_per_ele; j++)
|
{
|
code.append(to_string(numberResult[i][num_length_per_ele * 2 + 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 * 3 + 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 * 4 + 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 * 5 + 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.zyltMoney = money;
|
limitUpData.volume = volume;
|
if (limitUpData.code != "000000" && limitUpData.limitUpPercent != "0000.00") {
|
dataList.push_back(limitUpData);
|
}
|
else {
|
cout <<"³ö´í"<< endl;
|
}
|
free(numberResult[i]);
|
}
|
free(numberResult);
|
|
if (dataList.size() > 0)
|
{
|
int* unitData = (int*)malloc(sizeof(int) * 4 * dataList.size() * 2 );
|
//ʶ±ð½ð¶îµ¥Î»
|
int index = 0;
|
for (list<FirstLimitUpCodeData>::iterator ele = dataList.begin(); ele != dataList.end(); ele++) {
|
unitData[index * 4 * 2 + 0] = splitResult[(*ele).index * 4 * ele_count_per_line + 4 * 0 + 0];
|
unitData[index * 4 * 2 + 1] = splitResult[(*ele).index * 4 * ele_count_per_line + 4 * 0 + 1];
|
unitData[index * 4 * 2 + 2] = splitResult[(*ele).index * 4 * ele_count_per_line + 4 * 0 + 2];
|
unitData[index * 4 * 2 + 3] = splitResult[(*ele).index * 4 * ele_count_per_line + 4 * 0 + 3];
|
|
unitData[index * 4 * 2 + 4] = splitResult[(*ele).index * 4 * ele_count_per_line + 4 * 1 + 0];
|
unitData[index * 4 * 2 + 5] = splitResult[(*ele).index * 4 * ele_count_per_line + 4 * 1 + 1];
|
unitData[index * 4 * 2 + 6] = splitResult[(*ele).index * 4 * ele_count_per_line + 4 * 1 + 2];
|
unitData[index * 4 * 2 + 7] = splitResult[(*ele).index * 4 * ele_count_per_line + 4 * 1 + 3];
|
|
index++;
|
}
|
int* unitResult = (int*)malloc(sizeof(int) * dataList.size() * 2);
|
openCLExcuter->recognitionPlateMoneyUnit(grayImg.data, grayImg.cols, grayImg.rows, unitData, 2, dataList.size(), unitResult);
|
index = 0;
|
for (list<FirstLimitUpCodeData>::iterator ele = dataList.begin(); ele != dataList.end(); ele++) {
|
switch (unitResult[index*2])
|
{
|
case 0:
|
(*ele).zyltMoneyUnit = MONEY_UNIT_Y;
|
break;
|
case 1:
|
(*ele).zyltMoneyUnit = MONEY_UNIT_W;
|
break;
|
default:
|
break;
|
}
|
|
switch (unitResult[index * 2 + 1])
|
{
|
case 0:
|
(*ele).volumeUnit = MONEY_UNIT_Y;
|
break;
|
case 1:
|
(*ele).volumeUnit = MONEY_UNIT_W;
|
break;
|
case 2:
|
(*ele).volumeUnit = MONEY_UNIT_NO;
|
(*ele).volume = to_string((int)(stof((*ele).volume) * 100));
|
break;
|
default:
|
break;
|
}
|
|
index++;
|
}
|
free(unitData);
|
free(unitResult);
|
}
|
free(rowIndex);
|
free(splitResult);
|
free(zeroData);
|
free(templateNums);
|
grayImg.release();
|
return dataList;
|
}
|
|
LimitUpFinalData LimitUpCapture::captureLimitUpCodes() {
|
cout << "¿ªÊ¼ÔËÐÐ" << endl;
|
HWND hwnd = getWindow();
|
cout << "ͬ»¨Ë³¾ä±ú£º"<< hwnd << endl;
|
|
RECT wrect;
|
GetWindowRect(win, &wrect);
|
RECT menuRect;
|
GetWindowRect(menuWin, &menuRect);
|
|
LimitUpFinalData finalDatas;
|
list<LimitUpData> limitUpList;
|
list<FirstLimitUpCodeData> firstLimitUpList;
|
for (int n = 0; n < 2;n++) {
|
set<string> codesSet;
|
if (kill) {
|
break;
|
}
|
|
|
|
int x = 0;
|
int y = 0;
|
if (n == 0) {
|
x = limitUpPoint.x;
|
y = limitUpPoint.y;
|
}
|
else {
|
x = firstCodePoint.x;
|
y = firstCodePoint.y;
|
}
|
|
printf("x:%d y:%d\n", x, y);
|
PostMessage(menuWin, WM_LBUTTONDOWN, 0, MAKELONG(x, y));
|
Sleep(10);
|
PostMessage(menuWin, WM_LBUTTONUP, 0, MAKELONG(x, y));
|
Sleep(50);
|
|
|
|
for (int i = 0;i < 3;i++)
|
{
|
if (kill) {
|
break;
|
}
|
int x = wrect.right - 50;
|
int y = wrect.top + 50;
|
PostMessage(win, WM_MOUSEWHEEL, 0, MAKEWORD(x, y));
|
Sleep(200);
|
cv::Mat oimg = CaptureUtil::capture(win);
|
if (n == 0)
|
{
|
try {
|
list<LimitUpData> codes = captureLimitUpCodes(oimg);
|
for (list<LimitUpData>::iterator e = codes.begin(); e != codes.end(); e++) {
|
string code = (*e).code;
|
if (codesSet.count(code) == 0) {
|
codesSet.insert(code);
|
limitUpList.push_back(*e);
|
}
|
}
|
codes.clear();
|
}
|
catch (string e) {
|
cout << e << endl;
|
}
|
}
|
else {
|
try {
|
list<FirstLimitUpCodeData> codes = captureLimitUpFirstCodes(oimg);
|
for (list<FirstLimitUpCodeData>::iterator e = codes.begin(); e != codes.end(); e++) {
|
string code = (*e).code;
|
if (codesSet.count(code) == 0) {
|
codesSet.insert(code);
|
firstLimitUpList.push_back(*e);
|
}
|
}
|
codes.clear();
|
}
|
catch (string e) {
|
cout << e << endl;
|
}
|
|
}
|
Sleep(50);
|
}
|
}
|
finalDatas.limitUpDatas = limitUpList;
|
finalDatas.firstLimitUpDatas = firstLimitUpList;
|
return finalDatas;
|
}
|
|
//È«²¿¿ªÊ¼
|
void LimitUpCapture::start() {
|
running = true;
|
}
|
//È«²¿½áÊø
|
void LimitUpCapture::stop() {
|
running = false;
|
}
|
bool LimitUpCapture::isInited() {
|
return inited;
|
}
|