C API problem on OpenCV 3.4.6. [closed]

asked 2019-05-23 00:07:02 -0600

NeoDreamer gravatar image

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?

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by berak
close date 2019-05-23 01:42:28.034603

Comments

1

try to avoid the old c-api, support for that is fading away quickly. try to use proper c++ for this, avoid IplImages and cv*Functions in general:

sturkmen gravatar imagesturkmen ( 2019-05-23 01:00:48 -0600 )edit

@sturkmen << I know C API will be go away. but now it is necessary. It need long time to change API.

NeoDreamer gravatar imageNeoDreamer ( 2019-05-23 01:36:11 -0600 )edit

the C-api is DEAD since 2010, you MUST NOT use that for any new code.

if you have to use C, look at how to wrap the c++ code like it is done in the java / python wrappers, just DON'T try to use IplImages.

I know C API will be go away.

again, it already happened, you're too late for this

berak gravatar imageberak ( 2019-05-23 01:43:04 -0600 )edit