Function MouseControl
Function MouseControl
warning('off','vision:transition:usesOldCoordinates');
%% Initialization
if nargin < 1
redThresh = 0.22; % Threshold for Red color detection
greenThresh = 0.14; % Threshold for green color detection
blueThresh = 0.18; % Threshold for blue color detection
numFrame = 300; % Total number of frames duration
end
jRobot.mouseMove(1.5*centroidRed(:,1)*screenSize(3)/vidInfo.MaxWidth,
1.5*centroidRed(:,2)*screenSize(4)/vidInfo.MaxHeight);
end
if ~isempty(bboxBlue(:,1)) % Left Click, Right Click, Double Click
routine
if length(bboxBlue(:,1)) == 1 % Left Click routine
lCount = lCount + 1;
if lCount == sureEvent % Make sure of the left click event
jRobot.mousePress(16);
pause(0.1);
jRobot.mouseRelease(16);
end
elseif length(bboxBlue(:,1)) == 2 % Right Click routine
rCount = rCount + 1;
if rCount == sureEvent % Make sure of the right click event
jRobot.mousePress(4);
pause(0.1);
jRobot.mouseRelease(4);
end
elseif length(bboxBlue(:,1)) == 3 % Double Click routine
dCount = dCount + 1;
if dCount == sureEvent % Make sure of the double click event
jRobot.mousePress(16);
pause(0.1);
jRobot.mouseRelease(16);
pause(0.2);
jRobot.mousePress(16);
pause(0.1);
jRobot.mouseRelease(16);
end
end
else
lCount = 0; rCount = 0; dCount = 0; % Reset the sureEvent counter
end
if ~isempty(bboxGreen(:,1)) % Scroll event routine
if (mean(centroidGreen(:,2)) - iPos) < -2
jRobot.mouseWheel(-1);
elseif (mean(centroidGreen(:,2)) - iPos) > 2
jRobot.mouseWheel(1);
end
iPos = mean(centroidGreen(:,2));
end
vidIn = step(hshapeinsBox, rgbFrame, bboxRed,single([1 0 0])); % Show
the red objects in output stream
vidIn = step(hshapeinsBox, vidIn, bboxGreen,single([0 1 0])); % Show
the green objects in output stream
vidIn = step(hshapeinsBox, vidIn, bboxBlue,single([0 0 1])); % Show the
blue objects in output stream
step(hVideoIn, vidIn); % Output video stream
nFrame = nFrame+1;
end
%% Clearing Memory
release(hVideoIn); % Release all memory and buffer used
release(vidDevice);
clc;
end