Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

What is the best way to capture RGB8 image to memory for later write to disk?

HI-

I have been using the code below for some time now but wonder if an expert can take a look and let me kown if there are ways to improve it.  Problem I run into is that I preallocate the memory beforehand (camera.buffering[]), and with a 5 MP camera, this takes up a lot of RAM.  It seems like when I am running this program in debug mode all day and constantly start/stop it without allowing it to free the memory gracefully, i eventually bog the system and start getting Out of Memory error -12, in other places in my code such as DisplayBitmap or GetBitmapfrom File.  Is this all related to how much memory I am trying to allocate prior to begining the camera capture routine below?  Am I not allocating and free-ing it properly?

 

Code is below for how I grab the image and then send to memory usign memcpy.  Is there a better, more efficient or faster method?  I have removed error checking/etc from code below simply to save space. This operates at 15 fps.   

 

I also included my allocation and free-ing code, too. 

 

Thanks in advance.

Blue

 

//caemra capture loop//

camera.dxerror = IMAQdxGrab (camera.session, camera.image, 1, &camera.bufNum);          

stat = imaqRotate2 (rotateimage, camera.image, camera.rotate_image, pixval, IMAQ_BILINEAR, TRUE);    

stat = imaqScale (scaledimage, rotateimage, 4, 4, IMAQ_SCALE_SMALLER,IMAQ_NO_RECT);          

stat = imaqGetImageInfo(camera.image,&camera.info);

stat = imaqDisplayImage (scaledimage, 0, FALSE);         

memcpy (camera.buffering[camera.count], camera.info.imageStart, camera.info.pixelsPerLine*camera.CAMY*camera.bytesperpixel);   

 

 

//memory allocation code//

 camera.buffering = (int **)malloc(camera.maxcount*sizeof(int*));
 for(i=0;i<camera.maxcount;i++)

{

      camera.buffering[i] = (int *)malloc(camera.info.pixelsPerLine*camera.CAMY*camera.bytesperpixel); 

}

 

 

 

// free allocated memory code//

 for(x=0;x<camera.maxcount;x++)

 {

         free(camera.buffering[x]);

}
free(camera.buffering);

0 Kudos
Message 1 of 2
(4,191 Views)

How many images are you storing in RAM?  Typically when I need to work with tens, hundreds, or even thousands of images, I save them to the hard drive after I capture them as a PNG with 1000 quality.  Sometimes I process them before saving, sometimes I process them offline from the saved images depending on the application.  If you don't need all of the images simultaneously in memory at once, just save them to PNG.  If you only process one image at a time, only allocate enough memory for the processing you need to perform on a single image.

0 Kudos
Message 2 of 2
(4,181 Views)