擅长:python、mysql、java
<p>我写这个是为了追踪白色:</p>
<pre><code>import cv2
import numpy as np
cap = cv2.VideoCapture(0)
while(1):
_, frame = cap.read()
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
# define range of white color in HSV
# change it according to your need !
lower_white = np.array([0,0,0], dtype=np.uint8)
upper_white = np.array([0,0,255], dtype=np.uint8)
# Threshold the HSV image to get only white colors
mask = cv2.inRange(hsv, lower_white, upper_white)
# Bitwise-AND mask and original image
res = cv2.bitwise_and(frame,frame, mask= mask)
cv2.imshow('frame',frame)
cv2.imshow('mask',mask)
cv2.imshow('res',res)
k = cv2.waitKey(5) & 0xFF
if k == 27:
break
cv2.destroyAllWindows()
</code></pre>
<p>我试着追踪我手机的白色屏幕,得到了这个:</p>
<p><img src="https://i.stack.imgur.com/6zQ5g.png" alt="enter image description here"/></p>
<p>您可以尝试更改HSV值
你也可以试试HSL颜色空间,就像Legat说的那样,它会更精确</p>