Unplugging Webcam during Capture with V4L results in endless loop (Bug #3186)


Added by Thomas Muders over 11 years ago. Updated over 11 years ago.


Status:Cancelled Start date:2013-08-02
Priority:High Due date:
Assignee:- % Done:

70%

Category:highgui-camera
Target version:2.4.7
Affected version:2.4.6 (latest release) Operating System:Linux
Difficulty:Easy HW Platform:x64
Pull request:

Description

In modules/highgui/cap_v4l.cpp:

mainloop_v4l(CvCaptureCAM_V4L capture)* : read_frame_v4l2(capture) returns true in case of success or failure.

The error is "no such device" which makes sense, since the cam is unplugged. But neither the read(Mat)-method of VideoCapture or the isOpened()-method give me a clue about the error. Only my console is being spammed by VIDIOC_DQBUF-Messages.

I wrote a workaround which results in icvGrabFrameCAM_V4L(...) returning 0 in case of this error.

Is there a better way to detect unplugged cameras or did I discover a real bug in the V4L-Implementation of GrabFrame?

Best regards,
Thomas


Associated revisions

Revision ffd1df0c
Added by Vadim Pisarevsky over 10 years ago

Merge pull request #3186 from akarsakov:ocl_fixes

History

Updated by Victor Kocheganov over 11 years ago

Hello Thomas,

thanks for reporting the issue!
Please take a look at these questions:
  1. what camera model do you use?
  2. have you tried its Native API functions to check whether camera is plugged or not?
  3. what OS do you use?

This is indeed something that should be investigated.
And it would be great if you continue participating in investigation and fixing (if this is indeed the issue)!

Thank you in advance,
Victor Kocheganov

  • Category set to highgui-camera
  • Status changed from New to Incomplete
  • Target version set to 2.4.7
  • Assignee set to Thomas Muders

Updated by Thomas Muders over 11 years ago

Hello Victor,

thanks for your reply.
1: I tried two cameras (both no-name), one gives some additional errors about the jpeg data, but both are working very well.
2: No, I did not try anything else beside OpenCV since I want my code to be simple.
3: Oracle Linux 6.4 (64 Bit)

I am currently working with my own bugfix (minor changes in the file modules/highgui/cap_v4l.cpp).

Updated by Thomas Muders over 11 years ago

Why is read_frame_v4l2 returning 1 in case of an error and in case of success? When it is returning 0, it is called again, which is fine.

I modified it, to return 2 in case of an error, to make a distinction possible.

I have to correct the bug description: The endless loop occurs in my software and not in OpenCV.

Wich way to go? Fixing VideoCapture.isOpen() or the grabFrame-Method()?

Updated by Thomas Muders over 11 years ago

This is my diff:

1220c1220
<             return 1;
---
>             return 2; // to distinct error from success => return 2 instead of 1
1241,1242c1241,1242
< 
< static void mainloop_v4l2(CvCaptureCAM_V4L* capture) {
---
> // to distinct error from success => return int
> static int mainloop_v4l2(CvCaptureCAM_V4L* capture) {
1275,1276c1275,1279
< 
<             if (read_frame_v4l2 (capture))
---
>             int readresult = read_frame_v4l2 (capture); // obtain result
>             if (readresult == 2){ // err
>                 return 0; // err
>             }
>             if(readresult) // success
1279a1283
>     return 1;
1357c1361,1366
<         mainloop_v4l2(capture);
---
>         if(!mainloop_v4l2(capture))
>         {
>             fprintf( stderr, "HIGHGUI ERROR: V4L: Could not capture image.\n");
>             return 0;
>         }
>             
1370c1379,1383
<      mainloop_v4l2(capture);
---
>      if(!mainloop_v4l2(capture))
>      {
>        fprintf( stderr, "HIGHGUI ERROR: V4L: Could not capture image.\n");
>        return 0;
>      }

Updated by Victor Kocheganov over 11 years ago

I am sorry for delayed answer, Thomas.

That is really great, yo have prepared complete patch! Thanks a lot, this is really appreciated! But, I totally forgot to mention helpful website http://code.opencv.org/projects/opencv/wiki/How_to_contribute about how to provide your fixes into library in convenient way. Could you please do this last step?

Thank you for your fix!

Updated by Victor Kocheganov over 11 years ago

  • Status changed from Incomplete to Open

Updated by Steven Puttemans over 11 years ago

  • Assignee deleted (Thomas Muders)

Updated by Steven Puttemans over 11 years ago

Problem solved, fix merged!

  • % Done changed from 0 to 100
  • Status changed from Open to Done

Updated by Steven Puttemans over 11 years ago

Since the pull request was reversed after merging, I think this should be opened again, to see which step to take now. Have published some comments in the git pull request, will wait for responses there.

  • Status changed from Done to Open
  • % Done changed from 100 to 70

Updated by Steven Puttemans over 11 years ago

Added an updated pull request: https://github.com/Itseez/opencv/pull/1464
Added all remarks made in previous request, feel free to look for any needed extra's.

Updated by Alexander Smorkalov over 11 years ago

Such solution breaks initialization of some cameras. I canceled the ticket.

  • Status changed from Open to Cancelled

Also available in: Atom PDF