In the code below, similar to the one found in this opencv (ch)aruco detection doc, i get a segmentation fault from lines involving the DetectorParameters
(except the declaration). 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;