Ask Your Question
0

Calibration from Images results in 0 Successes

asked 2016-12-12 03:01:38 -0600

Vintez gravatar image

updated 2016-12-12 07:15:01 -0600

I try to calibrate the Camera of a Smartphone with a console application because the speed of the Android example is very slow and It is hard to make proper Images.

The Console Application is inspired by a Book I found: OpenCV 2 Computer Vision: Application Programming Cookbook

Instead of a Chessboard like mentioned in the Book I take the Circle Grid from openCV which can be found in the "data" Folder.

Unfortunately when I use the "addChessboardPoints" Method I get the result of 0 successes and no Points are added into my Calibration. Here the Code:

int Calibrator::addChessboardPoints(const std::vector<std::string>& fileList, cv::Size& boardSize){

double onePerc = fileList.size() / 100.0f;

std::vector<cv::Point2f> imageCorners;
std::vector<cv::Point3f> objectCorners;

calcBoardCornerPositions(boardSize, 13.40, objectCorners, ASYMCIRCLE);

cv::Mat image;
int successes = 0;

for(int i = 0; i < fileList.size(); i++){

    double state = i+1.0f;
    double progress = state / onePerc;

    image = cv::imread(fileList[i], 0);

    bool found = cv::findCirclesGrid(image, boardSize, imageCorners, cv::CALIB_CV_ASYMMETRIC_GRID);

    if(!found){
        std::cout << "Progres: " << progress << "%" << std::endl;
        continue;
    }

    cv::cornerSubPix(image, imageCorners, cv::Size(5,5), cv::Size(-1,-1),
                     cv::TermCriteria(cv::TermCriteria::MAX_ITER + cv::TermCriteria::EPS, 30, 0.1));

    if(imageCorners.size() == boardSize.area()){
        addPoints(imageCorners, objectCorners);
        successes++;
    }
    std::cout << "Progress: " << progress << "%" << std::endl;
}
return successes;
}

The Images I took with my Camera can be looked up here. The boardSize used here is cv::Size(11,4)

Does anyone know, what I did wrong?

UPDATE corrected BoardSize and findCirclesGrid flag. Problem still occurs.

UPDATE added calcBoardCornerPositions and usage in addChessboardPoints

void Calibrator::calcBoardCornerPositions(cv::Size boardSize, float squareSize, std::vector<cv::Point3f>& corners, PatternType flag){
//BoardSize is 11,4
switch(flag){
    case CHESSBOARD:
    case CIRCLEGRID:
        for(int i = 0; i < boardSize.height; ++i)
            for(int j = 0; j < boardSize.width; ++j)
                corners.push_back(cv::Point3f(j*squareSize, i*squareSize, 0));
        break;
    case ASYMCIRCLE:
        for(int i = 0; i < boardSize.height; ++i)
            for(int j = 0; j < boardSize.width; ++i)
                corners.push_back(cv::Point3f((2*j + i % 2) * squareSize, i*squareSize, 0));
        break;
    default:
        break;
}

}
edit retag flag offensive close merge delete

Comments

1

It is written on the images: "this is a 11x4 OpenCV assymetric circles' grid".

Eduardo gravatar imageEduardo ( 2016-12-12 04:12:06 -0600 )edit

I also noticed this a couple of minutes ago (shame on me!) But when I change the boardSize I don't get another Result :/. I also changed the flag to cv::CALIB_CB_ASYMMETRIC_GRID But still with (11,4) and (4,11) I still get 0 successes Could it be, that my Images are not good?

Vintez gravatar imageVintez ( 2016-12-12 04:13:58 -0600 )edit
1

for an asymmetric grid, you need a different objectCorners pattern, see here (calcBoardCornerPositions())

berak gravatar imageberak ( 2016-12-12 05:28:59 -0600 )edit

ok, I will implement that method now, but one Question left, what should I put there as squareSize? I printed the circleGrid from the Docs on a DINA4 Paper.

Vintez gravatar imageVintez ( 2016-12-12 06:17:51 -0600 )edit
1

Measure them with a ruler or a caliper should do the trick.

Ice_T02 gravatar imageIce_T02 ( 2016-12-12 06:36:10 -0600 )edit

Ok, was not sure with that! And Unit of Measurement? mm would be okay am I right?

Vintez gravatar imageVintez ( 2016-12-12 06:42:08 -0600 )edit

Yes 'mm' is fine.

Ice_T02 gravatar imageIce_T02 ( 2016-12-12 06:45:52 -0600 )edit

unfortunately I get an Error now at this Line corners.push_back(cv::Point3f((2*j + i % 2) * squareSize, i*squareSize, 0)); the Error is signal SIGKILL. The last Task in the Thread List is this: template<typename _Tp> inline Point3_<_Tp>::Point3_(const Point3_& pt) : x(pt.x), y(pt.y), z(pt.z) {}

Vintez gravatar imageVintez ( 2016-12-12 07:02:07 -0600 )edit

can you post your code? EDIT: Do you clear vector<cv::Point3f> corners outside of your function?

Ice_T02 gravatar imageIce_T02 ( 2016-12-12 07:10:51 -0600 )edit

No I don't clear it anywhere. It is just filled once and is never touched after that. The reference Points to objectCorners. Also the Error occurs with the first Iteration of the code.

Vintez gravatar imageVintez ( 2016-12-12 07:34:46 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-12-12 09:24:36 -0600

Ice_T02 gravatar image

So i took the first image from the link and tested it. It seems that due to the image size it doesn't find the grid.

Please try the following:

1) Load the image

2) Set boardSize to:

cv::Size boardSize(4, 11);

3) Resize the image

resize(frame, small, cv::Size(), 0.25, 0.25,0);

4) Find circle grid

bool found = cv::findCirclesGrid(small, boardSize, imageCorners, CALIB_CB_ASYMMETRIC_GRID);

Hope this helps

edit flag offensive delete link more

Comments

Well it solves my Problem now I get 17 Results with my Image set. But just one Question for clarification, doesn't this approach could also manipulate the Result of the Calibration?

Vintez gravatar imageVintez ( 2016-12-12 09:46:07 -0600 )edit

Yes thats correct. I just wanted to edit my answer and tell you that you can't use the calibration parameters for the original resolution. Anyway i see two possibilities. Either decrease the resolution until the algorithm finds the grid or adapt cv::findCirclesGrid() function.

Ice_T02 gravatar imageIce_T02 ( 2016-12-12 09:53:10 -0600 )edit

@Vintez I think my previous comment is incorrect. Please read the following. There are atleast some parameters which can be used without scaling.

Ice_T02 gravatar imageIce_T02 ( 2016-12-13 08:09:49 -0600 )edit

@Ice_T02 I think I know what you want to say. If I resize the Image and do the calibration, but want to use the Camera Matrix and everything else for a larger Image scale, I have to multiply the Values of the Camera Matrix with the scalefactor and they should be 'ok' right?

Vintez gravatar imageVintez ( 2016-12-13 08:19:08 -0600 )edit

Basically yes. But read the articel i think it states the the distortion coefficients applies for all image resolutions.

Ice_T02 gravatar imageIce_T02 ( 2016-12-13 08:24:38 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-12-12 03:01:38 -0600

Seen: 931 times

Last updated: Dec 12 '16