#include "ScreenDataCapture.h"
|
#include <thread>
|
#include<fstream>
|
|
ScreenDataCapture::ScreenDataCapture() {
|
|
openCLExcuter = new OpenCLExcuter();
|
openCLExcuter->init();
|
|
}
|
|
|
list<TradeData> ScreenDataCapture::captureLevel2TradeData(cv::Mat oimg, int identify) {
|
if (oimg.rows == 0 || oimg.cols == 0) {
|
throw ERROR_CODE_CAPTURE_FAIL;
|
}
|
|
clock_t starttime = clock();
|
|
/*
|
if (1 > 0) {
|
std:map<string, TradeData> map;
|
return map;
|
}
|
*/
|
|
|
//LogUtil::debug("½ØÍ¼Íê³É");
|
clock_t time_1 = clock();
|
//std::cout << "½ØÍ¼Íê³É: threadid-" << std::this_thread::get_id() << " ºÄʱ£º" << (time_1 - starttime) << endl;
|
|
//»Ò¶È»¯
|
cv::Mat img = cv::Mat::zeros(oimg.rows, oimg.cols, CV_8UC1);//ImgUtil::grayImage(oimg);
|
uchar* imgData = (uchar*)malloc(sizeof(uchar) * oimg.rows * oimg.cols);
|
|
openCLExcuter->rgb2Gray(oimg.data, oimg.cols, oimg.rows, imgData);
|
img.data = imgData;
|
oimg.release();
|
|
|
clock_t time_2 = clock();
|
std::cout << "»Ò¶ÈÍê³É: threadid-" << std::this_thread::get_id() << " ºÄʱ£º" << (time_2 - time_1) << endl;
|
LogUtil::debug("»Ò¶ÈÍê³É");
|
|
//½«Í¼ÏñתΪ1άÊý×é
|
//unsigned char* imgData = img.data;
|
|
|
|
|
//ͼÏñ·Ö¸î---¿ªÊ¼
|
list<int*> rowDataList;
|
try {
|
rowDataList = ImgUtil::divideImg(img);
|
if (rowDataList.size() == 0) {
|
throw ERROR_CODE_DIVIDE_IMG_FAIL;
|
}
|
}
|
catch (...) {
|
throw ERROR_CODE_DIVIDE_IMG_FAIL;
|
}
|
//×¼±¸Êý¾Ý
|
int* rowDataOneLevel = (int*)malloc(sizeof(int) * rowDataList.size() * 4);
|
list<int*>::iterator e;
|
int index = 0;
|
for (e = rowDataList.begin();e != rowDataList.end();e++) {
|
int* indexs = *e;
|
rowDataOneLevel[index * 4 + 0] = indexs[1];
|
rowDataOneLevel[index * 4 + 1] = indexs[0];
|
rowDataOneLevel[index * 4 + 2] = indexs[3];
|
rowDataOneLevel[index * 4 + 3] = indexs[2];
|
index++;
|
}
|
|
int* rowSplitDataOneLevel = (int*)malloc(sizeof(int) * rowDataList.size() * 4 * 7);
|
openCLExcuter->splitRowData(imgData, img.cols, img.rows, rowDataOneLevel, rowDataList.size(), rowSplitDataOneLevel);
|
free(rowDataOneLevel);
|
|
|
clock_t time_3 = clock();
|
//LogUtil::debug("·Ö¸ôÍê³É");
|
std::cout << "·Ö¸ôÍê³É: threadid-" << std::this_thread::get_id() << " ºÄʱ£º" << time_3 - time_2 << endl;
|
|
//ͼÏñ·Ö¸î---½áÊø
|
|
|
|
|
|
|
|
//ͼÏñʶ±ðµÄÊý×Ö×¼±¸
|
|
unsigned char* totalNumberData = (unsigned char*)malloc(sizeof(unsigned char) * (_NUMBER_L2_HEIGHT * rowDataList.size()) * _NUMBER_L2_WIDTH * 10 * _NUMBER_L2_TOTAL_NUMBER);
|
|
|
|
clock_t time_31 = clock();
|
std::cout << "Êý¾Ý×¼±¸-ͼÏñÊý¾Ý×¼±¸: threadid-" << std::this_thread::get_id() << " ºÄʱ£º" << time_31 - time_3 << endl;
|
|
int* pos = (int*)malloc(sizeof(int) * 3 * 4 * rowDataList.size());
|
|
|
index = 0;
|
for (e = rowDataList.begin();e != rowDataList.end();e++) {
|
|
int startS = index * 4 * 7;
|
|
|
int start = index * 4 * 3;
|
pos[start] = rowSplitDataOneLevel[startS + 0];
|
pos[start + 1] = rowSplitDataOneLevel[startS + 1];
|
pos[start + 2] = rowSplitDataOneLevel[startS + 2];
|
pos[start + 3] = rowSplitDataOneLevel[startS + 3];
|
|
|
start = index * 4 * 3 + 4 * 1;
|
pos[start] = rowSplitDataOneLevel[startS + 4 * 2 + 0];
|
pos[start + 1] = rowSplitDataOneLevel[startS + 4 * 2 + 1];
|
pos[start + 2] = rowSplitDataOneLevel[startS + 4 * 2 + 2];
|
pos[start + 3] = rowSplitDataOneLevel[startS + 4 * 2 + 3];
|
|
|
|
start = index * 4 * 3 + 4 * 2;
|
pos[start] = rowSplitDataOneLevel[startS + 4 * 5 + 0];
|
pos[start + 1] = rowSplitDataOneLevel[startS + 4 * 5 + 1];
|
pos[start + 2] = rowSplitDataOneLevel[startS + 4 * 5 + 2];
|
pos[start + 3] = rowSplitDataOneLevel[startS + 4 * 5 + 3];
|
|
index++;
|
}
|
|
|
clock_t time_32 = clock();
|
std::cout << "Êý¾Ý×¼±¸-λÖÃÊý¾Ý×¼±¸: threadid-" << std::this_thread::get_id() << " ºÄʱ£º" << time_32 - time_31 << endl;
|
|
unsigned char* zeroData = (unsigned char*)malloc(sizeof(unsigned char) * _NUMBER_L2_WIDTH * _NUMBER_L2_HEIGHT);
|
for (int r = 0;r < _NUMBER_L2_HEIGHT;r++) {
|
for (int c = 0;c < _NUMBER_L2_WIDTH;c++)
|
{
|
zeroData[r * _NUMBER_L2_WIDTH + c] = ImgUtil::NUMS_LEVEL2[0].data.ptr<uchar>(r)[c];
|
}
|
}
|
|
clock_t time_33 = clock();
|
std::cout << "Êý¾Ý×¼±¸-0Êý¾Ý×¼±¸: threadid-" << std::this_thread::get_id() << " ºÄʱ£º" << time_33 - time_32 << endl;
|
|
openCLExcuter->splitNum(imgData, img.cols, img.rows, pos, 3 * rowDataList.size(), zeroData, _NUMBER_L2_WIDTH, _NUMBER_L2_HEIGHT, _NUMBER_L2_TOTAL_NUMBER, totalNumberData);
|
|
free(pos);
|
free(zeroData);
|
|
|
/*
|
list<list<int*>>::iterator e;
|
int index = 0;
|
for (e = data.begin();e != data.end();e++) {
|
index++;
|
ImgUtil::splitRowNumDataForOpenCL(img, *e, totalNumberData,index-1);
|
}
|
|
*/
|
clock_t time_34 = clock();
|
std::cout << "Êý¾Ý×¼±¸-Êý×Ö·Ö¸ôÍê³É: threadid-" << std::this_thread::get_id() << " ºÄʱ£º" << time_34 - time_33 << endl;
|
|
//×¼±¸Ä£°åÊý×Ö
|
uchar* templateNums = (unsigned char*)malloc(sizeof(unsigned char) * (_NUMBER_L2_HEIGHT * rowDataList.size()) * _NUMBER_L2_WIDTH * 10 * _NUMBER_L2_TOTAL_NUMBER);
|
|
openCLExcuter->createNumberTemplates(rowDataList.size(), _NUMBER_L2_WIDTH, _NUMBER_L2_HEIGHT, _NUMBER_L2_TOTAL_NUMBER, ImgUtil::numsOneLevel_level2 ,templateNums);
|
|
//ImgUtil::createTemplateNumData(data.size());
|
clock_t time_4 = clock();
|
std::cout << "Êý¾Ý×¼±¸-Ä£°åÊý×Ö×¼±¸Íê³É: threadid-" << std::this_thread::get_id() << " ºÄʱ£º" << time_4 - time_34 << endl;
|
|
|
std::cout << "Êý¾Ý×¼±¸Íê³É: threadid-" << std::this_thread::get_id() << " ºÄʱ£º" << time_4 - time_3 << endl;
|
|
|
//ͼÏñʶ±ð(³ý¿ªÊý×ֵIJ¿·Ö)
|
RecognitionManager* recognitionManager = new RecognitionManager();
|
list<TradeData> resultList;
|
|
try {
|
resultList = (*recognitionManager).recognition(img, rowSplitDataOneLevel, rowDataList.size());
|
}
|
catch (...) {
|
throw ERROR_CODE_RECOGNITION_FAIL;
|
}
|
clock_t time_5 = clock();
|
std::cout << "·ÇÊý×ÖÊý¾Ýʶ±ðÍê³É: threadid-" << std::this_thread::get_id() << " ºÄʱ£º" << time_5 - time_4 << endl;
|
|
//Êý×Öʶ±ð
|
uchar** numberResult = openCLExcuter->recognition_numbers(totalNumberData, templateNums, rowDataList.size() * _NUMBER_L2_HEIGHT, _NUMBER_L2_WIDTH * 10 * _NUMBER_L2_TOTAL_NUMBER, _NUMBER_L2_WIDTH, _NUMBER_L2_HEIGHT, _NUMBER_L2_TOTAL_NUMBER);
|
//ÊÍ·ÅÄÚ´æ
|
free(totalNumberData);
|
free(templateNums);
|
//Ñ»·¶ÁÈ¡Êý×Ö
|
list<TradeData>::iterator tradeEle;
|
index = 0;
|
for (tradeEle = resultList.begin();tradeEle != resultList.end();tradeEle++) {
|
uchar* lineData = numberResult[index];
|
string time = "";
|
time.append(to_string(lineData[0])).append(to_string(lineData[1]));
|
time.append(":");
|
time.append(to_string(lineData[2])).append(to_string(lineData[3]));
|
time.append(":");
|
time.append(to_string(lineData[4])).append(to_string(lineData[5]));
|
string price = "";
|
price.append(to_string(lineData[6])).append(to_string(lineData[7])).append(to_string(lineData[8])).append(to_string(lineData[9]));
|
price.append(".");
|
price.append(to_string(lineData[10])).append(to_string(lineData[11]));
|
|
string num = "";
|
num.append(to_string(lineData[12])).append(to_string(lineData[13])).append(to_string(lineData[14])).append(to_string(lineData[15])).append(to_string(lineData[16]));
|
|
|
(*tradeEle).time = time;
|
(*tradeEle).num = stoi(num);
|
(*tradeEle).price = price;
|
(*tradeEle).index = index;
|
|
//ÊÍ·ÅÄÚ´æ
|
free(lineData);
|
|
index++;
|
}
|
|
free(numberResult);
|
|
clock_t time_6 = clock();
|
//LogUtil::debug("ʶ±ðÍê³É");
|
std::cout << "Êý×Öʶ±ðÍê³É: threadid-" << std::this_thread::get_id() << " ºÄʱ£º" << time_6 - time_5 << endl;
|
|
//ÊÍ·ÅÄÚ´æ
|
img.release();
|
rowDataList.clear();
|
list<int*>().swap(rowDataList);
|
//free(imgData);
|
free(rowSplitDataOneLevel);
|
|
delete recognitionManager;
|
|
std::cout << "-------½áÊøÈÎÎñ: threadid-" << std::this_thread::get_id() << " ÐòºÅ£º" << identify << " ºÄʱ£º" << clock() - starttime << endl;
|
|
return resultList;
|
}
|
|
//²¶»ñlevel2µÄÅÌ¿ÚÊý¾Ý
|
list<TradeData> ScreenDataCapture::captureLevel2TradeData(int frameIndex) throw(int) {
|
cv::Mat img = CaptureUtil::capture(frameIndex);
|
|
/*
|
string path1 = "E:\\temp\\";
|
|
path1.append(to_string(frameIndex));
|
path1.append("\\");
|
path1.append(to_string(clock()));
|
path1.append(".jpg");
|
cv::imwrite(path1, img);
|
std::map<string, TradeData> map;
|
*/
|
|
return captureLevel2TradeData(img, frameIndex);
|
}
|