首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何检查边框是否在AOI上,以及它何时离开。OpenCV python

如何检查边框是否在AOI上,以及它何时离开。OpenCV python
EN

Stack Overflow用户
提问于 2018-12-05 02:12:03
回答 1查看 983关注 0票数 0

所以我想要做的是使用OpenCV来检测盒子和制作感兴趣的区域。当一个盒子经过一个AOI时,它会把它算作一种用途。这很好,但它不断增加每个帧的使用。在检测到使用情况时,我只想这样做一次。

所以我在这里做的是:

  1. 从背景减法中找到轮廓。作品
  2. 检测到每个blob的边界框。作品
  3. 在每个AOI框上循环,并在Union上使用一个交集来查看是否有重叠。
  4. 我将AOI列表中的计数布尔值设置为True。只有当它开始是错误的时候。
  5. 如果它被计算的话,我会忽略它
  6. 如果在联合上没有交集,那么我将计数设置为False。

这里的错误是,它要么一直在计算每一个帧的使用情况,要么只会一次又一次地计数。我想计算它的每一个独特的用法,而不是每一个帧。这就是我到目前为止所拥有的。

代码语言:javascript
复制
 # # loop over the contours
    for c in contours:
        # Filter out the blobs that are too small to be considered cars.
        contours = filter(lambda cont: cv2.contourArea(cont) > 30, contours)
        # compute the bounding box for the contour
        (x, y, w, h) = cv2.boundingRect(c)

        #Find each Area Of Interest usage
        #detectUsage(area_of_interest, c, frame)
        for aoi in area_of_interest:
            #Check if there is a overlap between the detected contour and AOI
            if gvp.machineUseCheck(c, aoi[1]):
                print("{} in use".format(aoi[0]))
                cv2.rectangle(frame, (x, y), (x + w, y + h), (222, 150, 1), 2)
                if aoi[2] == False:
                    aoi[2] = True
                    print("{} set to True".format(aoi[0]))
                elif aoi[2] == True:
                    print("{} Already true".format(aoi[0]))
            elif gvp.machineUseCheck(c, aoi[1]) == False:
                aoi[2] = False
                print("{} not in use".format(aoi[0]))

        #Get all the centers for the bounding boxes
        center = (int(x + w / 2), int(y + h / 2))
        cv2.circle(frame, center, 4, (0, 0, 255), -1)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-12-05 05:55:49

我想出了我所需要做的就是稍微重新组织for循环。

代码语言:javascript
复制
        for aoi in area_of_interest:

        cv2.putText(frame, "AOI Value:{}".format(aoi[2]), (10, 150), cv2.FONT_HERSHEY_SIMPLEX, 0.6,
                    (0, 255, 0), 2)
        cv2.putText(frame, "{} Count:{}".format(aoi[0], str(aoi[3])), (10, aoi[4]), cv2.FONT_HERSHEY_SIMPLEX,
                    0.6, (0, 255, 0), 2)

        i = 0
        for c in contours:
            # Filter out the blobs that are too small to be considered cars.
            contours = filter(lambda cont: cv2.contourArea(cont) > 30, contours)
            # compute the bounding box for the contour
            (x, y, w, h) = cv2.boundingRect(c)
            center = (int(x + w / 2), int(y + h / 2))
            cv2.circle(frame, center, 4, (0, 0, 255), -1)
            if gvp.machineUseCheck(c, aoi[1]):
                if not aoi[2]:
                    aoi[2] = True
                    aoi[3] += 1
                cv2.putText(frame, "Machine IN USE:", (10, 130), cv2.FONT_HERSHEY_SIMPLEX, 0.6,
                            (0, 255, 0), 2)
                cv2.rectangle(frame, (x, y), (x + w, y + h), (222, 150, 1), 2)
                break
            elif i == len(c):
                aoi[2] = False
                break
            i += 1
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53624170

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档