Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java Robot ImageProcessing , +
i used a code to detect color where i can only detec red,green or blue color using "imsubtract(data(:,:,1),rgb2grey(data))" command... then i applied robaot java class for mouse pointer movement relative to cordinates of the color.... the mouse pointer moves and also clicks, but the problems i faced are..... 1) i dont know how the clicking operation is being executed.... does it executes when pointer is stable on a folder for some specified time or when another color is detected by the system?...... 2) if i move my hand to right , the pointer moves left and vice versa..... how to reverse that....... 3)if the camera resolution is less than the resolution of the screen, whole screen is not covered with this system.... how to eliminate this?..... 4)if i want to detect two different colors and execute clicking operations by manipulating the distance between the colors, how can i do that..?? please help...
Posted 21-Feb-13 6:12am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

% Capture the video frames using the videoinput function
% You have to replace the resolution & your installed adaptor name.
vid = videoinput('winvideo',1,'RGB24_640x480');
 
% Set the properties of the video object
set(vid, 'FramesPerTrigger', Inf);
set(vid, 'ReturnedColorspace', 'rgb')
vid.FrameGrabInterval = 5;
 
%start the video aquisition here
start(vid)
 
% Set a loop that stop after 100 frames of aquisition
while(vid.FramesAcquired<=20000)
 
% Get the snapshot of the current frame
data = getsnapshot(vid);
 
% Now to track red objects in real time
% we have to subtract the red component
% from the grayscale image to extract the red components in the image.
diff_im = imsubtract(data(:,:,1), rgb2gray(data));
%Use a median filter to filter out noise
diff_im = medfilt2(diff_im, [3 3]);
% Convert the resulting grayscale image into a binary image.
diff_im = im2bw(diff_im,0.18);
 
% Remove all those pixels less than 300px
diff_im = bwareaopen(diff_im,300);
 
% Label all the connected components in the image.
bw = bwlabel(diff_im, 8);
 
% Here we do the image blob analysis.
% We get a set of properties for each labeled region.
stats = regionprops(bw, 'BoundingBox', 'Centroid');
 
% Display the image
imshow(data)
 
hold on
 
%This is a loop to bound the red objects in a rectangular box.
for object = 1:length(stats)
bb = stats(object).BoundingBox;
bc = stats(object).Centroid;
rectangle('Position',bb,'EdgeColor','r','LineWidth',2)
plot(bc(1),bc(2), '-m+')
a=text(bc(1)+15,bc(2), strcat('X: ', num2str(round(bc(1))), ' Y: ', num2str(round(bc(2)))));
set(a, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'yellow');
import java.awt.Robot;
import java.awt.event.*;
mouse = Robot;
mouse.mouseMove(bc(1), bc(2));
mouse.mousePress(InputEvent.BUTTON2_MASK);
mouse.mouseRelease(InputEvent.BUTTON2_MASK);
end
 
hold off
end
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 390
1 Jochen Arndt 150
2 Richard MacCutchan 135
3 DamithSL 95
4 Garth J Lancaster 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,260


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 21 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100