How to avoid using libv4l2 resource when using python-opencv code in parallel?

I am trying to pass a webcam parallel process method. One of the functions shows the loading of the libv4l2 resource. Tried to use narrow latency between functions it works great. And when I use two cameras, it also works. I think there is a problem with libv4l2 settings or something. How to solve this problem?

import threading
from threading import Thread
import cv2
import numpy as np

def func1():
    video = cv2.VideoCapture(0)
    success, image = video.read()
    print success

def func2():
    video = cv2.VideoCapture(0)
    success, image = video.read()
    print success

if __name__ == '__main__':
    Thread(target = func1).start()
    Thread(target = func2).start()

      

And it is displayed as follows.

VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
libv4l2: error setting pixformat: Device or resource busy
HIGHGUI ERROR: libv4l unable to ioctl S_FMT
libv4l2: error setting pixformat: Device or resource busy
libv4l1: error setting pixformat: Device or resource busy
HIGHGUI ERROR: libv4l unable to ioctl VIDIOCSPICT

False
True

      

+3


source to share


1 answer


First, I highly recommend checking if your device is valid, i.e. webcam, provides parallel I / O control.

Apparently this is not happening because you are getting I / O control command errors

HIGHGUI ERROR: libv4l unable to ioctl S_FMT
HIGHGUI ERROR: libv4l unable to ioctl VIDIOCSPICT

      



You need to implement another layer of abstraction that will do the splitting / duplication of the video stream for you. But not at the device level as you are doing now.

A similar issue has been discussed and resolved here

+3


source







All Articles