-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
80 lines (64 loc) · 1.6 KB
/
main.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <decode_object.hpp>
#include <decode.hpp>
#include <cover_to_display.hpp>
#include <action.hpp>
#define debug
#include <robot/controllers.cpp>
int main (int argc, char* argv[])
{
VideoCapture cap;
if (!cap.open ("http://172.16.0.60:8080/video"))
return 0;
robosapien::interface robot;
for (;;) {
Mat im;
// Read image
cap >> im;
if (im.empty ()) break; // end of video stream
// Variable for decoded objects
vector <decodedObject> decodedObjects;
// Find and decode barcodes and QR codes
decode (im, decodedObjects, [&robot, &im](const decodedObject& obj)
{
// Print type and data
cout << "Type : " << obj.type << endl;
cout << "Data : " << obj.data << endl << endl;
bool problem_detected = false;
for (auto& point : obj.location)
{
cout << " X : " << point.x << endl << endl;
cout << " Y : " << point.y << endl << endl;
if (point.y >= im.rows - 30) // 30px between the robot and the QR code (our wall)
{
if (point.x <= im.cols / 4)
{
// turn left
robot.turn_left (3);
problem_detected = true;
break;
}
else if (point.x >= 3 * im.cols / 4)
{
// turn right
robot.turn_left (4);
problem_detected = true;
break;
}
else
{
continue;
}
}
else // no problems in front of me
{
continue;
}
}
if (problem_detected)
robot.go_forward (1.5); // go ahead more
});
// Display location
display (im, decodedObjects);
}
return EXIT_SUCCESS;
}