how to capture certain area of screen

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

답변 (3개)

sandeep
sandeep 2014년 11월 26일

0 개 추천

The code you are referring to takes only one screen shot. I need a code that can capture certain area of screen continuously lets say fro one mniute and then stop.

댓글 수: 4

Sean de Wolski
Sean de Wolski 2014년 11월 26일
Okay, then call that function multiple times in a for-loop or even better with a timer.
sandeep
sandeep 2014년 11월 26일
How with a timer, i am new to matlab.
doc timer
Set the timerfcn up to call screencapture and do whatever processing needs to be done.
sandeep
sandeep 2014년 11월 26일
Can u edit the code that i posted above so that it captures a certain area.

댓글을 달려면 로그인하십시오.

Image Analyst
Image Analyst 2014년 11월 26일

0 개 추천

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

Image Analyst
Image Analyst 2014년 11월 26일
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
Image Analyst 2014년 11월 26일
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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Images에 대해 자세히 알아보기

질문:

2014년 11월 26일

댓글:

2014년 11월 26일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by