-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSquareTracker.cpp
More file actions
49 lines (44 loc) · 1.16 KB
/
Copy pathSquareTracker.cpp
File metadata and controls
49 lines (44 loc) · 1.16 KB
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
#include "SquareTracker.h"
#include <imgproc.hpp>
#include <Windows.h>
cv::Point SquareTracker::trackAndAction(std::vector<cv::Point2f> input, TrackerOption option)
{
//Sleep(5); //may add
cv::Moments mom = cv::moments(input);
cv::Point rectLocation = cv::Point(mom.m10/mom.m00, mom.m01/mom.m00);
INPUT key_input;
ZeroMemory(&key_input, sizeof(INPUT)); //0À¸·Î inputÀ» ÃʱâÈ
key_input.type = INPUT_KEYBOARD;
if (rectLocation.x < option.x1) {
if (rectLocation.y < option.y1) {
key_input.ki.wVk = (BYTE) (option.keyCodes)[0];
//1
}
else if (rectLocation.y >= option.y1 && rectLocation.y < option.y2) {
//(option.keyCodes)[2] == -1
//3 pass
}
else {
key_input.ki.wVk = (option.keyCodes)[4];
//5
}
}
else {
if (rectLocation.y < option.y1) {
key_input.ki.wVk = (option.keyCodes)[1];
//2
}
else if (rectLocation.y >= option.y1 && rectLocation.y < option.y2) {
key_input.ki.wVk = (option.keyCodes)[3];
//4
}
else {
key_input.ki.wVk = (option.keyCodes)[5];
//6
}
}
SendInput(1, &key_input, sizeof(INPUT));
key_input.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &key_input, sizeof(INPUT));
return rectLocation;
}