cv2.VideoCapture does not work on raspberry pi and ueye cameras

2.8k views Asked by At

I'm using ueye cameras connected to a Raspberry pi 4 running raspbian and I'm trying to get and display images from the cameras using OpenCV from python. The problem comes when I use:

cap=cv2.VideoCapture(0,cv2.CAP_DSHOW)

or

cv2.CAP_V4L2

or

cv2.CAP_ANY. 

It doesn't detect the camera.

Maybe the problem was the device index '0' so I ran this code to try other indexes:

import cv2

cams_test=100
for i in range (-1,cams_test):
    cap=cv2.VideoCapture(i,cv2.CAP_DSHOW)
    test, frame=cap.read()
    print("i : "+str(i)+" // result: " +str(test))
    if test:
        print("SUCCESSFULL!") 

All indexes failed.

I read the following qüestion How can I use OpenCV to capture video stream of ueye cameras? but i'm not able to find this /dev/ueye directory they are talking about.

Can I substitute the index number in videocapture to a path where my ueye cameras are installed? (I don't know this path)

Is there a way to retrieve the video stream from ueye cameras? Preferably keeping VideoCapture function.

Here's my code:

from tkinter import *
from PIL import Image
from PIL import ImageTk
import cv2
import imutils

def iniciar():
    global cap
    cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
    visualizar()

def visualizar():
    global cap
    if cap is not None:
        ret, frame = cap.read()
        if ret == True:
            frame = imutils.resize(frame, width=640)
            frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
            im = Image.fromarray(frame)
            img = ImageTk.PhotoImage(image=im)
            lblVideo.configure(image=img)
            lblVideo.image = img
            lblVideo.after(10, visualizar)
        else:
            lblVideo.image = ""
            cap.release()

def finalizar():
    global cap
    cap.release()

cap = None
root = Tk()
btnIniciar = Button(root, text="Iniciar", width=45, command=iniciar)
btnIniciar.grid(column=0, row=0, padx=5, pady=5)
btnFinalizar = Button(root, text="Finalizar", width=45, command=finalizar)
btnFinalizar.grid(column=1, row=0, padx=5, pady=5)
lblVideo = Label(root)
lblVideo.grid(column=0, row=1, columnspan=2)
root.mainloop()

Thanks in to whoever is reading my qüestion I hope the answer helps other people

0

There are 0 answers