2016-08-12 2 views
0

J'ai calibré un objectif fisheye en utilisant un jeu de 20 images d'un damier. Les points sont tous correctement étiquetés et j'ai des coefficients intrinsèques et de distorsion de l'objectif. Définir la variable 'square size' à 15 pour 15mm me donne 0 coefficients de distorsion et une distance focale de ~ 600. Le réglage à 0,015 me donne des coefficients de distorsion et une focale de ~ 1200. Dans les deux cas, mon centre de projection est approximativement le point médian de l'image qui est raisonnable.Erreur d'image fisheye non déportée

Lorsque j'essaie d'appliquer mon distorsion à mes images, j'obtiens un résultat très étrange.

Undistorted image

Je ne comprends pas pourquoi. Avec 0 sur les coefficients de distorsion, j'obtiens toujours cette image. Si quelqu'un peut l'aider serait grandement apprécié!

void undistortFisheye() 
{ 
    std::vector <cv::Mat> inputImages; 
    std::vector<std::vector<cv::Point3f> > objectPoints(1); 
    std::vector<std::vector<cv::Point2f>> image_points; 

//Load images 
for (int i = 0; i < 13; i++) 
{ 
    std::cout << "Loading: " << "C:/Data/CheckerboardCalib/" << std::to_string(i + 1) << ".png" << std::endl; 

    inputImages.push_back(cv::imread("C:/Data/CheckerboardCalib/" + std::to_string(i + 1) + ".png")); 
} 

int chessBoardFlags = cv::CALIB_CB_ADAPTIVE_THRESH | cv::CALIB_CB_NORMALIZE_IMAGE; 

for (int i = 0; i < inputImages.size(); i++) 
{ 
    std::vector<cv::Point2f> pointBuf; 
    cv::Mat view; 

    std::cout << i << std::endl; 
    bool found = cv::findChessboardCorners(inputImages[i], cv::Size(21, 14), pointBuf, chessBoardFlags); 

    if (found) // If done with success, 
    { 
     std::cout << "Corners found!" << std::endl; 

     // improve the found corners' coordinate accuracy for chessboard 
     cv::Mat viewGray; 
     cvtColor(inputImages[i], viewGray, cv::COLOR_BGR2GRAY); 
     cornerSubPix(viewGray, pointBuf, cv::Size(11, 11), cv::Size(-1, -1), cv::TermCriteria(cv::TermCriteria::EPS + cv::TermCriteria::COUNT, 30, 0.1)); 

     image_points.push_back(pointBuf); 

     // Draw the corners. 
    // inputImages[i].copyTo(view); 
     //cv::drawChessboardCorners(view, cv::Size(21, 14), cv::Mat(pointBuf), found); 
     //cv::imshow("Window", view); 
     //cv::waitKey(0); 
    } 
} 

float squareSize = 15.0f; 
calcBoardCornerPositions(cv::Size(21,14), squareSize, objectPoints[0]); 
objectPoints.resize(image_points.size(), objectPoints[0]); 

cv::Matx33f K; 
cv::Vec4f D; 

std::vector<cv::Vec3f> rvec; 
std::vector<cv::Vec3f> tvec; 

//int flag = cv::fisheye::CALIB_CHECK_COND | cv::fisheye::CALIB_FIX_SKEW; 
int flag = cv::fisheye::CALIB_FIX_SKEW | cv::fisheye::CALIB_RECOMPUTE_EXTRINSIC; 
//| cv::fisheye::CALIB_FIX_K1 | cv::fisheye::CALIB_FIX_K2 | cv::fisheye::CALIB_FIX_K3;// | cv::fisheye::CALIB_FIX_K4;// | cv::fisheye::CALIB_RECOMPUTE_EXTRINSIC;// | cv::fisheye::CALIB_FIX_K1;// | cv::fisheye::CALIB_RECOMPUTE_EXTRINSIC; 

cv::fisheye::calibrate(objectPoints, image_points, cv::Size(1920, 1080), K, D, rvec, tvec, flag, cv::TermCriteria(3, 20, 1e-6)); 

std::cout << "Points detected" << std::endl; 
//double rms = calibrateCamera(objectPoints, image_points, cv::Size(1920, 1080), K, D, rvec, tvec, flag, cv::TermCriteria(3, 20, 1e-6)); 
std::cout << "Calibrated." << std::endl; 

std::cout << K << std::endl; 
std::cout << D << std::endl; 

for (int i = 0; i < inputImages.size(); i++) 
{ 
    cv::Mat src = cv::imread("C:/Data/CheckerboardCalib/" + std::to_string(i + 1) + ".png"); 
    cv::Mat temp; 

    cv::fisheye::undistortImage(src, temp, K, D, cv::Mat::eye(3,3, CV_64F)); 
    cv::imwrite("C:/Data/CheckerboardCalib/undistorted/" + std::to_string(i+1) + ".png", temp); 
} 
std::string inputLine; 
std::cin >> inputLine; 
} 

Répondre