下面是我用于跟踪白色对象的python代码。它工作 - 但只有几秒钟然后整个屏幕变黑,有时它不起作用。我尝试了蓝色并且它有效 - 但白色和绿色给我带来了问题:import cv2import numpy as npcap = 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 !sensitivity = 15lower_white = np.array([0,0,255-sensitivity])upper_white = np.array([255,sensitivity,255])# Threshold the HSV image to get only white colorsmask = cv2.inRange(hsv, lower_white, upper_white)# Bitwise-AND mask and original imageres = cv2.bitwise_and(frame,frame, mask= mask)cv2.imshow('frame',frame)cv2.imshow('mask',mask)cv2.imshow('res',res)k = cv2.waitKey(5) & 0xFFif k == 27:breakcv2.destroyAllWindows()
添加回答
举报
0/150
提交
取消