Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Opencv function crashes on AMD processors, runs fine on Intel.

As above, I have a function in my application that uses opencv and the aruco module.

On machines with Intel cpus, it runs great. (tested on more than 20 PCs). On machines with AMD cpus, it freezes and crashes the application.

I have tried rebuilding opencv and disabling AVX512 instructions, and I see the same thing.

Why might this be happening?

The specific code is:

if (InImage.channels() != 1)
    {
        cvtColor(InImage, InImage, cv::COLOR_BGR2GRAY);

    }

    found = false;
    vector< int > ids;
    vector< vector< Point2f > > corners, rejected;
    Vec3d rvec, tvec;

    ArucoFunctionsT265::Pose poseInv;

    // detect markers
    aruco::detectMarkers(InImage, dictionary5, corners, ids, detectorParams5, rejected);
    aruco::refineDetectedMarkers(InImage, boardMapOrigin5, corners, ids, rejected, cam, dist);

    // estimate board pose
    int markersOfBoardDetected = 0;
    if (ids.size() > 0)
    {
        markersOfBoardDetected =
            estimatePoseBoardLocal5(corners, ids, boardMapOrigin5, cam, dist, rvec, tvec);
    }

and:

//local
void getBoardObjectAndImagePointsLocal5(const Ptr<cv::aruco::Board> &board, InputArrayOfArrays detectedCorners,
    InputArray detectedIds, OutputArray objPoints, OutputArray imgPoints) {

    CV_Assert(board->ids.size() == board->objPoints.size());
    CV_Assert(detectedIds.total() == detectedCorners.total());

    size_t nDetectedMarkers = detectedIds.total();

    vector< Point3f > objPnts;
    objPnts.reserve(nDetectedMarkers);

    vector< Point2f > imgPnts;
    imgPnts.reserve(nDetectedMarkers);

    // look for detected markers that belong to the board and get their information
    for (unsigned int i = 0; i < nDetectedMarkers; i++) {
        int currentId = detectedIds.getMat().ptr< int >(0)[i];
        for (unsigned int j = 0; j < board->ids.size(); j++) {
            if (currentId == board->ids[j]) {
                for (int p = 0; p < 4; p++) {
                    objPnts.push_back(board->objPoints[j][p]);
                    imgPnts.push_back(detectedCorners.getMat(i).ptr< Point2f >(0)[p]);
                }
            }
        }
    }

    // create output
    Mat(objPnts).copyTo(objPoints);
    Mat(imgPnts).copyTo(imgPoints);
}

int estimatePoseBoardLocal5(InputArrayOfArrays _corners, InputArray _ids, const Ptr<cv::aruco::Board> &board,
    InputArray _cameraMatrix, InputArray _distCoeffs, Vec3d &_rvec,
    Vec3d &_tvec) {

    CV_Assert(_corners.total() == _ids.total());

    // get object and image points for the solvePnP function
    Mat objPoints, imgPoints;
    getBoardObjectAndImagePointsLocal5(board, _corners, _ids, objPoints, imgPoints);

    CV_Assert(imgPoints.total() == objPoints.total());

    if (objPoints.total() == 0)
        return 0;


    solvePnP(objPoints, imgPoints, _cameraMatrix, _distCoeffs, _rvec, _tvec, false, cv::SOLVEPNP_IPPE); //SOLVEPNP_ITERATIVE

    //  cv::solvePnPRansac(objPoints, imgPoints, _cameraMatrix, _distCoeffs, _rvec, _tvec, false, 300, 1.0, 0.99, cv::noArray(), SOLVEPNP_ITERATIVE);

    // divide by four since all the four corners are concatenated in the array for each marker
    return (int)objPoints.total() / 4;
}

Opencv function crashes on AMD processors, runs fine on Intel.

As above, I have a function in my application that uses opencv and the aruco module.

On machines with Intel cpus, it runs great. (tested on more than 20 PCs). On machines with AMD cpus, it freezes and crashes the application.

I have tried rebuilding opencv and disabling AVX512 instructions, and I see the same thing.

Why might this be happening?

The specific code function that crashes is:

if (InImage.channels() != 1)
    {
        cvtColor(InImage, InImage, cv::COLOR_BGR2GRAY);

    }

    found = false;
    vector< int > ids;
    vector< vector< Point2f > > corners, rejected;
    Vec3d rvec, tvec;

    ArucoFunctionsT265::Pose poseInv;

    // detect markers
    aruco::detectMarkers(InImage, dictionary5, corners, ids, detectorParams5, rejected);
    aruco::refineDetectedMarkers(InImage, boardMapOrigin5, corners, ids, rejected, cam, dist);

    // estimate board pose
    int markersOfBoardDetected = 0;
    if (ids.size() > 0)
    {
        markersOfBoardDetected =
            estimatePoseBoardLocal5(corners, ids, boardMapOrigin5, cam, dist, rvec, tvec);
    }

and:

//local
void getBoardObjectAndImagePointsLocal5(const Ptr<cv::aruco::Board> &board, InputArrayOfArrays detectedCorners,
    InputArray detectedIds, OutputArray objPoints, OutputArray imgPoints) {

    CV_Assert(board->ids.size() == board->objPoints.size());
    CV_Assert(detectedIds.total() == detectedCorners.total());

    size_t nDetectedMarkers = detectedIds.total();

    vector< Point3f > objPnts;
    objPnts.reserve(nDetectedMarkers);

    vector< Point2f > imgPnts;
    imgPnts.reserve(nDetectedMarkers);

    // look for detected markers that belong to the board and get their information
    for (unsigned int i = 0; i < nDetectedMarkers; i++) {
        int currentId = detectedIds.getMat().ptr< int >(0)[i];
        for (unsigned int j = 0; j < board->ids.size(); j++) {
            if (currentId == board->ids[j]) {
                for (int p = 0; p < 4; p++) {
                    objPnts.push_back(board->objPoints[j][p]);
                    imgPnts.push_back(detectedCorners.getMat(i).ptr< Point2f >(0)[p]);
                }
            }
        }
    }

    // create output
    Mat(objPnts).copyTo(objPoints);
    Mat(imgPnts).copyTo(imgPoints);
}

int estimatePoseBoardLocal5(InputArrayOfArrays _corners, InputArray _ids, const Ptr<cv::aruco::Board> &board,
    InputArray _cameraMatrix, InputArray _distCoeffs, Vec3d &_rvec,
    Vec3d &_tvec) {

    CV_Assert(_corners.total() == _ids.total());

    // get object and image points for the solvePnP function
    Mat objPoints, imgPoints;
    getBoardObjectAndImagePointsLocal5(board, _corners, _ids, objPoints, imgPoints);

    CV_Assert(imgPoints.total() == objPoints.total());

    if (objPoints.total() == 0)
        return 0;


    solvePnP(objPoints, imgPoints, _cameraMatrix, _distCoeffs, _rvec, _tvec, false, cv::SOLVEPNP_IPPE); //SOLVEPNP_ITERATIVE

    //  cv::solvePnPRansac(objPoints, imgPoints, _cameraMatrix, _distCoeffs, _rvec, _tvec, false, 300, 1.0, 0.99, cv::noArray(), SOLVEPNP_ITERATIVE);

    // divide by four since all the four corners are concatenated in the array for each marker
    return (int)objPoints.total() / 4;
}

Opencv function crashes on AMD processors, runs fine on Intel.

As above, I have a function in my application that uses opencv and the aruco module.

On machines with Intel cpus, it runs great. (tested on more than 20 PCs). On machines with AMD cpus, it freezes and crashes the application.

I have tried rebuilding opencv and disabling AVX512 instructions, and I see the same thing.

Why might this be happening?

The specific function that crashes is:

    aruco::detectMarkers(InImage, dictionary5, corners, ids, detectorParams5, rejected);