Sorry, this content is no longer available

Ask Your Question
0

The camera is not working

asked Jul 16 '18

Teo gravatar image

updated Jul 30 '18

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)
         cap.open(0);

      else
         cap.open( 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)

Preview: (hide)

Comments

weird, no v4l in the videoio section ?

you could try to use ffmpeg explicity, like:

cap.open(0, CAP_FFMPEG);
berak gravatar imageberak (Jul 18 '18)edit
1

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

Teo gravatar imageTeo (Jul 18 '18)edit

2 answers

Sort by » oldest newest most voted
0

answered Jul 19 '18

Just in case you want to try a different option to see if it helps, you can try using CamCap: https://www.ccoderun.ca/programming/d...

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.initialize(false);
    camera_device.set_all_controls_to_defaults();
    camera_device.set_format(800, 600);
    camera_device.retry_incomplete_captures(5);
    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.)

Preview: (hide)

Comments

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

Teo gravatar imageTeo (Jul 19 '18)edit

Question Tools

1 follower

Stats

Asked: Jul 16 '18

Seen: 471 times

Last updated: Jul 18 '18