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::CameraI mage = 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->Colu mn)/(cam_b in_mode+1) );
i_Height=((Attributes->Row )/(cam_bin _mode+1));
cam_bin_mode=Attributes->B in;
delete [] CallbackImageData::CameraI mage; // delete previous image (if any)
CallbackImageData::CameraI mage = 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::CameraI mage, 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
unsigned char* CallbackImageData::CameraI
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->Colu
i_Height=((Attributes->Row
cam_bin_mode=Attributes->B
delete [] CallbackImageData::CameraI
CallbackImageData::CameraI
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
cvSetData(NIRImage, CallbackImageData::CameraI
cvNamedWindow("Machine Vision", 1);
cvShowImage("Machine Vision", ImageEdges);
key = cvWaitKey(20);
//cleanup
cvReleaseImage(&ImageEdges
cvReleaseImage(&NIRImage);
} //end of Framecallback call
How can I fix the call so as to deallocate without error?
Thanks in advance,
WLE
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
\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::CameraI mage, 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 ?
iplDeallocate, not iplDeallocateImage :)
What you can also do, is after each of these lines :
NIRImage = cvCreateImageHeader(size, IPL_DEPTH_8U, 1);
cvInitImageHeader(NIRImage
cvSetData(NIRImage, CallbackImageData::CameraI
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 ?
ASKER
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\s rc\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,Callbac kImageData ::CameraIm age , i_Width*1);
ATImage = cvCreateImage(cvSize(i_Wid th,i_Heigh t), 8, 1); //Create Image
cvAdaptiveThreshold( NIRImage, ATImage, 50, CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY, 3, 5 );
CvContourScanner blobs = cvStartFindContours(ATImag e, 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 );
}
Unknown error code -9 (null pointer to header)
in function cvInitImageHeader, C:\User\VP\opencv\cxcore\s
Abort, retry etc.
I think its from this line:
cvInitImageHeader(NIRImage
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
cvSetData(NIRImage,Callbac
ATImage = cvCreateImage(cvSize(i_Wid
cvAdaptiveThreshold( NIRImage, ATImage, 50, CV_ADAPTIVE_THRESH_MEAN_C,
CvContourScanner blobs = cvStartFindContours(ATImag
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 ?
>> [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 ?
ASKER
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if (NIRImage) iplDeallocate(NIRImage, IPL_IMAGE_ALL);
and see if you get the same result.