2012-07-04 542 views
3

使用摄像机我必须检查真实的门是否打开或关闭。这是一个普通的木门(没有窗户),你可以在任何房子里找到。用OpenCV检查物理门是否打开或关闭

我想使用OpenCV进行图像识别。我想知道门的开启和关闭状态。

但我不知道我应该使用哪种算法或检测方法。什么是最好的选择呢?


编辑:

这里是门的一个例子的图像。我有一个想法是只扫描图像的一小部分(顶部角落),并检查当前图像的“封闭状态”图像。截图中的小例子。

enter image description here

+2

把QR码在门上,并检测。 –

+0

我的猜测会是检测矩形.... http:// stackoverflow。com/questions/1817442 /如何识别矩形在这个图像 – Brian

+0

@PaulTomblin相机是太遥远的二维码检测,我不想在门上放一大屁股二维码: - ) – w00

回答

0

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

优点:它可以自动适应照明条件的微小变化,而且不需要校准。这种方法的

缺点将是其他的变化都可能触发事件:一个人走在走廊,光开启/关闭等

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

最后,一个非常简单但可能有效的方法是屏蔽门上的两个区域:一个与门本身,另一个与木制面具安装在墙上。然后,算法根据非常简单的度量(平均亮度/颜色/强度等)比较两个区域。如果差值高于合理的阈值,可能是门被打开了,你看看有什么东西在其他房间(墙/窗/地毯)

1

我已经张贴的答案,在OpenCV的类似的东西: http://answers.opencv.org/question/56779/detect-open-door-with-traincascade/

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

的主要思想是利用此时,floodFill算法:

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 

garage door closed garage door opened

相关问题