Need help to resolve error related to physical memory
    5 views (last 30 days)
  
       Show older comments
    
Hello guys,
Hope you all are doing great. I am facing an error when I run the following code in Matlab. There is only one drive on my computer "c" and there is enough memory (more than 300gb) in it. Earlier matlab was not giving this error, but I don't understand why it is giving this error now. 
Can anyone please help me to resolve this error. I would be thankful to you. 
Here are my script 
outdir = 'C:\Users\newfolder';
outprefix1 = "pic1_";  %string, not character vector!
img_suffix = ".tiff";
vid1 = videoinput('gentl', 1, 'Mono8');
src1 = getselectedsource(vid1);
vid1.FramesPerTrigger = 10;
vid1.ROIPosition = [2462 1092 415 1553];
vidlist = [vid1];
start(vidlist);
filename = 'C:\usuarios\abc_Graphs.xls';
framecount = 0;
counter=0;
while true
 framecount = 1 + framecount ;
 counter = counter +1;
  pause(1800);      %After every 900sec
  img=getdata(vid1);
   for i = 1:10
       outname1 = fullfile(outdir, outprefix1 + counter + "_" + i + img_suffix);
       imwrite(img(:,:,:,i), outname1);
   end
  start(vidlist);
     if isfile(filename)
      break
      end
end
stop(vidlist);
Also, here are the error that I got while running this script
>> tencontinuousshot_code
Warning: The ROIPosition property was modified by the device.
Error event occurred at 14:14:34 for video input object: Mono8-gentl-1.
Unable to allocate memory for an incoming image frame due to insufficient free physical memory.
Unable to allocate memory for an incoming image frame due to insufficient free physical memory.
Error in tencontinuousshot_code (line 18)
  pause(1800);      %After every 900se
4 Comments
  Walter Roberson
      
      
 on 31 May 2023
				Do the imaqmex('feature','-limitPhysicalMemoryUsage',false); once at the beginning, not within the loop.
I would suggest that you consider using backgroundPool or (if necessary) parpool and parfeval or parfeval . You would read the data in the main worker, and use parfeval() to queue writing to the disk. You might not gain any peformance past 3-ish simultaneous writers to the same drive, but it is typically possible to improve performance by spreading the work out to drives that are on different controllers. 
Answers (1)
  Diwakar Diwakar
      
 on 30 May 2023
        This code seems to be capturing video frames using a video input device and saving them as individual images.
The error message shows that your system does not have enough free physical memory to allocate for incoming image frames. This could be due to various reasons, such as running multiple memory-intensive processes or having limited RAM. To resolve this issue, you can try closing other applications or processes consuming a significant amount of memory to free up resources.
and your code:
outdir = 'C:\Users\newfolder';
outprefix1 = "pic1_";  % string, not character vector!
img_suffix = ".tiff";
vid1 = videoinput('gentl', 1, 'Mono8');
src1 = getselectedsource(vid1);
vid1.FramesPerTrigger = 10;
vid1.ROIPosition = [2462 1092 415 1553];
vidlist = [vid1];
start(vidlist);
filename = 'C:\usuarios\abc_Graphs.xls';
framecount = 0;
counter = 0;
while true
    framecount = framecount + 1;
    counter = counter + 1;
    pause(1800);  % After every 900 sec
    img = getdata(vid1);
    for i = 1:10
        outname1 = fullfile(outdir, outprefix1 + string(counter) + "_" + string(i) + img_suffix);
        imwrite(img(:, :, :, i), outname1);
    end
    start(vidlist);
    if isfile(filename)
        break;
    end
end
stop(vidlist);
0 Comments
See Also
Categories
				Find more on Introduction to Installation and Licensing in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


