Ask Your Question

Can't get images from 2 cameras

asked 2018-09-10 11:21:32 -0500

updated 2018-09-11 02:38:02 -0500

Hello guys, my problem is that I can't get get images from 2 cameras. They are identical and resolution 320x240. Encoding is MJPEG which is compressed one.

The problem I get:

VIDIOC_STREAMON: No space left on device
Right video camera is not working at the moment. Capture Error!

My df -i results:

Filesystem     Inodes IUsed  IFree IUse% Mounted on
udev           183230  1425 181805    1% /dev
tmpfs          219824  1652 218172    1% /run
/dev/mmcblk0p2 966656 72370 894286    8% /
tmpfs          219824     1 219823    1% /dev/shm
tmpfs          219824     2 219822    1% /run/lock
tmpfs          219824    16 219808    1% /sys/fs/cgroup
/dev/mmcblk0p1      0     0      0     - /media/boot
tmpfs          219824     4 219820    1% /run/user/0

The code I use:

// OpenCV libraries
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/core.hpp"
#include "opencv2/shape.hpp"
#include <opencv2/aruco.hpp>

// Std libraries
#include <iostream>
#include <string>
#include <cstdlib>
#include <stdio.h>
#include <cmath>
#include <ctime>
#include <signal.h>
#include <algorithm>
#include <unistd.h>

using namespace std;
using namespace cv;

bool isSingleBoard = true;
VideoCapture capL, capR;
VideoWriter leftWriter, rightWriter;

//Signal handling for SIGINT ( CTRL + C )
void my_handler(int s){
    capL.release(); // opencv camera release
    capR.release(); // opencv camera release
    //SDL_Quit(); // OpenGL release

int main(int argc, char **argv){

    cv::Mat cameraMatrixL = cv::Mat(3,3, CV_64F);
    cv::Mat distCoeffsL = cv::Mat(1,4, CV_64F);

    cv::Mat cameraMatrixR = cv::Mat(3,3, CV_64F);
    cv::Mat distCoeffsR = cv::Mat(1,4, CV_64F);

    int width = 320, height = 240; // Change as you desire, care that most of the cameras are not supporting all ratios!

    // Signal is needed because capture should be released in any case. I use sigint for closing, I handled it.
    struct sigaction sigIntHandler;
    sigIntHandler.sa_handler = my_handler;
    sigIntHandler.sa_flags = 0;
    sigaction(SIGINT, &sigIntHandler, NULL);

        capL = VideoCapture("/dev/video1", cv::CAP_V4L);
        capR = VideoCapture("/dev/video2", cv::CAP_V4L);
        capL = VideoCapture("/dev/video0", cv::CAP_V4L);
        capR = VideoCapture("/dev/video1", cv::CAP_V4L);

    capL.set(CV_CAP_PROP_FPS, 10);
    capR.set(CV_CAP_PROP_FPS, 10);



    // For unique video names.
    time_t seconds;
    seconds = time(NULL);

    string leftname, rightname;
    leftname = string("left_") + to_string(seconds) + string(".avi");
    rightname = string("right_") + to_string(seconds) + string(".avi");

    // CV_FOURCC('M','J','P','G')
    leftWriter = VideoWriter(leftname,CV_FOURCC('M','J','P','G'), 10, Size(width,height));
    rightWriter = VideoWriter(rightname,CV_FOURCC('M','J','P','G'), 10, Size(width,height));

    // BLACK BOX RIGHT CAMERA<double>(0,0) = 8.7030170819798286e+02;<double>(0,1) = 0.;<double>(0,2) = 320.;<double>(1,0) = 0.;<double>(1,1) = 8.7030170819798286e+02;<double>(1,2) = 240.;<double>(2,0) = 0.;<double>(2,1) = 0.;<double>(2,2) = 1.;<double>(0,0) = -4.7851541557875366e-01;<double>(0,1) = 1.0494014645561520e+00;<double>(0,2) = 0.;<double>(0,3) = 0.;<double>(0,4) = -3.0666278646347642e+00;

    // BLACK BOX LEFT CAMERA<double>(0,0 ...
edit retag flag offensive close merge delete



pro tip, you want to put the error at the top, not 500 lines down !

berak gravatar imageberak ( 2018-09-10 11:23:07 -0500 )edit

Thank you for looking the post. Against your unnecessary critism, I want to give a pro tip to you: 1- Insted of using exclamation point and yelling, you can do a nice critism so I can understand and swap the code and error location. 2- You also commented( and removed ) this: ''' "No space left on device" <-- what exactly do you NOT understand here ?''' I already search every single post and tried everything. I need spesific solution and I am willing to give every detail people need. I have enough space in every part and my bandwith is enough to receive 2 1080P images in a second. I looked and change the buffer for higher storage value and I couldn't find something. Thanks Mr. Genius like you, looks like I can't find the answer till the eternity. I am editing the post so you can be happy.

yeser gravatar imageyeser ( 2018-09-11 01:46:46 -0500 )edit

touché (and i got it even wrong. apologies.)

berak gravatar imageberak ( 2018-09-11 02:01:21 -0500 )edit

Again, thanks for looking up on the post. I can give the necessary information. I am adding "df -i" output and some info also.

yeser gravatar imageyeser ( 2018-09-11 02:30:34 -0500 )edit

1 answer

Sort by » oldest newest most voted

answered 2018-09-11 05:26:50 -0500

kbarni gravatar image

I also had exactly his problem, two webcams and a Raspberry Pi 3. I solved it eventually.

If I remember correctly, I was just ignoring this "no space left" error message.

    if (frameL.empty() || frameR.empty())
        break; //instead of exit

If it doesn't work, try to use the default camera settings (so comment the cap...set(...) lines). Or make a small pause between setting up the camera and capturing.

If it still doesn't help, I'll try to think of something other I did. As I said, I don't remember exactly how I solved it...

edit flag offensive delete link more


Thanks for the reply. Unfortunately I changed the code as you say but didn't work. I also make everything default and gave 3 seconds break between settings and reading frames. The same error occured. Thank you

yeser gravatar imageyeser ( 2018-09-11 07:37:08 -0500 )edit

Another idea: try another coding, for example MP42.

kbarni gravatar imagekbarni ( 2018-09-11 09:38:16 -0500 )edit

also try to google this "VIDIOC_STREAMON: No space left on device" issue...there are several discussions on the subject. It seems that it's camera, driver and usb controller dependent. Anyway, it isn't related to OpenCV.

kbarni gravatar imagekbarni ( 2018-09-11 09:41:22 -0500 )edit

You are right about that it is not about opencv. I couldn't find a way and changed my odroid from C2 to XU4. It is worked perfectly. Hope your answer helps someone but unfortunately it didn't work for me. I will try with C2 with miniUSB+USB kamera system which seperates the hubs. If I can manage it, I will write something for that.

yeser gravatar imageyeser ( 2018-09-12 09:11:37 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-09-10 11:21:32 -0500

Seen: 86 times

Last updated: Sep 11 '18