-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAprilTagDetectionDemoV2.cpp
67 lines (52 loc) · 1.56 KB
/
AprilTagDetectionDemoV2.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
using namespace std;
#include <iostream>
#include <cstring>
#include <vector>
#include <list>
#include <sys/time.h>
#ifndef __APPLE__
#define EXPOSURE_CONTROL
#endif
#ifdef EXPOSURE_CONTROL
#include <libv4l2.h>
#include <linux/videodev2.h>
#include <fcntl.h>
#include <errno.h>
#endif
#include "opencv2/opencv.hpp"
#include "AprilTags/TagDetector.h"
#include "AprilTags/Tag16h5.h"
#include "AprilTags/Tag25h7.h"
#include "AprilTags/Tag25h9.h"
#include "AprilTags/Tag36h9.h"
#include "AprilTags/Tag36h11.h"
#include <unistd.h>
cv::VideoCapture m_cap = cv::VideoCapture(0);
AprilTags::TagDetector* m_tagDetector = new AprilTags::TagDetector(AprilTags::tagCodes36h11);
void processImage(cv::Mat& image, cv::Mat& image_gray)
{
cv::cvtColor(image, image_gray, cv::COLOR_BGR2GRAY);
vector<AprilTags::TagDetection> detections = m_tagDetector->extractTags(image_gray);
cout << detections.size() << " tags detected:" << endl;
int frame_width = m_cap.get(cv::CAP_PROP_FRAME_WIDTH);
int frame_height = m_cap.get(cv::CAP_PROP_FRAME_HEIGHT);
cv::VideoWriter video("AprilTagOutput.avi", cv::VideoWriter::fourcc('W', 'M', 'V', '2'), 15, cv::Size(frame_width, frame_height), true);
for (int i=0; i<detections.size(); i++)
{
detections[i].draw(image);
}
video.write(image);
imshow("AprilTagDetector", image);
}
int main(int argc, char* argv[])
{
cv::Mat image;
cv::Mat image_gray;
while (true)
{
m_cap >> image;
processImage(image, image_gray);
if (cv::waitKey(1) >= 0) break;
}
return 0;
}