11-20-2008 10:44 PM
Im rotating images of 1600x1200 size, after 20 runs it fails and memory corruption happens.
Help please.
Armando
Solved! Go to Solution.
11-21-2008 02:04 AM
Hi, Armando,
Also good idea to post a) Code example with illustration b) LabVIEW/Vision versions.
See attached code - image 1600x1200 rotated without memory corruption
Andrey.
11-21-2008 08:16 AM
Sorry.
Im using NIVision 71. with C++ in WinXP.
Im capturing images with a Lumenera Camera and after 20 images, imaqRotate2 returns and error, this error is
"Not enough memory to complete the operation"
Initialy with 1GB RAM was the error, but then added 2 GB, so I have 3GB total memory, and the error is the same. Im erasing the previous image on each cycle, and no memory leaks in the program.
The images when working correctly can be processed for pattern matching, etc, etc.(and they have 5.5 MB in size on Hard Disk)..but the one returned when the error, it has only 1Kb size on disk and is like a sinlge back point. I'll send the image failed as soon as arrive to work.
The memory needed to capture the image from the camera is unsigned char* with size 1600x1200 and get this memory with new. This buffer is erased on each cycle, so no memory leak. After the error, I cant get this memory to capture from the camera and a exception is thrown.
11-21-2008 08:16 AM
Here a piece of code
fCameraWidth = pFormat.width ; // The size is from a function in the camera = 1600
fCameraHeight= pFormat.height; //1200
try
{
pImageBuffer = new BYTE[iSize]; // buffer for image from cam. After the fail, it cant be assigned
pcFrameRgb = new BYTE[iSize * 4]; // buffer to conver image to RGB
if(pImageBuffer != NULL)
{
BOOL result=
LucamTakeFastFrame((void*)currentCamera,(BYTE*)pImageBuffer);// get
camera image
apiError = LucamGetLastError();
Sleep(1);
LUCAM_CONVERSION lcConversion;
lcConversion.CorrectionMatrix = LUCAM_CM_DAYLIGHT;
lcConversion.DemosaicMethod = LUCAM_DM_FAST;
imagendecamara = imaqCreateImage (IMAQ_IMAGE_RGB, 0); // create vision image
Image * temp_imagendecamara; // before this error was rotating with imagendecamara on both image* parametes,and tried to have another image
if(fcImageRotation != 0.0)
temp_imagendecamara = imaqCreateImage (IMAQ_IMAGE_RGB, 0); // create temporary image if needs to rotate
LucamConvertFrameToRgb32((void*)currentCamera, pcFrameRgb,
pImageBuffer,fCameraWidth, fCameraHeight, LUCAM_PF_8,
&lcConversion); //convert buffer to RGB
int error = imaqArrayToImage (temp_imagendecamara,pcFrameRgb,
fCameraWidth, fCameraHeight); // convert RGB to NI IMage
if(fcImageRotation != 0.0)
{
if(imaqRotate2 (imagendecamara, temp_imagendecamara, fcImageRotation,
valueForPixel, IMAQ_ZERO_ORDER, false) ==0) // Rotate
{
char * error_text = imaqGetErrorText(imaqGetLastError());
AnsiString texterror = error_text;
imaqDispose(error_text);
AnsiString lLastError = AnsiString(imaqGetLastErrorFunc());
lLastError = lLastError+": " + texterror; // The error is "Not enough memory ...."
Sleep(0);
}
imaqDispose(temp_imagendecamara); // free temporary image
}
}
}
__finally
{
if(pImageBuffer != NULL) // free buffers
{
delete []pImageBuffer;
pImageBuffer = NULL;
}
else
Sleep(0); // After fail and in the next cycle new throws an exception and the buffer is NULL, so the code entes here
if(pcFrameRgb != NULL)
{
delete []pcFrameRgb;
pcFrameRgb = NULL;
}
else
Sleep(0); // After fail and in the next cycle new throws an exception and the buffer is NULL, so the code entes here
}
11-21-2008 09:05 AM
11-21-2008 09:20 AM
I added code to save exactly before rotation and after rotation and the results show that imaqRotate2 is killing the memory.
Then I decided to use an obsolete imaqRotate function and it's working. But it cuts the image, since it has not the keep size parameter.
11-21-2008 09:35 AM
If you have images, which saved before rotation, then try to reproduce it with saved images, and if problem still present, then send bug report to NI or may be think about upgrade to Vision 8.6.1.
You using third party code for grabbing images. So, may be something written out of reserved memory, and this may cause such effect.
Andrey.
11-21-2008 09:53 AM
Armando -
It looks like you're never calling imaqDispose() on the image imagendecamara - try putting that in when you're done with it and see if that helps.
Greg Stoll
Vision R&D
National Instruments
11-21-2008 09:54 AM
11-21-2008 10:10 AM
I changed the imaqRotation2 for this code in order to keep image size, but wha are the chances the error comes out again?
int angle = 270;
hwRect rect;
if(angle == 180 || angle == 360)
{
imaqRotate (imagendecamara, imagendecamara, angle, valueForPixel, IMAQ_ZERO_ORDER);
}
if(angle == 90)
{
rect.top = 0;
rect.left= 0;
rect.width = fCameraWidth - (fCameraWidth-fCameraHeight);
rect.height= fCameraWidth;
imaqSetImageSize(imagendecamara, fCameraWidth,fCameraWidth);
imaqRotate (imagendecamara, imagendecamara, angle, valueForPixel, IMAQ_ZERO_ORDER);
imaqResample(imagendecamara,imagendecamara, fCameraHeight, fCameraWidth, IMAQ_ZERO_ORDER,rect);
}
if(angle == 270)
{
rect.top = 0;
rect.left= fCameraWidth-fCameraHeight;
rect.width = fCameraWidth - (fCameraWidth-fCameraHeight);
rect.height= fCameraWidth;
imaqSetImageSize(imagendecamara, fCameraWidth,fCameraWidth);
imaqRotate (imagendecamara, imagendecamara, angle, valueForPixel, IMAQ_ZERO_ORDER);
imaqResample(imagendecamara,imagendecamara, fCameraHeight, fCameraWidth, IMAQ_ZERO_ORDER,rect);
}
AnsiString imFileName = AnsiString("c:\\capture\\test") + num_img++ + ".bmp";
imaqWriteBMPFile (imagendecamara, imFileName.c_str(), true, NULL);