title: How to get screen coordinates from color detection resultant area obtained from openCV with python?
body: <p>I am trying to work with a pen having green cap tip to navigate mouse cursor using webcam but how can I get the coordinates of cap image on screen so that I can give it as input to pyinput library move function.</p>
  
  <p>Thanks in advance.</p>
  
  <pre><code># Python program for Detection of a
  # specific color(green here) using OpenCV with Python
  
  import cv2
  import numpy as np
  import time
  
  cap = cv2.VideoCapture(0)
  
  
  while (1):
      # Captures the live stream frame-by-frame
  
      _, frame = cap.read()
      hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
      lower_red = np.array([75, 50, 50])
      upper_red = np.array([100, 255, 255])
      mask = cv2.inRange(hsv, lower_red, upper_red)
      res = cv2.bitwise_and(frame, frame, mask=mask)
      cv2.imshow('frame', frame)
      cv2.imshow('mask', mask)
      cv2.imshow('res', res)
  
      **#code to output coordinates of green pen tip**
  
      k = cv2.waitKey(5) &amp; 0xff
      if k == 27:
          break
  
  cv2.destroyAllWindows()
  cap.release()
  </code></pre>