2012-07-04 92 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

相關問題