How do I move the mouse
    11 ビュー (過去 30 日間)
  
       古いコメントを表示
    
I have this code for iris detection now I need to make the mouse move using the center of the circle around the iris,how do i do that?
code:
cam=webcam();   %create webcam object
detector = vision.CascadeObjectDetector(); % Create a detector for face using Viola-Jones
detector1 = vision.CascadeObjectDetector('EyePairSmall'); %create detector for eyepair
while true % Infinite loop to continuously detect the face
      vid=snapshot(cam);  %get a snapshot of webcam
      vid = rgb2gray(vid);    %convert to grayscale
      img = flip(vid, 2); % Flips the image horizontally
       bbox = step(detector, img); % Creating bounding box using detector  
       if ~ isempty(bbox)  %if face exists 
           biggest_box=1;     
           for i=1:rank(bbox) %find the biggest face
               if bbox(i,3)>bbox(biggest_box,3)
                   biggest_box=i;
               end
           end
           faceImage = imcrop(img,bbox(biggest_box,:)); % extract the face from the image
           bboxeyes = step(detector1, faceImage); % locations of the eyepair using detector
           subplot(2,2,1),imshow(img); hold on; % Displays full image
           for i=1:size(bbox,1)    %draw all the regions that contain face
               rectangle('position', bbox(i, :), 'lineWidth', 2, 'edgeColor', 'y');
           end
           subplot(2,2,3),imshow(faceImage);     %display face image
           if ~ isempty(bboxeyes)  %check it eyepair is available
               biggest_box_eyes=1;     
               for i=1:rank(bboxeyes) %find the biggest eyepair
                   if bboxeyes(i,3)>bboxeyes(biggest_box_eyes,3)
                       biggest_box_eyes=i;
                   end
               end
               bboxeyeshalf=[bboxeyes(biggest_box_eyes,1),bboxeyes(biggest_box_eyes,2),bboxeyes(biggest_box_eyes,3)/3,bboxeyes(biggest_box_eyes,4)];   %resize the eyepair width in half
               eyesImage = imcrop(faceImage,bboxeyeshalf(1,:));    %extract the half eyepair from the face image
               eyesImage = imadjust(eyesImage);    %adjust contrast
               r = bboxeyeshalf(1,4)/4;
               [centers, radii, metric] = imfindcircles(eyesImage, [floor(r-r/4) floor(r+r/2)], 'ObjectPolarity','dark', 'Sensitivity', 0.93); % Hough Transform
               [M,I] = sort(radii, 'descend');
       eyesPositions = centers;
             subplot(2,2,2),imshow(eyesImage); hold on;
             viscircles(centers, radii,'EdgeColor','b');
               end          
  end
0 件のコメント
回答 (1 件)
  Walter Roberson
      
      
 2018 年 6 月 9 日
        Use the Java Robot class to move the mouse cursor. See https://www.mathworks.com/matlabcentral/answers/100545-how-can-i-programmatically-control-mouse-motion-and-clicks-with-matlab
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

