开发者

does cvrelease delete the allocated memory?

开发者 https://www.devze.com 2023-01-22 20:05 出处:网络
This might be the wrong way of doing things, but I pass an array from LabView into my C++ function as a simple array of char. I then create an OpenCV image and point the pointer to my data that was pa

This might be the wrong way of doing things, but I pass an array from LabView into my C++ function as a simple array of char. I then create an OpenCV image and point the pointer to my data that was passed. At the end of the function I use cvReleaseImage to delete all the OpenCV images, would that remove the data off my original pointer?

also, Would there be a better way of performing an in-place operation which modifies the original image?

EXPORT void smoothImg(uchar * the_img, int size_x, int size_y)
{
 CvSize size;
 size.height = size_y ;
 size.width = size_x;

 IplImage * img1 = cvCreateImageHeader(size, IPL_DEPTH_8U, 1);
 img1->imageData = (char *)the_img;
 img1->imageDataOrigin = img1->imageData;

 IplImage * img2 = cvCreateImage(size, IPL_DEPTH_8U, 1);
// this is because I want my end result to be in img1 (same data as my the_img
 memcpy(img2->imageData,img1-开发者_如何转开发>imageData,sizeof(char)*size_x*size_y);

 cvSmooth(img2,img1,CV_BLUR, 5,5);

 cvReleaseImage(&img1 );
 cvReleaseImage(&img2 );

}

Note: it doesnt seem to affect my images as the results are correct, but I want to make sure this is right before I put it everywhere

Thanks!


cvRelease deallocates the memory used by the image, so after calling it you can no longer reference that image.

BUT - the memory may not be available for other programs until openCV exists, it's system dependant how it handles memory, and indeed when the system returns free'ed memory for other apps.

edit: Sorry I didn't really answer what you asked. There is a flag you can pass to cvCreateImage() to say - I own the memory, don't delete it. The flag depends slightly on which version of opencv you have


I actually found a pretty interesting article on memory allocation/deallocation for OpenCV, i guess this means I should have used cvReleaseImageHeader as I was only trying to remove the header.

http://www.andol.info/hci/963.htm

0

精彩评论

暂无评论...
验证码 换一张
取 消