camera calibration problem

asked 2013-02-11 18:44:02 -0500

seifullaah73 gravatar image

Any e experts on here, please help

here is my code i have used

int main() { int numBoards = 0; int numCornersHor; int numCornersVer;

printf("Enter number of corners along width: ");
scanf("%d", &numCornersHor);

printf("Enter number of corners along height: ");
scanf("%d", &numCornersVer);

printf("Enter number of boards: ");
scanf("%d", &numBoards);

int numSquares = numCornersHor * numCornersVer;
Size board_sz = Size(numCornersHor, numCornersVer);
VideoCapture capture = VideoCapture(0);

vector<vector<Point3d>> object_points;
vector<vector<Point2d>> image_points;

vector<Point2d> corners;
int successes=0;

Mat image;
Mat gray_image;
capture >> image;

vector<Point3d> obj;
for(int j=0;j<numSquares;j++)
    obj.push_back(Point3d(j/numCornersHor, j%numCornersHor, 0.0f));

while(successes<numBoards)
{
    cvtColor(image, gray_image, CV_BGR2GRAY);

    bool found = findChessboardCorners(image, board_sz, corners, CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FILTER_QUADS);

    if(found)
    {
        cornerSubPix(gray_image, corners, Size(11, 11), Size(-1, -1), TermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 30, 0.1));
        drawChessboardCorners(gray_image, board_sz, corners, found);
    }

    imshow("win1", image);
    imshow("win2", gray_image);

    capture >> image;

    int key = waitKey(1);

    if(key==27)
        return 0;

    if(key==' ' && found!=0)
    {
        image_points.push_back(corners);
        object_points.push_back(obj);
        printf("Snap stored!\n");

        successes++;

        if(successes>=numBoards)
            break;
    }
}

Mat intrinsic = Mat(3, 3, CV_32FC1);
Mat distCoeffs;
vector<Mat> rvecs;
vector<Mat> tvecs;

intrinsic.ptr<float>(0)[0] = 1;
intrinsic.ptr<float>(1)[1] = 1;

calibrateCamera(object_points, image_points, image.size(), intrinsic, distCoeffs, rvecs, tvecs);

Mat imageUndistorted;
while(1)
{
    capture >> image;
    undistort(image, imageUndistorted, intrinsic, distCoeffs);

    imshow("win1", image);
    imshow("win2", imageUndistorted);

    waitKey(1);
}

capture.release();

return 0;

}

any help thanks

edit retag flag offensive close merge delete

Comments

Hi Seifullaah73, i am not an expert in camera calibration. But for the experts in camera calibration you should provide more informations about your problem. What kind of problem do you have? Do you get strange calibration results? Are there runtime errors?

Siegfried gravatar imageSiegfried ( 2013-02-12 12:36:59 -0500 )edit