Device or resource busy

asked 2014-10-11 00:16:34 -0500

maxdoom gravatar image

updated 2014-10-11 03:00:25 -0500

Hi there,

I'm trying to write a program that uses 2 cameras. In the first step I open the cameras on by one for configuration (which is left, right, not to use and so on). After that I open the left and right camera each in on thread. I close the configuration with:

destroyWindow(id);

cap.release();

The Problem is after the configuration I get the following massage when I try to open the capturing:

  VIDEOIO ERROR: V4L/V4L2: VIDIOC_CROPCAP
    VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV
    VIDIOC_REQBUFS: Device or resource busy
    VIDIOC_G_FMT: Bad file descriptor
    Unable to stop the stream.: Device or resource busy
    VIDIOC_G_FMT: Bad file descriptor

Another thing thats happening is that the camera window stays open for much to long. I put a sleep(60) after closing the video feed and the window stays open until the sleep is over. It's like the command is not even executed when the command is given.

Edit: Full Code in here: http://pastebin.com/MgYen8pL The important part is the main function and the registerCameras function.

edit retag flag offensive close merge delete

Comments

please show more code. (impossible to guess, what you're doing now)

berak gravatar imageberak ( 2014-10-11 02:35:30 -0500 )edit

It's done, pastbin link is up.

maxdoom gravatar imagemaxdoom ( 2014-10-11 02:52:24 -0500 )edit

the capture is already running in a thread of its own. (it's all async)

does it get better, if you skip the registerCameras() function ? (i don't see the reason for this anyway)

berak gravatar imageberak ( 2014-10-11 03:23:41 -0500 )edit

The 2 threads run fine if I don't use registerCameras(). I need to register them because I have 3 cameras and need to know which one is left or right.

maxdoom gravatar imagemaxdoom ( 2014-10-11 03:34:00 -0500 )edit

again, the main code won't wait until your captures(from registerCameras()) properly close.

berak gravatar imageberak ( 2014-10-11 04:00:23 -0500 )edit

Yeah I thought so, but how do I close it properly?

maxdoom gravatar imagemaxdoom ( 2014-10-11 04:11:36 -0500 )edit

it will get even worse, once you try to port to a different machine/os/capture_type.

berak gravatar imageberak ( 2014-10-11 04:26:12 -0500 )edit

And what do you suggest I do? No Threads? How do I properly close the video stream?

maxdoom gravatar imagemaxdoom ( 2014-10-11 04:41:32 -0500 )edit

maybe: while( cap.isOpened() ) waitKey(20);

berak gravatar imageberak ( 2014-10-11 04:44:57 -0500 )edit

the complete VideoCapture interface is quite unable to handle multiple cameras effectively. This is a known issue but adapting the complete interface will indeed be one hell of a job.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-10-12 07:38:03 -0500 )edit