Ask Your Question
0

Segmentation fault from DetectorParameters[SOLVED]

asked 2019-11-11 09:13:47 -0600

wr43th13 gravatar image

updated 2019-11-11 21:41:21 -0600

supra56 gravatar image

In the code below, similar to the one found in this opencv (ch)aruco board detection doc, i get a segmentation fault from lines involving the DetectorParameters (except the declaration) data structure. Commenting the lines params->cornerRefinementMethod = aruco::CORNER_REFINE_NONE; and aruco::detectMarkers(image, dictionary, corners, ids, params); results in no segmentation fault when executing. I can see the images from the camera (without detecting markers of course).

// charuco board generation
    Ptr<aruco::CharucoBoard> board = aruco::CharucoBoard::create(
        5, 
        7, 
        0.04, 
        0.02, 
        dictionary);
    Mat boardImage;
    board->draw({640, 480}, boardImage, 10, 1);
    imwrite("ArucoBoard.png", boardImage);


    //detection
    VideoCapture inputVideo(0);

    if(!inputVideo.isOpened())  // check if we succeeded
    {        
        cout << "Camera Init Fail\n";
        return -1;
    }

    cout<<"\nAfter check"<<endl;

    Ptr<aruco::DetectorParameters> params;
    params->cornerRefinementMethod = aruco::CORNER_REFINE_NONE;

    cout<<"\nBefore while"<<endl;

    while (inputVideo.grab()) {

        Mat image, imageCopy;
        inputVideo.retrieve(image);
        image.copyTo(imageCopy);

        cout<<"\nCopied image"<<endl;

        vector<int> ids;
        vector<vector<Point2f>> corners;
        aruco::detectMarkers(image, dictionary, corners, ids, params);

        cout<<"\nDetected markers"<<endl;

        // if at least one marker detected
        if (ids.size() > 0) {
            aruco::drawDetectedMarkers(imageCopy, corners, ids);
            vector<Point2f> charucoCorners;
            vector<int> charucoIds;
            aruco::interpolateCornersCharuco(corners, ids, image, board, charucoCorners, charucoIds);
            // if at least one charuco corner detected
            if(charucoIds.size() > 0)
                aruco::drawDetectedCornersCharuco(imageCopy, charucoCorners, charucoIds, Scalar(255, 0, 0));
        }
        imshow("out", imageCopy);
        char key = (char) waitKey(25);
        if (key == 27)
            break;
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2019-11-11 09:31:42 -0600

berak gravatar image

updated 2019-11-11 09:47:53 -0600

you've found a bug in the tutorial ;)

if you want to use additional params for the aruco detection, you need a valid instance of it

(as it is in the sample code) :

Ptr<aruco::DetectorParameters> params = aruco::DetectorParameters::create();
// now youcan use a "valid pointer" to set param values:
params->cornerRefinementMethod = aruco::CORNER_REFINE_NONE;

// also now with valid params 
aruco::detectMarkers(image, dictionary, corners, ids, params);
edit flag offensive delete link more

Comments

2

Yeah this fixes it. Not sure why opencv doc page doesn't assign anything to the params (i.e. Ptr<aruco::DetectorParameters> params = cv::aruco::DetectorParameters::create();, or using a params .yaml file). Thanks, begginer's mistake.

wr43th13 gravatar imagewr43th13 ( 2019-11-11 09:48:15 -0600 )edit
1

hey, it's an error in the tutorial, not your fault at all.

feel encouraged to raise an issue here about it, seriously.

berak gravatar imageberak ( 2019-11-11 09:53:23 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-11-11 09:13:47 -0600

Seen: 806 times

Last updated: Nov 11 '19