#include "CaptureUtil.h"
|
#include "Win32Util.h"
|
|
HWND CaptureUtil::level2Frames[8];
|
HWND CaptureUtil::tradeQueueFrames[8];
|
std::list<FrameInfo> CaptureUtil::tempFrames;
|
|
BOOL CALLBACK CaptureUtil::EnumChildProc(HWND hwndChild, LPARAM lParam) {
|
//TEXT("AfxWnd100s")
|
char className[100];
|
GetClassNameA(hwndChild, className, 100);
|
if (string(className) == "AfxWnd100s") {
|
RECT rect;
|
GetWindowRect(hwndChild, &rect);
|
bool show= IsWindowVisible(hwndChild);
|
|
if (show&&rect.right - rect.left < 1000&& rect.right - rect.left>400)
|
{
|
FrameInfo info = FrameInfo();
|
info.frame = hwndChild;
|
info.position = rect;
|
tempFrames.push_back(info);
|
}
|
|
/*
|
if ( rect.right - rect.left>2800)
|
{
|
FrameInfo info = FrameInfo();
|
info.frame = hwndChild;
|
info.position = rect;
|
tempFrames.push_back(info);
|
}
|
*/
|
|
}
|
return TRUE;
|
}
|
void CaptureUtil::init(HWND l2win) {
|
tempFrames.clear();
|
HWND root = l2win;
|
RECT rootRect;
|
GetWindowRect(root, &rootRect);
|
int rootHeight = (rootRect.bottom- rootRect.top);
|
|
root = FindWindowEx(root, NULL, TEXT("AfxFrameOrView100s"), NULL);
|
|
EnumChildWindows(root, EnumChildProc, NULL);
|
|
std::list<FrameInfo> tempL2;
|
std::list<FrameInfo> tempTrade;
|
|
//¸³Öµ
|
std::list<FrameInfo>::iterator ele;
|
for (ele = tempFrames.begin();ele != tempFrames.end();ele++) {
|
FrameInfo frameInfo = *ele;
|
if (frameInfo.position.bottom - frameInfo.position.top > rootHeight/2) {
|
tempL2.push_back(frameInfo);
|
}
|
else {
|
|
if (frameInfo.position.bottom - frameInfo.position.top < 200 && frameInfo.position.bottom - frameInfo.position.top >40)
|
{
|
tempTrade.push_back(frameInfo);
|
}
|
}
|
}
|
//ÅÅÐò
|
tempL2.sort();
|
tempTrade.sort();
|
|
|
int index = 0;
|
for (ele = tempL2.begin();ele != tempL2.end();ele++) {
|
level2Frames[index++] = (*ele).frame;
|
}
|
|
index = 0;
|
for (ele = tempTrade.begin();ele != tempTrade.end();ele++) {
|
tradeQueueFrames[index++] = (*ele).frame;
|
}
|
//±£´æÍ¼Æ¬
|
for (int i = 0;i < 8;i++) {
|
cv::Mat img= ImgUtil::grayImage(capture(tradeQueueFrames[i]));
|
string path = "C:\\Users\\Administrator\\Desktop\\ocr\\trade_queue\\";
|
path.append(to_string(i)).append(".jpg");
|
//cv::imwrite(path,img);
|
}
|
|
|
|
}
|
HWND CaptureUtil::getHWND(int index, CaptureContentType type) {
|
if (type == CAPTURE_TYPE_L2)
|
return level2Frames[index];
|
else
|
return tradeQueueFrames[index];
|
}
|
|
cv::Mat CaptureUtil::capture(int index, CaptureContentType type) {
|
|
cv::Mat cap = capture(getHWND(index, type));
|
return cap;
|
}
|
|
|
cv::Mat CaptureUtil::capture(HWND hwnd) {
|
clock_t starttime = clock();
|
cv::Mat cap = _wss::screen_shot_by_window(hwnd);
|
//std::cout << "½ØÍ¼ºÄʱ: threadid-" << std::this_thread::get_id() << " ºÄʱ£º" << clock() - starttime << endl;
|
return cap;
|
}
|