Click here to Skip to main content
15,887,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm new on this forum. I'd like to ask you a question that has been annoying me all this day. the problem is that i don't find anything on internet about it. At the university we have to do this: Write a program that: -Loads the checkerboard images. ( these imagines are in a folder provided by the professor, they represent some pictures (15) taken by a Huawei smartphone of a chessboard). -Detects the checkerboard intersections in each image. The OpenCV function you need is cv::findChessboardCorners() (optional: consider to use the cv::cornerSubPix() function to refine the corner detections).

I'm writing it with Xcode ( c++) with opencv 3.4.5 on a Macbook.

The problem is that at the instruction "findChessboardCorners" it gets me an error. I really don't understand what causes it, the problem is " abort trap: 6. Can Someone help me?

Thank you very much.

What I have tried:

C++
#include <sstream>
#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/calib3d/calib3d.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>


#define points_per_row 12
#define points_per_colum 8
using namespace cv;
using namespace std;


int main(int argc, const char * argv[]) {
    //read the file
    stringstream sst;
    vector<Mat> imagesArray;
    vector<Point2f> centers; //this will be filled by the detected centers
    Size patternSize = Size(11, 7); //2nd parameter FindchessCorners
    bool patternfound = false; //result of findChessboardCorners

    cout << "flag1 "<< endl;
    for(int i = 1; i < 16; i++){
        sst << "img" << i << ".jpg";
        cout << sst.str() << endl;
        imagesArray.push_back(imread(sst.str())); // putting into an array
        cout << "flag2" << endl;
    }//for
    //PUNTO 2: individuation of the corners of every image
    for(int i = 0 ; i <=15 ; i++){
        cout << "flag3" << endl;
        patternfound = findChessboardCorners(imagesArray[i] , patternSize , centers);
        if(patternfound){
            cout << "pattern found:"<< patternSize << endl;
            cout << "centroids: " << centers << endl;
            cout << "centroids array size: " << centers.size() << endl;
        for(int j = 0; j < centers.size(); j++)
                cout << centers[j] << endl;
        }
    }//for

return 0;
}
Posted
Updated 23-Mar-19 2:34am
v2

The problem is in the for loops. You stated there are fifteen images. Since array indexes start with zero, the fifteenth image will be index fourteen but your for loop goes out to fifteen. A better way to do this would be to define a constant :
C++
const int ImageCount = 15;

// and write the for loops like this :

for( int i = 0; i < ImageCount; ++i )
{
    sst << "img" << i + 1 << ".jpg";   // first image is 1

    // rest of code goes here
}

for( int i = 0 ; i < ImageCount ; i++)
{
    patternfound = findChessboardCorners( imagesArray[i] , patternSize , centers );

    // rest of code goes here
}
This should work better for you
 
Share this answer
 
Hi. First of all, thank you for answering. I followed your valuable advice(with a little modification, but that's the point), but the problem doesn't change. here the piece of the code correct:

for(int i = 0 ; i < imagesArray.size(); i++){
                        cout << "flag3" << endl;
                        patternfound = findChessboardCorners(imagesArray[i] , patternSize , centers);
                        if(patternfound){
                            cout << "pattern found:"<< patternSize << endl;
                            cout << "centroids: " << centers << endl;
                            cout << "centroids array size: " << centers.size() << endl;
                        for(int j = 0; j < centers.size(); j++)
                                cout << centers[j] << endl;
                        }//if
                    }//for


But still I get the same error when I compile:

libc++abi.dylib: terminating with uncaught exception of type cv::Exception: OpenCV(3.4.5) /tmp/opencv@3-20190117-71360-ynjwgu/opencv-3.4.5/modules/core/src/matrix.cpp:757: error: (-215:Assertion failed) dims <= 2 && step[0] > 0 in function 'locateROI'

Abort trap: 6
 
Share this answer
 
Comments
Richard MacCutchan 23-Mar-19 7:25am    
You need to look at the stack trace to see which part of your code leads to the assertion.
Member 14192637 23-Mar-19 7:30am    
hi, I'm compiling with the terminal. Do you know how I can do it?
Richard MacCutchan 23-Mar-19 7:37am    
Sorry, I have no idea what that means. You need to use whatever debugging features you have available.
Rick York 23-Mar-19 13:09pm    
First of all, look at what you have given us. An error message from line 757 of matrix.cpp in a function locateROI. What you haven't shown is the code around line 757 of matrix.cpp in locateROI or where you have called the function. How can we can guess what is going from that?

Secondly, this is not a solution to the question. You should have revised the question with more relevant information.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900