C API problem on OpenCV 3.4.6. [closed]
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?
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 << I know C API will be go away. but now it is necessary. It need long time to change API.
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.
again, it already happened, you're too late for this