Python 带识别的opencv运动跟踪器

Python 带识别的opencv运动跟踪器,python,opencv,tracking,opencv-contour,Python,Opencv,Tracking,Opencv Contour,目前,下面的脚本工作得非常好,但我现在想为每个矩形绑定框指定一个标识符 while True: # grab the current frame and initialize the occupied/unoccupied (grabbed, frame) = camera.read() if not grabbed: break # resize the frame, convert it to grayscale, and blur it

目前,下面的脚本工作得非常好,但我现在想为每个矩形绑定框指定一个标识符

while True:
    # grab the current frame and initialize the occupied/unoccupied
    (grabbed, frame) = camera.read()

    if not grabbed:
        break

    # resize the frame, convert it to grayscale, and blur it
    frame = imutils.resize(frame, width=500)
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    gray = cv2.GaussianBlur(gray, (21, 21), 0)

    # if the first frame is None, initialize it
    if firstFrame is None:
        firstFrame = gray
        continue

    # compute the absolute difference between the current frame and
    # first frame
    frameDelta = cv2.absdiff(firstFrame, gray)
    thresh = cv2.threshold(frameDelta, 25, 255, cv2.THRESH_BINARY)[1]

    # dilate the thresholded image to fill in holes, then find contours
    # on thresholded image
    thresh = cv2.dilate(thresh, None, iterations=2)
    (_, cnts, _) = cv2.findContours(thresh.copy(),   cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)

    # loop over the contours
    for c in cnts:
        # if the contour is too small, ignore it

        if cv2.contourArea(c) < args["min_area"]:
            continue

        # compute the bounding box for the contour, draw it on the frame
        (x, y, w, h) = cv2.boundingRect(c)
        cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
为True时:
#抓取当前帧并初始化已占用/未占用的帧
(抓取,帧)=照相机。读取()
如果没有抓到:
打破
#调整帧大小,将其转换为灰度,然后对其进行模糊
frame=imutils.resize(frame,width=500)
灰色=cv2.CVT颜色(边框,cv2.COLOR\u BGR2GRAY)
灰色=cv2.高斯模糊(灰色,(21,21,0)
#如果第一帧为无,则初始化它
如果firstFrame为无:
第一帧=灰色
持续
#计算当前帧与当前帧之间的绝对差值
#第一帧
frameDelta=cv2.absdiff(第一帧,灰色)
thresh=cv2.threshold(frameDelta,25255,cv2.thresh_二进制)[1]
#放大阈值图像以填充孔洞,然后找到轮廓
#关于阈值图像
thresh=cv2.扩张(thresh,无,迭代次数=2)
(u,cnts,u)=cv2.findContours(thresh.copy(),cv2.RETR_EXTERNAL,cv2.CHAIN_近似_SIMPLE)
#在轮廓上打圈
对于碳纳米管中的碳:
#如果轮廓太小,请忽略它
如果cv2.轮廓面积(c)
例如,如下图所示:

我希望能够将四个矩形边界中的每一个都识别为一个对象。(即,最左边是钻石女王卡的装订盒,最右边是红桃王牌卡的装订盒)


现在,我很困惑如何才能做到这一点,我想知道是否有人能给我灵感,你所需要做的就是使用连续帧之间的差异找到轮廓,并在轮廓上循环,然后命令坐标分别检测每个轮廓,然后你可以标记它们。。。
参考

关于……也有一个类似的问题。。。也许你可以在那里找到一些有用的东西?我不确定你提供的链接是否与我的查询有关..:/我想我不明白你的问题。你说的“给每个矩形框一个标识符”是什么意思?假设有两个人在视频中行走。我应该能够识别第一个框为Person 1,第二个框为Person 2Oh,好的,你想在视频的连续帧中跟踪多个移动对象。因此,基本上是从先前帧中获取的信息,预测当前帧中每个对象的位置,并找到最可能的匹配(在看到对象的第一帧中,您需要进行一些有根据的猜测)。你能分辨出这些物体吗?还是你所知道的一切都只是位置?