How to detect laser movement like, moving from top to bottom
8 views (last 30 days)
Show older comments
I am done with tracking the laser and moving the mouse pointer to the centroid of the laser.Now I want to recognize the laser gesture/movement like, top to bottom and from bottom to top. if the event is from top to bottom do scroll down by calling java.awt.event function cursor.mouseWheel(+1). I have used some other methods,but not working properly.
clc;
clear all;
close all;
greenThresh = 0.04; % Threshold for green detection
x1=[];
y1=[];
count=0;
vidDevice = imaq.VideoDevice('winvideo', 1, 'YUY2_640x480', ...
'ROI', [1 1 640 480], ...
'ReturnedColorSpace', 'rgb');
%set(vidDevice.DeviceProperties, 'Brightness', 0);
set(vidDevice.DeviceProperties, 'Exposure', -8);
set(vidDevice.DeviceProperties, 'FrameRate', '30.0000');
set(vidDevice.DeviceProperties, 'Sharpness', 100);
set(vidDevice.DeviceProperties, 'Zoom',1);
vidInfo = imaqhwinfo(vidDevice);
hblob = vision.BlobAnalysis('AreaOutputPort', false, ...
'CentroidOutputPort', true, ...
'BoundingBoxOutputPort', true', ...
'MinimumBlobArea', 600, ...
'MaximumBlobArea', 3000, ...
'MaximumCount', 10);
hshapeinsBox = vision.ShapeInserter('BorderColorSource', 'Input port', ... % box handling
'Fill', true, ...
'FillColorSource', 'Input port', ...
'Opacity', 0.2);
htextinsCent = vision.TextInserter('Text', '+ X:%d,Y:%d', ... % text for centroid
'LocationSource', 'Input port', ...
'Color', [1 1 1], ...
'Font', 'Courier New', ...
'FontSize', 15);
hVideoIn = vision.VideoPlayer('Name', 'Final Video', ... % video player
'Position', [400 100 vidInfo.MaxWidth+20 vidInfo.MaxHeight+30]);
%nFrame = 0;
import java.awt.Robot;
import java.awt.event.*;
cursor = Robot;
while(1)
rgbFrame = step(vidDevice);
diffFrameGreen = imsubtract(rgbFrame(:,:,2), rgb2gray(rgbFrame)); % Get green component of the image
diffFrameGreen = medfilt2(diffFrameGreen, [3 3]); % Filter out the noise by using median filter
binFrameGreen = im2bw(diffFrameGreen, greenThresh); % Convert the image into binary image with the green objects as white
binFrameGreen = bwareaopen(binFrameGreen,1000);
[centroidGreen, bboxGreen] = step(hblob, binFrameGreen); % Get the centroids and bounding boxes of the green blobs
centroidGreen = uint16(centroidGreen); % Convert the centroids into Integer for further steps
vidIn = step(hshapeinsBox, rgbFrame, bboxGreen, single([0 1 0])); % Insert the green box
for object = 1:1:length(bboxGreen(:,1)) % Write the corresponding centroids for green
centXGreen = centroidGreen(object,1);
centYGreen = centroidGreen(object,2);
x1=cat(1,x1,centXGreen);
y1=cat(1,y1,centYGreen);
vidIn = step(htextinsCent, vidIn, [centXGreen centYGreen], [centXGreen-6 centYGreen-9]);
cursor.mouseMove(2.14*centXGreen,1.6*centYGreen);
end
% if(centYGreen>300)
% if(y1>250)
% display('Scroll up');
%
% %cursor.mouseWheel(-1);
% end
% end
% if(x==1)
%
% if(centXGreen>580&¢YGreen>420)
%
% count=count+1;
%
% if(count>20)
%
% display('Scroll down');
% cursor.mouseWheel(+1);
% pause(1);
% count=0;
% end
%
% end
%
% if(centXGreen>580&¢YGreen<50)
%
% count=count+1;
%
% if(count>20)
%
% display('Scroll up');
% cursor.mouseWheel(-1);
% pause(1);
% count=0;
% end
%
% end
%
%
% else
%
% count=count+1;
%
% if (count>50)
%
% %FlagClick=0;
% display('double click');
% cursor.mousePress(InputEvent.BUTTON1_MASK);
% %cursor.delay(0.1);
% cursor.mouseRelease(InputEvent.BUTTON1_MASK);
% %cursor.delay(0.5);
% cursor.mousePress(InputEvent.BUTTON1_MASK);
% %cursor.delay(0.1);
% cursor.mouseRelease(InputEvent.BUTTON1_MASK);
% count=0;
%
% end
%cursor.mouseWheel(+1);
%end
% end
% if(y1>250)
% display('Scroll down');
%
% %cursor.mouseWheel(+1);
% end
% end
step(hVideoIn, vidIn); % Output video stream
%nFrame = nFrame+1;
end
release(hVideoIn);
release(vidDevice);
0 Comments
Answers (0)
See Also
Categories
Find more on Tracking and Motion Estimation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!