-
Notifications
You must be signed in to change notification settings - Fork 6
/
test_camera.cpp
60 lines (51 loc) · 1.54 KB
/
test_camera.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
#include "squaredcirclepattern.h"
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <string>
#include <vector>
using cv::Point2f;
using std::vector;
// patch the to_string(...) for gcc
namespace patch
{
template < typename T > std::string to_string( const T& n )
{
std::ostringstream stm ;
stm << n ;
return stm.str() ;
}
}
static void drawPoints(cv::Mat &frame, const vector<Point2f> &points)
{
int face = cv::FONT_HERSHEY_SCRIPT_SIMPLEX;
for (int i = 0; i < points.size(); ++i)
{
cv::Point pt(points[i].x, points[i].y);
cv::circle(frame, pt, 2, cv::Scalar(0,200,0), 2);
cv::putText(frame, patch::to_string(i), pt, face, 0.6, cv::Scalar(20,20,220), 2);
}
}
int main(int argc, char *argv[])
{
SquaredCirclePattern detector;
cv::VideoCapture cap(0);
if (!cap.isOpened())
return -1;
vector<Point2f> points;
for(;;)
{
cv::Mat frame, gray;
cap >> frame;
if (frame.empty())
break;
cv::cvtColor(frame, gray, cv::COLOR_BGR2GRAY);
if (0 == detector.detect(gray, points))
{
drawPoints(frame, points);
}
cv::imshow("frame", frame);
if (27 == cv::waitKey(10))
break;
}
return 0;
}