Search code examples
opencvubuntuubuntu-14.04webcam

opencv webcam not shutting down


I started the webcam using openCV but (stupidly) did not assign code for proper closing up of resources. So now the webcam is stuck. How can I restart the webcam without rebooting ? I know rebooting will be able to release the webcam but I need a proper fix that doesn't need a reboot for every time I muck up.

OS:ubuntu 14.04
opencv v3.1


Solution

  • Try unloading the kernel module

    sudo modprobe -r uvcvideo
    

    and reload again

    sudo modprobe uvcvideo
    

    This resets the cam if it is a UVC cam. For other cams it shall be similar reloading a different module. Experimenting with openCV sometimes makes the cam reinitialize using a different device (e.g. /dev/video1 instead of /dev/video0). So have a look at

    ls /dev/video*
    

    Maybe it is not locked but just on a different number.