Ask Your Question

The camera is not working

asked 2018-07-16 15:20:29 -0600

Teo gravatar image

updated 2018-07-30 06:34:19 -0600

Eduardo gravatar image

I'm new and just starting to learn OpenCV. The camera is not initialized during image capture I tried different cameras, but there is no result, even a window with a black screen does not show. Below information about the video:

 Video I/O:
    DC1394:                      YES (ver 2.2.5)
    FFMPEG:                      YES
      avcodec:                   YES (ver 57.107.100)
      avformat:                  YES (ver 57.83.100)
      avutil:                    YES (ver 55.78.100)
      swscale:                   YES (ver 4.8.100)
      avresample:                YES (ver 3.7.0)
    GStreamer:                   NO
    gPhoto2:                     YES

program text:

#include <opencv2/opencv.hpp>
#include <iostream>

int main( int argc, char** argv )

      cv::namedWindow( "Example10", cv::WINDOW_AUTOSIZE );
      cv::VideoCapture cap;
      if (argc == 1);

      else argv[1] );

      if (!cap.isOpened())
           std::cerr << "Error." << std::endl;
           return -1;

      cv::Mat frame;

      for (;;)

            cap >> frame;
            if (frame.empty()) break;
            cv::imshow( "Example10", frame );
            if (cv::waitKey(33) == 27) break;

     return 0;

P.S (OpenCV - 3.4.1, Linux ubuntu 18.04)

edit retag flag offensive close merge delete


weird, no v4l in the videoio section ?

you could try to use ffmpeg explicity, like:, CAP_FFMPEG);
berak gravatar imageberak ( 2018-07-18 01:43:46 -0600 )edit

The v4l-utils package of the newest version (1.14.2-1) is already installed. Tried with CAP_FFMPEG, nothing changes.

Teo gravatar imageTeo ( 2018-07-18 06:13:34 -0600 )edit

2 answers

Sort by » oldest newest most voted

answered 2018-07-18 23:20:57 -0600

Just in case you want to try a different option to see if it helps, you can try using CamCap:

I'm using it to capture to jpeg before processing with OpenCV. But you can also get the raw pixels so you're not having to deal with jpeg artifacts. Sample code:

#include <CamCap.hpp>

int main()
    CC::Device camera_device;
    camera_device.set_format(800, 600);
    const std::string filename = "test.jpg";

    while (true)
        const v4l2_buffer buffer = camera_device.capture_to_jpeg(filename);
        process(buffer, filename);

    return 0;

(Disclaimer: I'm the author of CamCap.)

edit flag offensive delete link more


Sorry, but how to install this library? Should I install the packages separately from the download page?

Teo gravatar imageTeo ( 2018-07-19 02:24:13 -0600 )edit

Question Tools

1 follower


Asked: 2018-07-16 15:20:29 -0600

Seen: 378 times

Last updated: Jul 18 '18