Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 41027

fisheye camea calibration

$
0
0
hello, I can't get correct image from following code. Could you find where are problems in my code. thanks, int main(int argc, char** argv) { Mat frame = imread("fisheye_img.jpg"); Size boardSize; boardSize.width = 8; boardSize.height = 5; int sq_sz = 30; vector> img_points; vector> obj_points(1); int width = boardSize.width; int height = boardSize.height; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { obj_points[0].push_back(Point3f(float(j * sq_sz), float(i * sq_sz), 0)); } } vector corners; bool found = findChessboardCorners(frame, boardSize, corners, CALIB_CB_ADAPTIVE_THRESH|CALIB_CB_NORMALIZE_IMAGE|CALIB_CB_FAST_CHECK); if(found) drawChessboardCorners(frame, boardSize, corners, found); else cout << "can't find corners" << endl; return -1; vector img_temp; for (int i = 0; i < width*height; i++) { Point2d temp = corners[i]; img_temp.push_back(temp); } img_points.push_back(img_temp); Mat _cameraMatrix; Mat _distCoeffs; _cameraMatrix = Mat::eye(3, 3, CV_64F); _distCoeffs = Mat::zeros(4, 1, CV_64F); std::vector rvecs(1); std::vector tvecs(1); Size imagesize = frame.size(); obj_points.resize(img_points.size(),obj_points[0]); int flags = cv::fisheye::CALIB_RECOMPUTE_EXTRINSIC | cv::fisheye::CALIB_FIX_SKEW | //cv::fisheye::CALIB_CHECK_COND | cv::fisheye::CALIB_FIX_K3 | cv::fisheye::CALIB_FIX_K4; double rms = cv::fisheye::calibrate(obj_points, img_points, imagesize, _cameraMatrix, _distCoeffs, rvecs, tvecs, flags, cv::TermCriteria(3, 20, 1e-6)); //cv::TermCriteria(cv::TermCriteria::COUNT + cv::TermCriteria::EPS, 100, DBL_EPSILON)); cout << "RMS : " << rms << endl; cout << "_cameraMatrix : " << _cameraMatrix << endl; cout << "_distCoeffs : " << _distCoeffs << endl; Mat new_frame, map1, map2; Mat newCamMat; fisheye::estimateNewCameraMatrixForUndistortRectify(_cameraMatrix, _distCoeffs, imagesize, Matx33d::eye(), newCamMat, 1); fisheye::initUndistortRectifyMap(_cameraMatrix, _distCoeffs, Matx33d::eye(), newCamMat, imagesize, CV_16SC2, map1, map2); remap(frame, new_frame, map1, map2, INTER_LINEAR); imshow("input image", frame); imshow("correct image", new_frame); cvWaitKey ( 0 ) ; return 0; }

Viewing all articles
Browse latest Browse all 41027

Trending Articles