admin
2023-02-09 125db633619a0b4c7bd1d498ea2bf1cefa4f73d3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#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;
}