Problema con programma OpenCV per rilevamento porte aperte
Ho copiato in rete il seguente codice per il rilevemento di porte aperte o chiuse:
Se eseguo ottengo:
Non accetta > perché ? Non capisco.
Devo fargli riconoscere porte aperte o chiuse.
- Codice: Seleziona tutto
import cv2
from numpy import *
test_imgs = ['day_open.jpg','day_closed.jpg','night_open.jpg','night_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 = 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)
Se eseguo ottengo:
- Codice: Seleziona tutto
(3633211, array([[[ 48, 64, 77],
[ 43, 59, 72],
[ 40, 53, 67],
...,
[ 23, 37, 59],
[ 24, 41, 62],
[ 29, 46, 67]],
[[ 49, 65, 78],
[ 46, 62, 75],
[ 43, 56, 70],
...,
[ 26, 40, 62],
[ 23, 40, 61],
[ 25, 42, 63]],
[[ 49, 65, 77],
[ 48, 64, 76],
[ 46, 60, 72],
...,
[ 28, 41, 63],
[ 19, 33, 55],
[ 19, 33, 55]],
...,
[[ 66, 161, 204],
[ 63, 161, 203],
[ 58, 158, 200],
...,
[227, 241, 237],
[227, 241, 237],
[227, 241, 237]],
[[ 68, 163, 207],
[ 64, 161, 205],
[ 58, 158, 200],
...,
[224, 238, 234],
[225, 239, 235],
[226, 241, 237]],
[[ 68, 163, 207],
[ 64, 161, 205],
[ 58, 158, 200],
...,
[225, 239, 235],
[225, 240, 236],
[227, 242, 238]]], shape=(4000, 1800, 3), dtype=uint8), array([[1, 1, 1, ..., 1, 1, 1],
[1, 0, 0, ..., 0, 0, 1],
[1, 0, 0, ..., 0, 0, 1],
...,
[1, 0, 0, ..., 0, 0, 1],
[1, 0, 0, ..., 0, 0, 1],
[1, 1, 1, ..., 1, 1, 1]], shape=(4002, 1802), dtype=uint8), (0, 0, 1800, 4000))
Traceback (most recent call last):
File "/home/fabio/Scrivania/prova.py", line 21, in <module>
if retval > 10000:
TypeError: '>' not supported between instances of 'tuple' and 'int'
Non accetta > perché ? Non capisco.
Devo fargli riconoscere porte aperte o chiuse.