100
'''
c = max(cnts, key=cv2.contourArea)
((box_x, box_y), radius) = cv2.minEnclosingCircle(c)
M = cv2.moments(c)
center = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"]))
X = int(box_x)
Y = int(box_y)
'''
Get the center point coordinates of the target color object and output
'''
print('Target color object detected')
print('X:%d'%X)
print('Y:%d'%Y)
print('-------')
'''
Write text on the screen:Target Detected
'''
cv2.putText(img,'Target Detected',(40,60), font, 0.5,(255,255,255),1,cv2.LINE_AA)
'''
Draw a frame around the target color object
'''
cv2.rectangle(img,(int(box_x-radius),int(box_y+radius)),
else:
cv2.putText(img,'Target Detecting',(40,60), font, 0.5,(255,255,255),1,cv2.LINE_AA)
print('No target color object detected')
# encode as a jpeg image and return it
yield
cv2.imencode('.jpg', img)[1].tobytes()
●You can set the color you want to recognize by changing colorUpper and colorLower. The thing to note
here is that normal The H value (hue) of the HSV color space is 0-360, but in OpenCV, the H value ranges from
0-180.
(int(box_x+radius),int(box_y-radius)),(255,255,255),1)
Need help?
Do you have a question about the AWR Adeept Wheeled Robot and is the answer not in the manual?