问题描述
我正在尝试使用 OpenCV 通过一个短片来跟踪篮球。我正在使用代码来帮助我尝试找到正确的颜色代码的上限和下限,但球的颜色与视频底部附近的比赛时钟非常相似。我怎样才能在我的对象跟踪代码中切断它,这样程序就不会简单地跟踪时钟?我正在使用本教程中的代码:https://www.pyimagesearch.com/2015/09/14/ball-tracking-with-opencv/
我认为将进行此更改的代码位于以下块中:
# find contours in the mask and initialize the current
# (x,y) center of the ball
cnts = cv2.findContours(mask.copy(),cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
center = None
# only proceed if at least one contour was found
if len(cnts) > 0:
# find the largest contour in the mask,then use
# it to compute the minimum enclosing circle and
# centroid
c = max(cnts,key=cv2.contourArea)
((x,y),radius) = cv2.minenclosingCircle(c)
M = cv2.moments(c)
center = (int(M["m10"] / M["m00"]),int(M["m01"] / M["m00"]))
# only proceed if the radius meets a minimum size
if radius > 10:
# draw the circle and centroid on the frame,# then update the list of tracked points
cv2.circle(frame,(int(x),int(y)),int(radius),(0,255,255),2)
cv2.circle(frame,center,5,-1)
我知道我没有提供 MWE,但我不确定在这种情况下如何做到这一点。我认为我的问题至少是直截了当的,如果不简单的话。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)