Pixel Values from the Computer Screen

조회 수: 5 (최근 30일)
Bugrahan Guner
Bugrahan Guner 2021년 12월 22일
댓글: Voss 2021년 12월 22일
Hi,
I am trying to track the change of specific pixels on my computer screen, which are going to indicate the feedback on/off position, by providing a green light, for another application. Is it possible to track the pixel values for directly the pixels on the main computer screen by using MATLAB ? Overall, I am trying to write a code which will alert me if the feedback is closed and the light is switched off. I would appreciate if there is a solution by using MATLAB but I am open for other solution methods as well.
  댓글 수: 1
Voss
Voss 2021년 12월 22일
The way I would first try to approach this problem would be (1) to programmatically take a screenshot and then (2) check the resulting image for the existence of the green light in the specific location. Part 2 is specific to your requirements, but a couple of ways you might try to do part 1 are:
(A) use a java.awt.Robot (from within MATLAB), which has a method createScreenCapture for capturing a screenshot. Here is how I have used it in the past:
r = java.awt.Robot();
monitor_positions = get(groot(),'MonitorPositions');
monitor_positions(:,1) = monitor_positions(:,1)-1;
monitor_positions(:,2) = 0;
pos = monitor_positions(1,:);
cap = r.createScreenCapture(java.awt.Rectangle(pos(1),pos(2),pos(3),pos(4)));
w = cap.getWidth();
h = cap.getHeight();
rgb = typecast(cap.getRGB(0,0,w,h,[],0,w),'uint8');
rgb = cat(3,reshape(rgb(3:4:end),w,[]).',reshape(rgb(2:4:end),w,[]).',reshape(rgb(1:4:end),w,[]).');
This will give you rgb, a 3d matrix of type uint8 representing a screenshot of the 1st monitor (i.e., the monitor whose screen position is given by the first row of get(groot(),'MonitorPositions')).
(The systems I use this on only ever have one monitor, and on the mulitple-monitor system I'm using now, it gives some incomplete/incorrect result. But I'll leave it here as a reference/starting off point for you to try to adapt it to work on your system.)
(B) Look into MATLAB's ScreenshotDiagnostic class. I haven't used it.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by