0
글쎄, 이것이 아이폰 5 교정에 대한 나의 시도이다. 그것은 끔찍하고, 나는 이유를 모른다. 그것은 적절하게 구석을 찾는 것처럼 보이고 예 27 이미지는 보정합니다. 결과는 체스 보드의 입체파 재 해석입니다. 누구든지 오류를 찾도록 도와 줄 수 있습니까? 최종 버전 저는 다른 사람들이이 모든 것을 할 필요가 없도록 최종 매개 변수뿐만 아니라 세상과 공유하게되어 기쁩니다.OpenCV 교정 코드
int board_w = 8; // Board width in squares
int board_h = 5; // Board height
int n_boards = 20; // Maximum number of boards
int board_n = board_w * board_h;//Number of internal corners.
cv::Size board_sz = cv::Size(board_w, board_h); // Dimensions of board
cv::vector<cv::vector<cv::Point3f>> object_points; // place to store location of points in 3d.
cv::vector<cv::vector<cv::Point2f>> image_points; // place to store points in 2d.
cv::Mat point_counts = cv::Mat(n_boards, 1, CV_32SC1);
cv::Mat intrinsic_matrix = cv::Mat(3, 3, CV_32FC1);
cv::Mat distortion_coeffs = cv::Mat(5, 1, CV_32FC1);
cv::vector<cv::Mat> rvecs;
cv::vector<cv::Mat> tvecs;
std::vector<cv::Point2f> imageCorners;
for (int i=1; i<27; i++)
{
NSLog(@"Processing image %d", i);
NSString *currentPhoto = [[NSString alloc] initWithFormat:@"Board%d", i];
NSString* pathToImageFile = [[NSBundle mainBundle] pathForResource:currentPhoto ofType:@"jpeg"];
UIImage* image = [UIImage imageWithContentsOfFile:pathToImageFile];
cv::Mat imageMat = [self cvMatFromUIImage:image];
cv::Mat imageMatGray;
cv::cvtColor(imageMat,imageMatGray,CV_RGB2GRAY);
// Find chessboard corners:
int found = cv::findChessboardCorners(imageMat, board_sz, imageCorners, CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FILTER_QUADS);
// Get subpixel accuracy on those corners
cv::cornerSubPix(imageMatGray, imageCorners, cvSize(11, 11),
cvSize(-1, -1), cv::TermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 30, 0.1));
cv::drawChessboardCorners(imageMat, board_sz, imageCorners, found);
self.image.image = [self UIImageFromCVMat:imageMat];
cv::vector<cv::Point3f> obj;
for(int j=0;j<40;j++)
{
obj.push_back(cv::Point3f(j/board_h, j%board_h, 0.0f));
}
image_points.push_back(imageCorners);
object_points.push_back(obj);
}
intrinsic_matrix.ptr<float>(0)[0] = 1;
intrinsic_matrix.ptr<float>(1)[1] = 1;
NSString* pathToImageFile2 = [[NSBundle mainBundle] pathForResource:@"Board200" ofType:@"JPG"];
NSLog(pathToImageFile2);
UIImage* image2 = [UIImage imageWithContentsOfFile:pathToImageFile2];
![enter image description here][1]
self.image.image = image2;
cv::Mat distortedImage = [self cvMatFromUIImage:image2];
cv::Mat undistortedImage;
calibrateCamera(object_points, image_points, distortedImage.size(), intrinsic_matrix, distortion_coeffs, rvecs, tvecs);
cv::undistort(distortedImage, undistortedImage, intrinsic_matrix, distortion_coeffs);
image2 = [self UIImageFromCVMat:undistortedImage];
self.image.image = image2;