title: How can I implement mouse pointer movement with eye tracking in openCV & Python?
body: <p>I am fairly new to Python and OpenCV and I am working towards building an eye tracking system for mouse pointer movement. So far my script can recognise the pupil and it tracks the pupil's position, but I am unsure how to assign the mouse's movement to the pupil's position.</p>
  
  <p>I'm using opencv 4.0.0, python 2.7 and numpy. 
  I've found some answers such as this one <a href="https://stackoverflow.com/questions/40354074/how-can-i-move-mouse-by-detected-face-and-eye-using-opencv-and-python">How can I move mouse by detected face and Eye using OpenCV and Python</a> but I am not very sure how to implement the solution in my script since I don't have face and eye detection. </p>
  
  <pre class="lang-py prettyprint-override"><code>while True:
      ret, frame = cap.read()
      if ret is False:
          break
  
      roi = frame[20: 300, 27: 396]
      rows, cols, _ = roi.shape
      gray_roi = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)
      #gray_roi = cv2.GaussianBlur(gray_roi, (7, 7), 0)
  
      _, threshold = cv2.threshold(gray_roi, 22, 255, cv2.THRESH_BINARY_INV)
      contours, hierarchy = cv2.findContours(threshold, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
  
      contours = sorted(contours, key=lambda x: cv2.contourArea(x), reverse=True)
  
      for cnt in contours:
          (x, y, w, h) = cv2.boundingRect(cnt)
  
          cv2.drawContours(roi, [cnt], -1, (0, 0, 255), 3)
          cv2.rectangle(roi, (x, y), (x + w, y + h), (255, 0, 0), 2)
          cv2.line(roi, (x + int(w/2), 0), (x + int(w/2), rows), (0, 255, 0), 2)
          cv2.line(roi, (0, y + int(h/2)), (cols, y + int(h/2)), (0, 255, 0), 2)
          break
  
      cv2.imshow("Threshold", threshold)
      cv2.imshow("gray roi", gray_roi)
      cv2.imshow("Roi", roi)
      key = cv2.waitKey(30)
      if key == 27:
          break
  
  cv2.destroyAllWindows()
  </code></pre>
  
  <p>Any help is appreciated, thank you!</p>