微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

排除部分视频/图像 OpenCV 对象识别/跟踪

如何解决排除部分视频/图像 OpenCV 对象识别/跟踪

我正在尝试使用 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 举报,一经查实,本站将立刻删除。