New VideoCapture is broken (Bug #3880)


Added by Philipp Hasper over 10 years ago. Updated over 9 years ago.


Status:Done Start date:2014-08-23
Priority:Blocker Due date:
Assignee:- % Done:

100%

Category:-
Target version:-
Affected version:branch 'master' (3.0-dev) Operating System:Any
Difficulty:Medium HW Platform:Any
Pull request:

Description

Hi, I believe that during the creation of the new videoio module, VideoCapture was broken by using cv::Ptr : When using Direct Show (and most probably any other camera module), isOpened() always reports "true" even if no camera has been opened. This is because in cap.cpp, line 516:

bool VideoCapture::isOpened() const
{
    return (!cap.empty() || !icap.empty());
}

icap always owns an object and thus is not empty.

The problem lies in cap.cpp, line 624:

case CV_CAP_DSHOW:
            capture = Ptr<IVideoCapture>(new cv::VideoCapture_DShow(index));
if (capture)
 return capture

Reproducing and explaining the error

  1. Write a program containing the lines cv::VideoCapture cap(0) and assert(!cap.isOpened()) and run it with no camera attached
  2. In cap.cpp, line 624, cv::VideoCapture_DShow will be instanciated and in its constructor the helping method open() will notice that the number of available devices is 0 and thus leave all member variables to the default (i.e. all to -1)
  3. Although the created VideoCapture_DShow is just a dummy, the smart pointer contains a value and thus if(capture) holds and the method returns a capture object
  4. One layer higher, back in the VideoCapture::open(int device), this object is assigned to the member variable icap which is then assumed to be a valid, open camera. But it is not!
  5. P.S.: The runtime error happens when you try to retrieve an image and in cap_dshow.cpp, line 1591:
    bool videoInput::isDeviceSetup(int id){
    
        if(id<devicesFound && VDList[id]->readyToCapture)return true;
        else return false;
    
    }
    

    this method is called with the icaps device id - which has the default value -1. thus, VDList[-1] crashes.

Pew, this was a long post containing many problems. I hope I could make my point clear enough :-) . Plus, I fear that the same error might occur in other parts of the new camera module.


Related issues

related to Bug #3867: cv::VideoCapture of RTSP stream claims to be open when co... Cancelled 2014-08-14

Associated revisions

Revision 1381564a
Added by Vadim Pisarevsky almost 10 years ago

Merge pull request #3880 from vpisarev:fix_emd

History

Updated by Philipp Hasper over 10 years ago

  • % Done changed from 0 to 90

Updated by Philipp Hasper over 10 years ago

  • % Done changed from 90 to 100
  • Status changed from New to Done

Updated by Bruno Coutinho about 10 years ago

I am hitting a bug like this on opencv 2.4.10, ubuntu 14.04 and gcc 4.8.2. isOpen() returns true even if there is no camera in my machine. Then get this message:

GStreamer Plugin: Embedded video playback halted; module v4l2src0 reported: Cannot identify device '/dev/video0'.
OpenCV Error: Unspecified error (GStreamer: unable to start pipeline
) in icvStartPipeline, file /home/coutinho/src/opencv-2.4.10/modules/highgui/src/cap_gstreamer.cpp, line 383
terminate called after throwing an instance of 'cv::Exception'
what(): /home/coutinho/src/opencv-2.4.10/modules/highgui/src/cap_gstreamer.cpp:383: error: (-2) GStreamer: unable to start pipeline
in function icvStartPipeline

Aborted (core dumped)

Also available in: Atom PDF