4

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

Joan Goset
  • 41
  • 2
  • Which user are you running this on? Does the user have permission to read your camera? – AKX May 27 '21 at 13:00
  • Check if you see your camera using lsusb – Doch88 May 27 '21 at 13:17
  • Normally, it is udev that creates the symbolic link if a device is detected by the kernel. `cv2.VideoCapture(0) `can correspond to `"/dev/video0"` do a `"ls /dev | grep video"` to confirm that the symbolic link exists. check that in raspi-config the use of camera is Ok, and think well to add the user to the group corresponding to these dynamic link – Jerome Favrou May 27 '21 at 22:46
  • 3
    First of all thanks for your comments. I confirm that the camera is Ok. I had to add my user to the symbolic link in "/dev/videoX/". I see many symbolic links (from 10 to 16) and only two are stablishing connection with the camera. The problem now is that when I connect to them with **cv2.VideoCapture(15, cv2.CAP_V4L2)** I see the next error: `[ WARN:0] global /tmp/[...]/opencv/modules/videoio/src/cap_v4l.cpp (1004) tryIoctl VIDEOIO(V4L2:/dev/video15): select() timeout.` Any idea about what's happening? Many thanks in advanced! – Joan Goset May 29 '21 at 16:02

0 Answers0