-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalphabot.cpp
59 lines (51 loc) · 1.48 KB
/
alphabot.cpp
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
#include "RequestProcessing.h"
#include "ImageProcessing.h"
using namespace std;
using namespace cv;
void SetColor(Mat &frame, VideoCapture cap)
{
namedWindow("Result");
namedWindow("Settings");
createTrackbar("h1", "Settings", 0, 255);
createTrackbar("s1", "Settings", 0, 255);
createTrackbar("v1", "Settings", 0, 255);
createTrackbar("h2", "Settings", 0, 255);
createTrackbar("s2", "Settings", 0, 255);
createTrackbar("v2", "Settings", 0, 255);
while(true)
{
cap >> frame;
Mat frameHsv;
cvtColor(frame, frameHsv, COLOR_BGR2HSV);
int h1 = getTrackbarPos("h1", "Settings");
int s1 = getTrackbarPos("s1", "Settings");
int v1 = getTrackbarPos("v1", "Settings");
int h2 = getTrackbarPos("h2", "Settings");
int s2 = getTrackbarPos("s2", "Settings");
int v2 = getTrackbarPos("v2", "Settings");
vector <int> HsvMin = {h1, s1, v1};
vector <int> HsvMax = {h2, s2, v2};
Mat thresh;
inRange(frameHsv, HsvMin, HsvMax, thresh);
imshow("Result", thresh);
char ch = waitKey(500);
if (ch == 27)
break;
}
destroyAllWindows();
}
int main()
{
Controller controller;
cv::VideoCapture Cap("/dev/video0");
char c;
cout << "Enter \'s\' to set color of bot : " << endl;
cin >> c;
if(c == 's')
{
Mat frame;
SetColor(frame, Cap);
}else
controller.FiniteAutomate(Cap);
return 0;
}