使用java机器人类通过颜色检测方法控制鼠标.... [英] mouse control by color detection methods using java robot class....

查看:145
本文介绍了使用java机器人类通过颜色检测方法控制鼠标....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用代码检测颜色,我只能使用imsubtract(data(:,,1),rgb2grey(data))命令检测红色,绿色或蓝色...然后我应用了robaot java类鼠标指针移动相对于颜色的坐标....鼠标指针移动,也点击,但我遇到的问题是..... 1)我不知道点击操作是如何执行....当指针在文件夹上稳定一段指定时间或系统检测到另一种颜色时执行?...... 2)如果我向右移动指针,指针向左移动,反之亦然....如何反转....... 3)如果相机分辨率低于屏幕的分辨率,整个屏幕都没有覆盖这个系统....如何消除这个?..... 4 )如果我想检测两种不同的颜色并通过操纵颜色之间的距离来执行点击操作,我该怎么做呢?请帮忙...

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...

推荐答案

%使用videoinput功能捕获视频帧

%你必须替换分辨率和安装的适配器名称。

vid = videoinput(''winvideo'',1,''RGB24_640x480'');



%设置视频的属性对象

set(vid,''FramesPerTrigger'',Inf);

set(vid,''ReturnedColorspace'',''rgb'')

vid.FrameGrabInterval = 5;



%在这里开始视频采集

start(vid)



%设置一个在100帧采集后停止的循环

while(vid.FramesAcquired< = 20000)



%获取当前帧的快照

data = getsnapshot(VID);



%现在实时跟踪红色物体

%我们必须减去红色成分

%从灰度图像中提取图像中的红色成分。

diff_im = imsubtract(data(:,:,1),rgb2gray(data));

%使用中值滤波器滤除噪音

diff_im = medfilt2(diff_im,[3 3]);

%将生成的灰度图像转换为二进制图像。

diff_im = im2bw(diff_im,0.18);



%删除所有小于300像素的像素

diff_im = bwareaopen(diff_im,300);



%标记图像中所有连接的组件。

bw = bwlabel(diff_im,8);



%这里我们进行图像blob分析。

%我们为每个标记区域获取一组属性。

stats = regionprops(bw,''BoundingBox'',''Centroid'');



%显示图片

imshow(数据)



持有



%这是一个用于绑定矩形框中红色对象的循环。

for object = 1:length(stats)

bb = stats(object).BoundingBox;

bc = stats(object).Centroid;

矩形(''位置'',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'', ''黄色'');

import java.awt.Robot;

import java.awt.event。*;

mouse =机器人;

mouse.mouseMove(bc(1),bc(2));

mouse.mousePress(InputEvent.BUTTON2_MASK);

mouse.mouseRelease(InputEvent.BUTTON2_MASK);

结束



延期

结束
% 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


这篇关于使用java机器人类通过颜色检测方法控制鼠标....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆