3

With a camera i have to check if a real door is opened or closed. It's a normal wooden door (no windows in it) that you can find in any house.

I want to use OpenCV for image recognition. With that i want to recognize the open and closed states of the door.

But i'm not sure which algorithm or detection method i should use for this. What would be the best option for this?


Edit:

Here is an example image of the door. An idea i had is to just scan a small part of the image (top corner) and check the "closed state" image with the current image. Small example in screenshot aswell.

enter image description here

w00
  • 26,172
  • 30
  • 101
  • 147
  • 2
    Put a QR code on the door and detect that. – Paul Tomblin Jul 04 '12 at 11:07
  • My guess would be detecting rectangles.... http://stackoverflow.com/questions/1817442/how-to-recognize-rectangles-in-this-image – Brian Jul 04 '12 at 11:07
  • @PaulTomblin The camera is too far away for qr code detection and i don't want to put a big ass qr code on the door :-) – w00 Jul 04 '12 at 11:09
  • @Brian I don't think that will work, because it will still detect a rectangle when the door is opened. Because it sees the door post as a rectangle. – w00 Jul 04 '12 at 11:11
  • I came across this a while back... it's a bit obscure, but may point you in the right direction... http://rbrusu.com/tag/robots – Brian Jul 04 '12 at 11:14
  • Can you upload images/video of open and close door? – ArtemStorozhuk Jul 04 '12 at 11:15
  • Are the lighting conditions always going to be the same? Are you talking about an outdoor door where it might be front-lit, back-lit or unlit depending on the time of day? Are there going to be shadows across it? All these things are major impediments to doing it simply unless you can put a definite pattern on the door - even something as simple as a reflective square or two. – Paul Tomblin Jul 04 '12 at 11:22
  • 2
    This should be moved to DSP!!! – karlphillip Jul 04 '12 at 12:26

2 Answers2

5

I already posted an answer to something similar at opencv: http://answers.opencv.org/question/56779/detect-open-door-with-traincascade/

My problem was the detection of a door state with a steady camera angle.

The main idea was to use 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)

The Results were really good:

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

rbs
  • 1,087
  • 2
  • 17
  • 24
1

You can try background detection algorithms. The idea is that a change in door status (open/close) will trigger a change in background. You can use this info to further classify the event (opening/closing).

Pros: it automatically adapts for small changes in lighting conditions, and it doesn't need calibration.

Cons of this method would be that other changes may trigger an event: a person walking down the corridor, a light turned on/off, etc.

Your idea to detect the upper corner of the door is not that bad. You should manually mark the desired area, then scan for that rectangle to see whether the wooden texture is still there. LBP is a good texture discriminator, you can use it to train a classifier to make the distinction between wood and non-wood. Do not forget to put samples for day/night/evening/daylight/candlelight.

And finally, a very simple but probably effective way to do it is to mask two areas on the door: one with the door itself, and one with the wooden mask mounted in the wall. Then the algorithm compares the two areas based on a very simple metric (average brightness/color/intensity/etc). If the difference is above a reasonable threshold, probably the door is opened, and what you see is something in the other room (wall/window/carpet)

Sam
  • 19,708
  • 4
  • 59
  • 82