views:

30

answers:

1

Hello.

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!

+3  A: 

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

Martin Beckett