Python 排除部分视频/图像OpenCV对象识别/跟踪
我正在尝试使用OpenCV通过一个短片段跟踪篮球。我正在使用代码来帮助我找到正确的颜色代码的上限和下限,但是球的颜色与视频底部附近的游戏时钟非常相似。我如何在我的目标跟踪代码中切断这一点,使程序不只是跟踪时钟?我正在使用本教程中的代码: 我认为进行此更改的代码位于以下代码块中:Python 排除部分视频/图像OpenCV对象识别/跟踪,python,opencv,image-recognition,hsv,video-tracking,Python,Opencv,Image Recognition,Hsv,Video Tracking,我正在尝试使用OpenCV通过一个短片段跟踪篮球。我正在使用代码来帮助我找到正确的颜色代码的上限和下限,但是球的颜色与视频底部附近的游戏时钟非常相似。我如何在我的目标跟踪代码中切断这一点,使程序不只是跟踪时钟?我正在使用本教程中的代码: 我认为进行此更改的代码位于以下代码块中: # find contours in the mask and initialize the current # (x, y) center of the ball cnts = cv2.find
# 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, (0, 0, 255), -1)
我知道我没有提供MWE,但我不确定在这种情况下如何提供。我想我的问题至少是直截了当的,如果不简单的话。不要使用最大轮廓(cf.
c=max(…)
),而是获取n
最大轮廓,对于每个轮廓,获取已经存在的中心,并丢弃该轮廓,它似乎就是时钟(中心的y
大约是图像的高度,因为您声明,它在底部附近)。相机是“视图”吗静态,还是相机移动?如果相机不移动,那么你可以简单地应用你正在使用的方法,但只需添加一个过滤器来对帧进行差分,以便只处理移动的对象。这种差分基本上应该用作原始图像的遮罩。如果相机几乎在移动,那么你可能需要调整其他方法技术,比如寻找只存在于(比如)时钟中的特征,并基于此进行过滤。@HansHirse不幸的是,相机正在移动,剪辑看起来都类似于以下链接:有很多移动的对象,因此这可能会造成一些麻烦。