3

用相机我必须检查一扇真正的门是打开还是关闭。这是一扇普通的木门(里面没有窗户),你可以在任何房子里找到它。

我想使用 OpenCV 进行图像识别。有了它,我想识别门的打开和关闭状态。

但我不确定我应该为此使用哪种算法或检测方法。什么是最好的选择?


编辑:

这是门的示例图像。我的一个想法是只扫描图像的一小部分(上角)并用当前图像检查“关闭状态”图像。截图中的小例子也是如此。

在此处输入图像描述

4

2 回答 2

5

我已经在 opencv 上发布了类似内容的答案:http: //answers.opencv.org/question/56779/detect-open-door-with-traincascade/

我的问题是检测具有稳定摄像机角度的门状态。

主要思想是使用洪水填充算法:

import cv2
from numpy import *

test_imgs = ['night_open.jpg', 'night_closed.jpg', 'day_open.jpg', 'day_closed.jpg']

for imgFile in test_imgs:
    img = cv2.imread(imgFile)
    height, width, channels = img.shape
    mask = zeros((height+2, width+2), uint8)

    #the starting pixel for the floodFill
    start_pixel = (510,110)
    #maximum distance to start pixel:
    diff = (2,2,2)

    retval, rect = cv2.floodFill(img, mask, start_pixel, (0,255,0), diff, diff)

    print retval

    #check the size of the floodfilled area, if its large the door is closed:
    if retval > 10000:
    print imgFile + ": garage door closed"
    else:
    print imgFile + ": garage door open"

    cv2.imwrite(imgFile.replace(".jpg", "") + "_result.jpg", img)

结果非常好:

681
night_open.jpg: garage door open
19802
night_closed.jpg: garage door closed
639
day_open.jpg: garage door open
19847
day_closed.jpg: garage door closed

车库门关闭 车库门打开

于 2017-04-24T07:26:51.100 回答
1

您可以尝试背景检测算法。这个想法是门状态(打开/关闭)的变化将触发背景的变化。您可以使用此信息对事件进行进一步分类(开/关)。

优点:它会自动适应照明条件的微小变化,并且不需要校准。

这种方法的缺点是其他变化可能会触发一个事件:一个人走在走廊上,灯打开/关闭等。

您检测门上角的想法还不错。您应该手动标记所需区域,然后扫描该矩形以查看木质纹理是否仍然存在。LBP 是一个很好的纹理鉴别器,你可以用它来训练一个分类器来区分木材和非木材。不要忘记为白天/夜晚/晚上/日光/烛光放置样品。

最后,一个非常简单但可能有效的方法是遮盖门上的两个区域:一个是门本身,一个是安装在墙上的木制面具。然后算法根据一个非常简单的指标(平均亮度/颜色/强度/等)比较这两个区域。如果差异高于合理阈值,则可能门已打开,而您看到的是另一个房间(墙壁/窗户/地毯)中的东西

于 2012-07-04T11:56:34.210 回答