Cos'è ElectroYou | Login Iscriviti

ElectroYou - la comunità dei professionisti del mondo elettrico

Problema con programma OpenCV per rilevamento porte aperte

Linguaggi e sistemi

Moderatori: Foto UtentePaolino, Foto Utentefairyvilje

0
voti

[1] Problema con programma OpenCV per rilevamento porte aperte

Messaggioda Foto Utentealien75 » 2 apr 2025, 12:31

Ho copiato in rete il seguente codice per il rilevemento di 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.
Avatar utente
Foto Utentealien75
1 1 4 8
Sostenitore
Sostenitore
 
Messaggi: 588
Iscritto il: 31 lug 2011, 14:08

0
voti

[2] Re: Problema con programma opencv per rilevamento porte aper

Messaggioda Foto Utentexyz » 2 apr 2025, 13:14

alien75 ha scritto:
Codice: Seleziona tutto
TypeError: '>' not supported between instances of 'tuple' and 'int'


Ti consiglio, se vuoi continuare a scrivere in Python, di studiarti bene il linguaggio, altrimenti sarei sempre bloccato al primo errore banale. C'è chiaramente scritto: non puoi confrontare una tuple con un intero.
Avatar utente
Foto Utentexyz
6.864 2 4 6
G.Master EY
G.Master EY
 
Messaggi: 1778
Iscritto il: 5 dic 2009, 18:37
Località: Italy Turin


Torna a PC e informatica

Chi c’è in linea

Visitano il forum: Nessuno e 6 ospiti