how to capture certain area of screen
8 views (last 30 days)
Show older comments
This is a matlab screen capture program that captures whole screen every one second and saves capture screen to a folder. I need to modify it to capture certain rectangular area of screen instead of all screen. Also i need to apply image processing on captured frames in real time i.e. immediately after they are captured. Please help.
%press (ctrl+break) to stop your program from capturing screen
i=1;
while true
robo = java.awt.Robot;
t = java.awt.Toolkit.getDefaultToolkit();
%# Set the capture area as the size for the screen
rectangle = java.awt.Rectangle(t.getScreenSize());
%# Get the capture
image = robo.createScreenCapture(rectangle);
%# Save it to file
filehandle = java.io.File(sprintf('capture%d.jpg', i));
javax.imageio.ImageIO.write(image,'jpg',filehandle);
pause(300) %# Wait for 5 min
i = i + 1;
end
0 Comments
Answers (3)
sandeep
on 26 Nov 2014
4 Comments
Sean de Wolski
on 26 Nov 2014
doc timer
Set the timerfcn up to call screencapture and do whatever processing needs to be done.
Image Analyst
on 26 Nov 2014
Don't use image as the name of your variable since it's the name of a built-in function. Try this
screenImage = robo.createScreenCapture(rectangle);
subImage = screenImage(row1:row2, col1:col2,:); % Crop it.
Then do your save on subImage.
2 Comments
Image Analyst
on 26 Nov 2014
sandeep's reply moved here since it's not an answer to the original question, but a reply to me:
@ Image analyst, I get the meaning of first line in your code. But what kind of cropping will be done by second line. The code i posted captures full screen every 300 seconds and saves capture screen to a folder. I need to modify it to capture certain rectangular area on screen.... and then send the captures frames to image processing algorithm. Please help me here.
Image Analyst
on 26 Nov 2014
The second line of code takes a 3D image - a color image - and extracts out a sub image (that is also color) into its own variable called subImage. The rest of your code with looping and saving can stay the same, except for the write line where you want to write this subImage to disk, instead of the whole screen image.
See Also
Categories
Find more on Interactive Control and Callbacks 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!