-
Notifications
You must be signed in to change notification settings - Fork 877
/
Copy pathcalib3d.cpp
235 lines (211 loc) · 8.62 KB
/
calib3d.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#include "calib3d.h"
double Fisheye_Calibrate(Points3fVector objectPoints, Points2fVector imagePoints, Size size, Mat k, Mat d, Mat rvecs, Mat tvecs, int flags) {
try {
cv::Size sz(size.width, size.height);
return cv::fisheye::calibrate(*objectPoints, *imagePoints, sz, *k, *d, *rvecs, *tvecs, flags);
} catch(const cv::Exception& e){
setExceptionInfo(e.code, e.what());
return 0.0;
}
}
OpenCVResult Fisheye_DistortPoints(Mat undistorted, Mat distorted, Mat k, Mat d) {
try {
cv::fisheye::distortPoints(*undistorted, *distorted, *k, *d);
return successResult();
} catch(const cv::Exception& e) {
return errorResult(e.code, e.what());
}
}
OpenCVResult Fisheye_UndistortImage(Mat distorted, Mat undistorted, Mat k, Mat d) {
try {
cv::fisheye::undistortImage(*distorted, *undistorted, *k, *d);
return successResult();
} catch(const cv::Exception& e) {
return errorResult(e.code, e.what());
}
}
OpenCVResult Fisheye_UndistortImageWithParams(Mat distorted, Mat undistorted, Mat k, Mat d, Mat knew, Size size) {
try {
cv::Size sz(size.width, size.height);
cv::fisheye::undistortImage(*distorted, *undistorted, *k, *d, *knew, sz);
return successResult();
} catch(const cv::Exception& e) {
return errorResult(e.code, e.what());
}
}
OpenCVResult Fisheye_UndistortPoints(Mat distorted, Mat undistorted, Mat k, Mat d, Mat r, Mat p) {
try {
cv::fisheye::undistortPoints(*distorted, *undistorted, *k, *d, *r, *p);
return successResult();
} catch(const cv::Exception& e) {
return errorResult(e.code, e.what());
}
}
OpenCVResult Fisheye_EstimateNewCameraMatrixForUndistortRectify(Mat k, Mat d, Size imgSize, Mat r, Mat p, double balance, Size newSize, double fovScale) {
try {
cv::Size newSz(newSize.width, newSize.height);
cv::Size imgSz(imgSize.width, imgSize.height);
cv::fisheye::estimateNewCameraMatrixForUndistortRectify(*k, *d, imgSz, *r, *p, balance, newSz, fovScale);
return successResult();
} catch(const cv::Exception& e) {
return errorResult(e.code, e.what());
}
}
OpenCVResult InitUndistortRectifyMap(Mat cameraMatrix,Mat distCoeffs,Mat r,Mat newCameraMatrix,Size size,int m1type,Mat map1,Mat map2) {
try {
cv::Size sz(size.width, size.height);
cv::initUndistortRectifyMap(*cameraMatrix,*distCoeffs,*r,*newCameraMatrix,sz,m1type,*map1,*map2);
return successResult();
} catch(const cv::Exception& e) {
return errorResult(e.code, e.what());
}
}
Mat GetOptimalNewCameraMatrixWithParams(Mat cameraMatrix,Mat distCoeffs,Size size,double alpha,Size newImgSize,Rect* validPixROI,bool centerPrincipalPoint) {
try {
cv::Size sz(size.width, size.height);
cv::Size newSize(newImgSize.width, newImgSize.height);
cv::Rect rect(validPixROI->x,validPixROI->y,validPixROI->width,validPixROI->height);
cv::Mat* mat = new cv::Mat(cv::getOptimalNewCameraMatrix(*cameraMatrix,*distCoeffs,sz,alpha,newSize,&rect,centerPrincipalPoint));
validPixROI->x = rect.x;
validPixROI->y = rect.y;
validPixROI->width = rect.width;
validPixROI->height = rect.height;
return mat;
} catch(const cv::Exception& e){
setExceptionInfo(e.code, e.what());
return new cv::Mat();
}
}
double CalibrateCamera(Points3fVector objectPoints, Points2fVector imagePoints, Size imageSize, Mat cameraMatrix, Mat distCoeffs, Mat rvecs, Mat tvecs, int flag) {
try {
return cv::calibrateCamera(*objectPoints, *imagePoints, cv::Size(imageSize.width, imageSize.height), *cameraMatrix, *distCoeffs, *rvecs, *tvecs, flag);
} catch(const cv::Exception& e){
setExceptionInfo(e.code, e.what());
return 0.0;
}
}
OpenCVResult Undistort(Mat src, Mat dst, Mat cameraMatrix, Mat distCoeffs, Mat newCameraMatrix) {
try {
cv::undistort(*src, *dst, *cameraMatrix, *distCoeffs, *newCameraMatrix);
return successResult();
} catch(const cv::Exception& e) {
return errorResult(e.code, e.what());
}
}
OpenCVResult UndistortPoints(Mat distorted, Mat undistorted, Mat k, Mat d, Mat r, Mat p) {
try {
cv::undistortPoints(*distorted, *undistorted, *k, *d, *r, *p);
return successResult();
} catch(const cv::Exception& e) {
return errorResult(e.code, e.what());
}
}
bool CheckChessboard(Mat image, Size size) {
try {
cv::Size sz(size.width, size.height);
return cv::checkChessboard(*image, sz);
} catch(const cv::Exception& e){
setExceptionInfo(e.code, e.what());
return false;
}
}
bool FindChessboardCorners(Mat image, Size patternSize, Mat corners, int flags) {
try {
cv::Size sz(patternSize.width, patternSize.height);
return cv::findChessboardCorners(*image, sz, *corners, flags);
} catch(const cv::Exception& e){
setExceptionInfo(e.code, e.what());
return false;
}
}
bool FindChessboardCornersSB(Mat image, Size patternSize, Mat corners, int flags) {
try {
cv::Size sz(patternSize.width, patternSize.height);
return cv::findChessboardCornersSB(*image, sz, *corners, flags);
} catch(const cv::Exception& e){
setExceptionInfo(e.code, e.what());
return false;
}
}
bool FindChessboardCornersSBWithMeta(Mat image, Size patternSize, Mat corners, int flags, Mat meta) {
try {
cv::Size sz(patternSize.width, patternSize.height);
return cv::findChessboardCornersSB(*image, sz, *corners, flags, *meta);
} catch(const cv::Exception& e){
setExceptionInfo(e.code, e.what());
return false;
}
}
OpenCVResult DrawChessboardCorners(Mat image, Size patternSize, Mat corners, bool patternWasFound) {
try {
cv::Size sz(patternSize.width, patternSize.height);
cv::drawChessboardCorners(*image, sz, *corners, patternWasFound);
return successResult();
} catch(const cv::Exception& e) {
return errorResult(e.code, e.what());
}
}
Mat EstimateAffinePartial2D(Point2fVector from, Point2fVector to) {
try {
return new cv::Mat(cv::estimateAffinePartial2D(*from, *to));
} catch(const cv::Exception& e){
setExceptionInfo(e.code, e.what());
return new cv::Mat();
}
}
Mat EstimateAffinePartial2DWithParams(Point2fVector from, Point2fVector to, Mat inliers, int method, double ransacReprojThreshold, size_t maxIters, double confidence, size_t refineIters) {
try {
return new cv::Mat(cv::estimateAffinePartial2D(*from, *to, *inliers, method, ransacReprojThreshold, maxIters, confidence, refineIters));
} catch(const cv::Exception& e){
setExceptionInfo(e.code, e.what());
return new cv::Mat();
}
}
Mat EstimateAffine2D(Point2fVector from, Point2fVector to) {
try {
return new cv::Mat(cv::estimateAffine2D(*from, *to));
} catch(const cv::Exception& e){
setExceptionInfo(e.code, e.what());
return new cv::Mat();
}
}
Mat EstimateAffine2DWithParams(Point2fVector from, Point2fVector to, Mat inliers, int method, double ransacReprojThreshold, size_t maxIters, double confidence, size_t refineIters) {
try {
return new cv::Mat(cv::estimateAffine2D(*from, *to, *inliers, method, ransacReprojThreshold, maxIters, confidence, refineIters));
} catch(const cv::Exception& e){
setExceptionInfo(e.code, e.what());
return new cv::Mat();
}
}
OpenCVResult TriangulatePoints(Mat projMatr1, Mat projMatr2, Point2fVector projPoints1, Point2fVector projPoints2, Mat points4D) {
try {
cv::triangulatePoints(*projMatr1, *projMatr2, *projPoints1, *projPoints2, *points4D);
return successResult();
} catch(const cv::Exception& e) {
return errorResult(e.code, e.what());
}
}
OpenCVResult ConvertPointsFromHomogeneous(Mat src, Mat dst) {
try {
cv::convertPointsFromHomogeneous(*src, *dst);
return successResult();
} catch(const cv::Exception& e) {
return errorResult(e.code, e.what());
}
}
OpenCVResult Rodrigues(Mat src, Mat dst) {
try {
cv::Rodrigues(*src, *dst);
return successResult();
} catch(const cv::Exception& e) {
return errorResult(e.code, e.what());
}
}
bool SolvePnP(Point3fVector objectPoints, Point2fVector imagePoints, Mat cameraMatrix, Mat distCoeffs, Mat rvec, Mat tvec, bool useExtrinsicGuess, int flags) {
try {
return cv::solvePnP(*objectPoints, *imagePoints, *cameraMatrix, *distCoeffs, *rvec, *tvec, useExtrinsicGuess, flags);
} catch(const cv::Exception& e){
setExceptionInfo(e.code, e.what());
return false;
}
}