【问题标题】:How to detect free space between two detected windows如何检测两个检测到的窗口之间的可用空间
【发布时间】:2021-04-21 19:54:24
【问题描述】:

我使用 YOLOv3 来检测建筑物上的窗户。每个窗口都显示有一个边界框,我还提取了每个窗口的坐标[top_left,bottom_left,top_right,bottom_right]。现在我想在所有窗户之间找到空闲空间[墙]。我将每个窗口的坐标放在一个字典中。 当我手动设置值时,它适用于每个窗口,例如:

p1 = points_list[0][2] # top_left window1
p2 = points_list[1][1] # bottom_left window2
cv2.rectangle(img, p1, p2, (255, 0, 255), -1)

,但我怎样才能让它自动找到墙壁。 这里是my first output image,检测到的墙以粉色显示。 这里我还添加了我的代码示例。

def bb_to_rect(x, y, w, h):
    top_left = (x, y)
    top_right = (x + w, y)
    bottom_left = (x, y + h)
    bottom_right = (x + w, y + h)
return top_left, bottom_left, top_right, bottom_right

def draw_bounding_box(img, font, boxes, confidences, colors):

    indices = cv2.dnn.NMSBoxes(boxes, confidences, CONF_THRESHOLD, NMS_THRESHOLD)
    points_list={}
    count = 0
    for i in range(len(boxes)):
        if i in indices:

           (x, y, w, h) = boxes[i]
           label = "{}:{:.2f}%".format(classes[class_ids[i]], confidences[i] * 100)
           color = colors[class_ids[i]]
           cv2.rectangle(img, (x, y), (x + w, y + h), color, 2)
           cv2.putText(img, str(i), (x, y), cv2.FONT_HERSHEY_TRIPLEX,
                      .5, (255, 255, 0), 1, cv2.LINE_AA)

           top_left, bottom_left, top_right, bottom_right = bb_to_rect(x, y, w, h)
           points_list[count] = [top_left, bottom_left, top_right, bottom_right]
           count += 1

           cv2.circle(img, (x + w, y), 3, (50, 100, 0), -1) # top Right
           cv2.circle(img, (x + w, y + h), 3, (0, 0, 255), -1) # bottom Right
           cv2.circle(img, (x, y), 3, (0, 255, 100), -1)  # top left
           cv2.circle(img, (x, y + h), 3, (255, 0, 255), -1)  # bottom left

return img, points_list

if __name__ == "__main__":

     net, output_layers, colors, classes = load_yolo_model()
     img, height, width = load_img(IMAGES_PATH)

     outs = create_blob(img, net, output_layers)
     boxes, class_ids, confidences, centroids = detect_obj(outs, height, width, img)

     img, points_list = draw_bounding_box(img, FONT, boxes, confidences, colors)

     p1 = points_list[0][2] # window0 to window1
     p2 = points_list[1][1]

     p2_1 = points_list[1][2] # window1 to window2
     p2_2 = points_list[2][1]

     p3_1 = points_list[3][2] # window3 to window5
     p5_2 = points_list[5][1]

     cv2.rectangle(img, p1, p2, (255, 0, 255), -1)
     cv2.rectangle(img, p2_1, p2_2, (255, 0, 255), -1)
     cv2.rectangle(img, p3_1, p5_2, (255, 0, 255), -1)
     cv2.imshow('out', img)
     cv2.waitKey(0)
  

此外,如果您看到照片,您会看到随机检测到的窗口,并且每个窗口的 ID 号没有排序。我怎么解决这个问题?在此先感谢您的帮助:)

【问题讨论】:

  • 在黑色图像上绘制检测到的填充白色的窗口边界框。剩下的黑色区域是空闲空间

标签: python-3.x opencv computer-vision object-detection yolo


【解决方案1】:

您是否尝试过图像分割来查找墙上的对象?然后通过一个简单的技巧,比如找到计数器,你可以按照你所说的测量窗户等物体之间的距离。

第二招: 我有另一种简单的方法可以帮助你:
首先,使用canny边缘检测找到边缘,用dilate函数填充窗口之间垂直边缘的中间空间然后通过霍夫线检测可以找到窗口的垂直线,并得到墙壁垂直线的y轴之间的距离

【讨论】:

  • 感谢您的回复。不,我还没有尝试图像分割。这可能是个好主意。关于第二招,业主想使用深度学习技术。但我也可以测试这种方法,看看性能是否会更好。 Tnx
猜你喜欢
  • 2021-07-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-29
  • 1970-01-01
  • 1970-01-01
  • 2015-04-27
  • 1970-01-01
相关资源
最近更新 更多