I run the code shown below to take screen shot of the current screen. Monitor resolution is 1920*1080. I am storing the screen capture as an image named imgdata. Suppose if I detect a particular item from the image (say a folder, based on its color), i am able to get its centroid. How to convert these coordinates of centroid to screen coordinates?
% Take screen capture
robot = java.awt.Robot();pos = [0 0 1920 1080]; % [left top width height]
rect = java.awt.Rectangle(pos(1),pos(2),pos(3),pos(4));cap = robot.createScreenCapture(rect);% Convert to an RGB image
rgb = typecast(cap.getRGB(0,0,cap.getWidth,cap.getHeight,[],0,cap.getWidth),'uint8');imgData = zeros(cap.getHeight,cap.getWidth,3,'uint8');imgData(:,:,1) = reshape(rgb(3:4:end),cap.getWidth,[])';imgData(:,:,2) = reshape(rgb(2:4:end),cap.getWidth,[])';imgData(:,:,3) = reshape(rgb(1:4:end),cap.getWidth,[])';
Best Answer