【问题标题】:How to detect an object across overlapping cameras如何跨重叠的相机检测物体
【发布时间】:2018-06-03 04:59:05
【问题描述】:

我有一个多摄像头设置,但对于这个问题,我将其缩小到两个摄像头。两个摄像头对齐,摄像头 1 的右侧与摄像头 2 的左侧重叠,以确保没有任何区域处于视线之外。 两个相机共享一个共同的参考系统,即:图像 2 中的 x 轴是图像 1 中 x 轴的连续性。

当对象完全包含在一张图像中时,我对于像下图这样的简单场景没有问题:

我的问题:

当对象穿过这个重叠区域时,我不知道如何继续,如下图所示。对于我的应用程序,我需要为每个检测对象返回:中心点 (x,y),高度边界框和边界框的宽度。

我目前的做法:

我正在使用cv2.findContourscv2.boundingRect 这两个图像。如果对象接触图像的任一侧,我会根据矩形的大小和图像的大小进行计算。如果他们不这样做,这很容易,但如果他们这样做了,那我现在就被困住了。我不知道如何在两个图像的值之间进行权衡并从两个轮廓创建一个唯一的 (x,y,w,h) 点。

有我当前的代码:

import numpy as np
import cv2

img1 = cv2.imread('image_from_cam1.png')
img2 = cv2.imread('image_from_cam2.png')
gray1= cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
gray2= cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
img1_width = img1.shape[1]
img2_width = img2.shape[1]

#Thresholds on both images then find the contours
ret1, thresh1 = cv2.threshold(gray1, 127, 255, 1)
ret2, thresh2 = cv2.threshold(gray2, 127, 255, 1)
cnts1, _ = cv2.findContours(thresh1, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cnts2, _ = cv2.findContours(thresh2, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

result = [] #result list that will contain [(x1,y1,w1,h1), ...]
overlap = False #is the object overlapping across several images
l1 = [] #storage list for sub-results in image1
l2 = [] #storage list for sub-results in image2

#loop over contours of image1 to draw rectangles and check if they touch either left of right border
for cnt in cnts1:
    x,y,w,h = cv2.boundingRect(cnt)
    cv2.rectangle(img1, (x,y), (x+w, y+h), (0,255,0), 2)
    #Test if the bounding box touches the border of the screen
    if x<2 or (x+w)>(img1_width - 2):
        overlap = True
        l1.append((x,y,w,h))
    else:
        #the object is fully contained in image1
        result.append((x,y,w,h))

#loop over contours of image2 to draw rectangles and check if they touch either left of right border
for cnt in cnts2:
    x,y,w,h = cv2.boundingRect(cnt)
    cv2.rectangle(img2, (x,y), (x+w, y+h), (0,255,0), 2)
    #Test if the bounding box touches the border of the screen
    if x<2 or (x+w)>(img2_width - 2):
        overlap = True
        l2.append((x,y,w,h))
    else:
        #the object is fully contained in image2
        result.append((x,y,w,h))

cv2.imshow('cam1',img1)
cv2.imshow('cam2',img2)
cv2.waitKey(0)
cv2.destroyAllWindows()

所以同一个对象会给我 2 组不同的 (x,y,w,h) 和 cv2.boundingRect 在两个图像中。如何获得对象的“真实”(x,y,w,h)?或者从我的代码:如果对象重叠,我如何从l1l2 创建result

【问题讨论】:

  • 你能展示实际的图片吗?
  • 如果你的相机是固定的,那么你可以计算相机之间的变换矩阵,然后将它们拼接在一起,这样就可以得到一个完整的图像。
  • 是的,我的相机已经修好了。如果我用这种方法 @Silencer 将它们缝合在一起,得到的整个图像会包含重叠区域吗?

标签: python python-2.7 opencv computer-vision


【解决方案1】:

我知道这晚了一年,但其他人可能会觉得这很有用。

一种可能的解决方案是: 如果您的 Y 轴始终对齐,则使用单个 X 和 Y 轴定义一个新的坐标系。因此,对于任何一对图像,您将始终只有两个轴。

从左帧中获取对应的X值,减去重叠的像素。 假设从左边开始 x = 0。 大致:

if x_main <= x_left_max:
    x_main = x_left
else:
    x_main = x_left_max + (x_right - overlap)

创建一个转换器函数并始终处理自定义坐标空间中的对象。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-30
    • 1970-01-01
    • 2012-09-05
    • 2014-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-14
    相关资源
    最近更新 更多