How to make the program wait while I translate the chessboard

I want to calibrate my stereo camera, so I am trying to capture 10 images for the checkerboard on the right and left.

what the code should do: capture 10 images of the checkerboard on the right and left of the camera. The program saves two images if both contain sharp corner points. The program has to wait 20 frames for me to change the position of the checkerboard.

what's going on: it grabs 10 good images and saves them, but it doesn't wait for me to reposition the checkerboard

this is my code:

int captureImages_stereoCal()
{
    CvCapture* captureL = cvCreateCameraCapture(1);
    assert(captureL);
    waitKey(10000);
    CvCapture* captureR = cvCreateCameraCapture(2);
    assert(captureR);
    waitKey(10000);
    /*Mat imageL ;
    Mat imageR*/ ;
    int nx=8 , nh=5;


    int frame=0;
    int s =1;
    int ss;

    CvPoint2D32f* cornersL = new CvPoint2D32f[nx*nh];
    int corner_countL;
    CvPoint2D32f* cornersR = new CvPoint2D32f[nx*nh];
    int corner_countR;

    IplImage *imageL=cvQueryFrame(captureL);
    IplImage *gray_imageL=cvCreateImage(cvGetSize(imageL),8,1);
    IplImage *CimageL=cvCreateImage(cvGetSize(imageL),32,3);
    IplImage *imageR=cvQueryFrame(captureR);
    IplImage *gray_imageR=cvCreateImage(cvGetSize(imageR),8,1);
    IplImage *CimageR=cvCreateImage(cvGetSize(imageL),32,3);
    const int board_dt=20;

    while(s<=12)
    {
        if(frame++ % board_dt == 0)
        {
            string Result;     
            ostringstream convert;  
            ss=s-2;
            convert << ss; 
            Result = convert.str(); 

            //n=(char)s;
            //waitKey(1000);
            //Left -----------------------------------------------------------------------------------------------------------
            string nameL="L.jpg";

            //Find chessboard corners:
            int foundL = cvFindChessboardCorners(imageL, Size(nx,nh), cornersL, &corner_countL,CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FILTER_QUADS);
            //Get Subpixel accuracy on those corners
            cvCvtColor(imageL, gray_imageL, CV_BGR2GRAY);
            cvFindCornerSubPix(gray_imageL, cornersL, corner_countL,cvSize(11,11),cvSize(-1,-1), cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 30, 0.1 ));
            //Draw it
            Mat MimageL(imageL);
            CimageL=imageL;
            cvDrawChessboardCorners(CimageL, Size(nx,nh), cornersL,corner_countL, foundL);

            //Right -----------------------------------------------------------------------------------------------
            string nameR="R.jpg";

            //Find chessboard corners:
            int foundR = cvFindChessboardCorners(imageR, Size(nx,nh), cornersR, &corner_countR,CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FILTER_QUADS);
            //Get Subpixel accuracy on those corners
            cvCvtColor(imageR, gray_imageR, CV_BGR2GRAY);
            cvFindCornerSubPix(gray_imageR, cornersR, corner_countR,cvSize(11,11),cvSize(-1,-1), cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 30, 0.1 ));
            //Draw it
            Mat MimageR(imageR);
            CimageR=imageR;
            cvDrawChessboardCorners(CimageR, Size(nx,nh), cornersR,corner_countR, foundR);
            cvShowImage( "CalibrationL", CimageL );
            cvShowImage( "CalibrationR", CimageR );



            if(s>2)
            {   
                if((corner_countL==(nx*nh)) && (corner_countR==(nx*nh)) )
                {
                    nameL.insert(1,Result);

                    imwrite(nameL,MimageL); 
                    nameR.insert(1,Result);

                    imwrite(nameR,MimageR);
                    s++;
                }
            }
            int c = cvWaitKey(15);
            if(c == 'p')
            {
                c = 0;
                while(c != 'p' && c != 27)
                {
                    c = cvWaitKey(250);
                }
            }
            if(c == 27)
                return 0;
            imageL = cvQueryFrame(captureL);

            imageR = cvQueryFrame(captureR);
            if(s<3)
                s++;
        }// frame++ end

    } // while end
    return 0;
}

      

Also, after it draws the corners, it saves the image with the corners drawn on it. I want to keep the images without any changes.

+3


source to share


1 answer


If I understand the problem correctly, it is because you are using post-increment in your if-statement conditional:

if(frame++ % board_dt == 0)



You initialize frame

to 0, so the first time you call the if statement, it effectively tests (0 % 20) == 0

which is true.

You can change the if statement to be pre-incremented, for example. if(++frame % board_dt == 0)

to get the behavior you are looking for

0


source







All Articles