-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharmor_detect_demo.cpp
72 lines (53 loc) · 1.68 KB
/
armor_detect_demo.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
#include "MVCameraInput.h"
#include "VideoInput.h"
#include "ArmorDetect.h"
int main(int argc, char *argv[]) {
std::string filename;
std::shared_ptr<ImageInput> video;
if (argc > 1) {
filename = std::string(argv[1]);
std::cout << "Opening file: " << filename << std::endl;
video = std::make_shared<VideoInput>(filename);
} else {
video = std::make_shared<MVCameraInput>();
}
ImageInput & cap = *video;
if (!cap) return EXIT_FAILURE;
cv::namedWindow("frame");
cv::namedWindow("show");
cv::Mat frame;
cap >> frame;
std::cout << frame.size();
cv::waitKey(0);
ArmorDetect inst(ArmorDetect::Mode::FIND_BLUE);
while (true) {
cap >> frame;
// frame: original video source
cv::imshow("frame", frame);
cv::Mat show;
frame.copyTo(show);
// get target
auto aimArea = inst.process(frame);
// draw all light bars in frame
for (const auto &bar : inst.getLightBars()) {
cv::Point2f pts[4];
bar.box.points(pts);
// Draw with green lines
drawTetragon(show, pts, cv::Scalar(0, 255, 0));
}
if (aimArea.empty()) {
std::cout << "No target found.\n";
} else {
drawTetragon(show, aimArea.data(), cv::Scalar(255, 255, 255));
}
// draw all armors
for (const auto& armor : inst.getResults()) {
cv::Point2f pts[4];
armor.points(pts);
drawTetragon(show, pts, cv::Scalar(0,255,0));
}
cv::imshow("show", show);
// view frame by frame
if (cv::waitKey(0) == 27) break;
}
}