Ask Your Question
0

The camera is not working

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

Teo gravatar image

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

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)

edit retag flag offensive close merge delete

Comments

weird, no v4l in the videoio section ?

you could try to use ffmpeg explicity, like:

cap.open(0, CAP_FFMPEG);
berak gravatar imageberak ( 2018-07-18 01:43:46 -0500 )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 ( 2018-07-18 06:13:34 -0500 )edit

2 answers

Sort by » oldest newest most voted
0

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

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.)

edit flag offensive delete link more

Comments

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 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

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

Seen: 110 times

Last updated: Jul 18 '18