使用 OpenCV 检查物理门是打开还是关闭

w00*_*w00 3 opencv

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

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

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


编辑:

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

在此处输入图片说明

rbs*_*rbs 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)
Run Code Online (Sandbox Code Playgroud)

结果非常好:

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
Run Code Online (Sandbox Code Playgroud)

车库门关闭 车库门打开