好吧,这是我为iPhone 5进行校准的尝试。它很糟糕,我不知道为什么。 它似乎正在适当地找到角落,并且需要校准27张图像。 结果是棋盘的立体主义重新演绎。 谁能帮我找到错误? 我很乐意与世界分享最终版本以及最终参数,这样其他人就不必这样做。

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;

===============>>#1 票数:-1

小错误。

cv::Size board_sz = cv::Size( board_w, board_h ); // Dimensions of board

应该:

cv::Size board_sz = cv::Size( board_h, board_w ); // Dimensions of board

我也在研究这个问题,所以不确定它是否完美运行,但这是我发现的一个问题。

  ask by justagruvn translate from so

未解决问题?本站智能推荐: