Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I was also interessted in detecting a door state with OpenCV. My best result was using the floodfill algorithm:

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)

Programm output:

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

Result images:

day closed day open night closed night open