我正在尝试使用具有绿色帽尖的笔来使用网络摄像头导航鼠标光标,但是如何在屏幕上获取帽图像的坐标,以便我可以将其作为 pyinput 库移动功能的输入。
提前致谢。
# 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) & 0xff
if k == 27:
break
cv2.destroyAllWindows()
cap.release()