Fast screen captures for real-time processing
조회 수: 14 (최근 30일)
이전 댓글 표시
I'm writing an automated UI test suite using Matlab and the Java Robot class (called from Matlab). The basic control flow is this loop:
1)take a screenshot of the Direct X application using Robot
2)do some processing using Matlab
3)programmatically press some keys using Robot
I require fast and consistent timing for these steps (steps 1-3 to occur every 200ms ideally). Steps 2 and 3 are fine but, the screenshot is too slow, inconsistent and machine dependent (My laptop takes 200-500ms for screen capture and my desktop faster but still far beneath my ideal).
Are there any Matlab/Simulink packages that would allow more rapid and consistent timing of screenshots?
I've considered the Simulink Real-Time Windows Target, but I can't figure out if taking a screenshot is a valid form of input in simulink (and this seems like overkill).
I've also looked into the image acquisition toolbox, in order to use that to take the screen shots, but its unclear if it offers that functionality (it deals mainly with hardware image capturing devices).
Here's the screenshot code I've used for timing purposes:
import java.io.*;
import java.awt.*;
robot = Robot;
tool = Toolkit.getDefaultToolkit();
for n = 1:100
tic
img = robot.createScreenCapture(Rectangle(tool.getScreenSize()));
pic = java_img2mat(img);
screen = rgb2gray(pic);
screen = screen(1:end-100,:);
t(n) = toc;
end
And the function used to convert a java image into a Matlab usable form:
function image = java_img2mat(javaimg)
import java.io.*;
import java.awt.*;
H = javaimg.getHeight;
W = javaimg.getWidth;
% repackage as a 3D array (MATLAB image format)
image = uint8(zeros([H,W,3]));
pixelsData = uint8(javaimg.getData.getPixels(0,0,W,H,[]));
for i = 1 : H
base = (i-1)*W*3+1;
image(i,1:W,:) = deal(reshape(pixelsData(base:(base+3*W-1)),3,W)');
end
end
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!