Cos'è ElectroYou | Login Iscriviti

ElectroYou - la comunità dei professionisti del mondo elettrico

Problema cattura immagini da telecamera

Linguaggi e sistemi

Moderatori: Foto UtentePaolino, Foto Utentefairyvilje

0
voti

[1] Problema cattura immagini da telecamera

Messaggioda Foto Utentealien75 » 31 mar 2025, 19:38

Salve sto cercando di catuttrare immagini frame by frame da una telecamera con questo codice preso dal tutorila opencv:
Codice: Seleziona tutto
import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt

while True:
    cap = cv.VideoCapture(0)
    if not cap.isOpened():
        print("Cannot open camera")
        exit()
    # Capture frame-by-frame
    ret, frame = cap.read()
    mask = np.zeros(frame.shape[:2],np.uint8)
    bgdModel = np.zeros((1,65),np.float64)
    fgdModel = np.zeros((1,65),np.float64)
    rect = (100,100,2000,2000)
    cv.grabCut(ret,mask,rect,bgdModel,fgdModel,5,cv.GC_INIT_WITH_RECT)
    mask2 = np.where((mask==2)|(mask==0),0,1).astype('uint8')
    ret = ret*mask2[:,:,np.newaxis]
    plt.imshow(ret),plt.colorbar(),plt.show()


Se eseguo il codice mi da:
Codice: Seleziona tutto
Traceback (most recent call last):
  File "/home/fabio/Scrivania/ForeGround.py", line 16, in <module>
    cv.grabCut(ret,mask,rect,bgdModel,fgdModel,5,cv.GC_INIT_WITH_RECT)
cv2.error: OpenCV(4.11.0) /io/opencv/modules/imgproc/src/grabcut.cpp:557: error: (-5:Bad argument) image must have CV_8UC3 type in function 'grabCut'


perché vuole un'immagine CV_8UC3 ?
Sto cercando in rete la soluzione del problema.
Avatar utente
Foto Utentealien75
1 1 4 8
Sostenitore
Sostenitore
 
Messaggi: 588
Iscritto il: 31 lug 2011, 14:08

Torna a PC e informatica

Chi c’è in linea

Visitano il forum: Nessuno e 12 ospiti