Ask Your Question

Revision history [back]

C API problem on OpenCV 3.4.6.

I try to use cvGetSize function, but exception error occurred.

Unhandled exception at 0x00007FFA9563A388 in TestOpenCV2015.exe: Microsoft C++ exception: cv::Exception at memory location 0x0000001F0F0FD558.

I use released binary on opencv-3.4.6-vc14_vc15.exe file and just create image and check size.

IplImage* pIplImage = cvCreateImage(cvSize(100, 100), IPL_DEPTH_8U, 3);
CvSize szImg = cvGetSize(pIplImage);
CString strMsg;
strMsg.Format(L"Created Image Size is %dx%d", szImg.width, szImg.height);
AfxMessageBox(strMsg);

cvReleaseImage(&pIplImage);

Occurred exception error on Line 2.

I try to move cvGetSize to my project.

CvSize CTestOpenCV2015Dlg::getCvSize(CvArr* arr)
{
    CvSize size = { 0, 0 };

    if (CV_IS_MAT_HDR_Z(arr))
    {
        CvMat *mat = (CvMat*)arr;

        size.width = mat->cols;
        size.height = mat->rows;
    }
    else if (CV_IS_IMAGE_HDR(arr))
    {
        IplImage* img = (IplImage*)arr;

        if (img->roi)
        {
            size.width = img->roi->width;
            size.height = img->roi->height;
        }
        else
        {
            size.width = img->width;
            size.height = img->height;
        }
    }
    else
        CV_Error(CV_StsBadArg, "Array should be CvMat or IplImage");

    return size;
}

That works fine.

Why? How to fix that? How to build OpenCV 3.4.6 library to use C API functions?