Link to home
Start Free TrialLog in
Avatar of Wanderinglazyeye
Wanderinglazyeye

asked on

de-allocation error

Hi folks, this question is a partial revisitation of an old problem I thought was solved.  I got my camera running with your suggestions but if I tried to deallocate one of my images with cvReleaseImage(&NIRImage) I would get an error. So what I did was ignore the deallocation (bad!) which didn't cause any immediate problems. In fact I was able to preview the video fine. But then when I started calling machine vision functions with NIR Image, it began to hang. So I am back to figuring out why I can't deallocate with the following code:

unsigned char* CallbackImageData::CameraImage = NULL;
                  void FrameCallBack( TProcessedDataProperty* Attributes, unsigned char* Frameptr )
                                    {
                                            int i_Width, i_Height, cam_bin_mode, key;
                                            int Time_Stamp_Now=0, Last_Time_Stamp=0, Frame_Interval=0,  Frame_Rate=0;
                                            i_Width=((Attributes->Column)/(cam_bin_mode+1));
                                            i_Height=((Attributes->Row)/(cam_bin_mode+1));
                                            cam_bin_mode=Attributes->Bin;
                                            delete [] CallbackImageData::CameraImage;  // delete previous image (if any)
                                            CallbackImageData::CameraImage = Framptr;
                                            IplImage* NIRImage = 0;
                                            IplImage* ImageEdges = 0;
                                                        // create an IplImage from the frame data provided
                                                        CvSize size = cvSize(i_Width, i_Height);
                                                        NIRImage = cvCreateImageHeader(size, IPL_DEPTH_8U, 1);
                                                        cvInitImageHeader(NIRImage, size, IPL_DEPTH_8U, 1, IPL_ORIGIN_TL);
                                                        cvSetData(NIRImage, CallbackImageData::CameraImage, i_Width*1);
cvNamedWindow("Machine Vision", 1);
                                                cvShowImage("Machine Vision", ImageEdges);
                                                key = cvWaitKey(20);
                                                //cleanup
                                                cvReleaseImage(&ImageEdges);
                                                cvReleaseImage(&NIRImage);<--------------ERROR HERE
} //end of Framecallback call

How can I fix the call so as to deallocate without  error?

Thanks in advance,

WLE

Avatar of Infinity08
Infinity08
Flag of Belgium image

Try this instead :

        if (NIRImage) iplDeallocate(NIRImage, IPL_IMAGE_ALL);

and see if you get the same result.
SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Wanderinglazyeye
Wanderinglazyeye

ASKER

Well, it doesn't know the deallocation command - although I have seen it used:
\MachineVisionMod.cpp [Error C3861] 'iplDeallocateImage': identifier not found

Here is the actual error I get with the cvReleaseImage command:
OpenCV Error: Unknown error code -49
> in function [cvalloc.cpp:147]:cvFree():

Here is a thread where someone encountered the same thing:
http://tech.groups.yahoo.com/group/OpenCV/message/9369

When I use cvCanny and it hangs, I can't be sure its not really this original deallocation problem...Since it was never really fixed. I would at least like to rule out this by fixing it.
Um, a "Please sign in to Yahoo" does not really help here ;o)
>> \MachineVisionMod.cpp [Error C3861] 'iplDeallocateImage': identifier not found

iplDeallocate, not iplDeallocateImage :)


What you can also do, is after each of these lines :

               NIRImage = cvCreateImageHeader(size, IPL_DEPTH_8U, 1);
               cvInitImageHeader(NIRImage, size, IPL_DEPTH_8U, 1, IPL_ORIGIN_TL);
               cvSetData(NIRImage, CallbackImageData::CameraImage, i_Width*1);

check whether the NIRImage structure is still ok. (check return values, error codes, as well as the contents of the NIRImage structure)



And one other thing : are you sure that this line is ok :

        cvShowImage("Machine Vision", ImageEdges);

because ImageEdges is NULL when you call it ... :

        IplImage* ImageEdges = 0;

Also, with this line :

        cvReleaseImage(&ImageEdges);

aren't you trying to release a NULL pointer ?
Some how between then and today, the error changed: I am  left with this error:

Unknown error code -9 (null pointer to header)
in function cvInitImageHeader, C:\User\VP\opencv\cxcore\src\cxarray.cpp(3353)
Abort, retry etc.

I think its from this line:
            cvInitImageHeader(NIRImage, size, IPL_DEPTH_8U, 1, IPL_ORIGIN_TL);

It previews fine if I comment out the releaseimage stuff...but, I get a memory leak.
                     
I tried the iplDeallocate(&NIRIMage), i still get this error:
[Error C3861] 'iplDeallocate': identifier not found...:(

Here is the whole code (modded from above - sorry about being a moving target ):

void FrameCallBack( TProcessedDataProperty* Attributes, unsigned char* Frameptr )
                                    {
                                            ...
                                                IplImage* NIRImage = 0;
                                                IplImage* ATImage = 0;
                                                CvMemStorage* storage = cvCreateMemStorage(0);
                                                CvSeq* contours = 0;
                                                // create an IplImage from the frame data provided
                                                CvSize size = cvSize(i_Width, i_Height);
                                                NIRImage = cvCreateImageHeader(size, IPL_DEPTH_8U, 1);    
 error refers  here  ------------>  cvInitImageHeader(NIRImage, size, IPL_DEPTH_8U, 1, IPL_ORIGIN_TL);
                                                cvSetData(NIRImage,CallbackImageData::CameraImage , i_Width*1);
                                                ATImage = cvCreateImage(cvSize(i_Width,i_Height), 8, 1); //Create Image
                                                cvAdaptiveThreshold( NIRImage, ATImage, 50, CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY, 3, 5 );
                                                CvContourScanner blobs = cvStartFindContours(ATImage, storage,sizeof(CvContour), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );
                                               contours = cvFindNextContour(blobs);
                                               contours = cvEndFindContours( &blobs );
                                               cvNamedWindow("Machine Vision", 1);
                                               cvShowImage("Machine Vision", NIRImage);
                                                key = cvWaitKey(20);
                                               
                                                //cleanup
  Occurs here---------------->  cvReleaseImage(&NIRImage);
                                    cvReleaseImage(&ATImage);
                                            cvReleaseMemStorage( &storage );
                                    }
>> I tried the iplDeallocate(&NIRIMage), i still get this error:
>> [Error C3861] 'iplDeallocate': identifier not found...:(

Never mind then - it was a long shot anyway.


>> Unknown error code -9 (null pointer to header)

Can you check whether the cvCreateImageHeader(size, IPL_DEPTH_8U, 1); call did its work correctly ?


Also, isn't it better to use cvSetImageData instead of cvSetData ?
I've switched to cvSetImageData, still same error.

Not to sure how to check whether cvCreateImageHeader is calling correctly...but it appears that is from where the error is being generated.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial