- 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.

Elettrotecnica e non solo (admin)
Un gatto tra gli elettroni (IsidoroKZ)
Esperienza e simulazioni (g.schgor)
Moleskine di un idraulico (RenzoDF)
Il Blog di ElectroYou (webmaster)
Idee microcontrollate (TardoFreak)
PICcoli grandi PICMicro (Paolino)
Il blog elettrico di carloc (carloc)
DirtEYblooog (dirtydeeds)
Di tutto... un po' (jordan20)
AK47 (lillo)
Esperienze elettroniche (marco438)
Telecomunicazioni musicali (clavicordo)
Automazione ed Elettronica (gustavo)
Direttive per la sicurezza (ErnestoCappelletti)
EYnfo dall'Alaska (mir)
Apriamo il quadro! (attilio)
H7-25 (asdf)
Passione Elettrica (massimob)
Elettroni a spasso (guidob)
Bloguerra (guerra)


