-
Notifications
You must be signed in to change notification settings - Fork 53
/
main.cpp
88 lines (73 loc) · 1.95 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
80
81
82
83
84
85
86
87
/* Copyright 2017 onlyliu([email protected]). */
/* */
/* Automatic Camera and Range Sensor Calibration using a single Shot */
/* this project realize the papar: Automatic Camera and Range Sensor */
/* Calibration using a single Shot */
#include "opencv2/opencv.hpp"
#include <algorithm>
#include "CornerDetAC.h"
#include "ChessboradStruct.h"
#include <stdio.h>
#include <iostream>
#include <time.h>
using namespace cv;
using namespace std;
using std::vector;
vector<Point2i> points;
int main(int argc, char* argv[])
{
Mat src1;
cv::Mat src;
printf("read file...\n");
string sr;
if(argc < 2)
sr = string("02.png");
else
sr = string(argv[1]);
string simage, stxt, ssave;
simage = sr ;//+ ".bmp";
stxt = sr + ".txt";
ssave = sr + ".png";
ssave = "./t/"+ssave;
src1 = imread(simage.c_str(), -1);//载入测试图像
if (src1.channels() == 1)
{
src = src1.clone();
}
else
{
if (src1.channels() == 3)
{
cv::cvtColor(src1, src, CV_BGR2GRAY);
}
else
{
if (src1.channels() == 4)
{
cv::cvtColor(src1, src, CV_BGRA2GRAY);
}
}
}
if (src.empty())
{
printf("Cannot read image file: %s\n", simage.c_str());
return -1;
}
else
{
printf("read image file ok\n");
}
vector<Point> corners_p;//存储找到的角点
double t = (double)getTickCount();
std::vector<cv::Mat> chessboards;
CornerDetAC corner_detector(src);
ChessboradStruct chessboardstruct;
Corners corners_s;
corner_detector.detectCorners(src, corners_p, corners_s, 0.01);
t = ((double)getTickCount() - t) / getTickFrequency();
std::cout << "time cost :" << t << std::endl;
ImageChessesStruct ics;
chessboardstruct.chessboardsFromCorners(corners_s, chessboards, 0.6);
chessboardstruct.drawchessboard(src1, corners_s, chessboards, "cb", 0);
return 0;
}