OpenCVBlueprints / OpenCVBlueprints

OpenCVBlueprints
Other
135 stars 104 forks source link

camera stays busy after terminating set_motion_trap.py #6

Open sato-cloudian opened 8 years ago

sato-cloudian commented 8 years ago

Hi,

After terminating set_motion_trap.py by interrupting with Ctrl+C, my camera stays busy, and won't respond with the following error.

$ gphoto2 --list-all-config

*** Error ***              
An error occurred in the io-library ('Could not claim the USB device'): Could not claim interface 0 (Device or resource busy). Make sure no other program (gvfs-gphoto2-volume-monitor) or kernel module (such as sdc2xx, stv680, spca50x) is using the device and you have read/write access to the device.
*** Error (-53: 'Could not claim the USB device') ***       

For debugging messages, please use the --debug option.
Debugging messages may help finding a solution to your problem.
If you intend to send any error or debug messages to the gphoto
developer mailing list <gphoto-devel@lists.sourceforge.net>, please run
gphoto2 as follows:

    env LANG=C gphoto2 --debug --debug-logfile=my-logfile.txt --list-all-config

Please make sure there is sufficient quoting around the arguments.

After manually plug it out and in, it starts responding again.

Is there anyway to cleanly terminate the program? Or anything wrong?

Thanks.

StevenPuttemans commented 8 years ago

@sato-cloudian thank you for the report. It seems indeed that the while loop has no case for exiting, by example by pressing ESC. By hitting CTRL+C it seems you are interrupting the program, but the destructor of the camera object is likely not called anymore.

@JoeHowse any suggestions on how to cleanly fix this in python?

quanhua92 commented 8 years ago

We can solve this with cv2.waitKey function. For reference, please follow this tutorial http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_gui/py_video_display/py_video_display.html

StevenPuttemans commented 8 years ago

:+1: I will add the suggested fix!

StevenPuttemans commented 8 years ago

@JoeHowse and @sato-cloudian could you both check if the fix https://github.com/OpenCVBlueprints/OpenCVBlueprints/commit/513e6963b5ab4443643524f794460fbf48cc24b8 suits your guys needs?

JoeHowse commented 8 years ago

Thanks for the issue report and suggestions. @sato-cloudian Which camera and which operating system are you using?

As of OpenCV 3.1.0, cv2.waitKey seems to be broken. It always returns -1. (I have just tested on Mac 10.11 and Windows 7 with a basic script that just runs cv2.waitKey in a loop.)

Moreover, cv2.waitKey(tMillisecs) will time-out and miss any input that happens beyond the next tMillisecs milliseconds. Thus, it is ineffective in a loop that contains other long-running statements such as time.sleep(tSecs).

For now, I am reverting the change and re-opening the issue.

sato-cloudian commented 8 years ago

@JoeHowse I tried Canon PowerShot G9 on my Ubuntu 14.04.3 box. But I use Mac as well for demonstration purpose. And I use OpenCV 3.1(master) because I want to deploy Caffe to classify a detected object with our trained convolutional neural network.

Anyway, thanks for your considerations. Let me know if you come up with a good idea. For the time being, I just move ahead.