Python OpenCV - VideoCapture.release() won't work in Linux
The way to free the camera (without exiting) is indeed release(). I've tested your code in a Linux Mint 18 (64bit) environment running both OpenCV 2.4.13 and also OpenCV 3.1 with Python 2.7.12. There were no issues.
Here is a way for you to see what is going on in your code:
import cv2
import sys
#print "Before cv2.VideoCapture(0)"
#print cap.grab()
cap = cv2.VideoCapture(0)
print "After cv2.VideoCapture(0): cap.grab() --> " + str(cap.grab()) + "\n"
while True:
ret, frame = cap.read()
if frame is None:
print "BYE"
break
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
print "After breaking, but before cap.release(): cap.grab() --> " + str(cap.grab()) + "\n"
cap.release()
print "After breaking, and after cap.release(): cap.grab() --> " + str(cap.grab()) + "\n"
cap.open(0)
print "After reopening cap with cap.open(0): cap.grab() --> " + str(cap.grab()) + "\n"
cv2.destroyAllWindows()
while True:
cv2.waitKey(1)
You may want to think about reinstalling OpenCV on your system. I recommend checking out the awesome guides on PyImageSearch --> http://www.pyimagesearch.com/opencv-tutorials-resources-guides/
Let me know if this helps!
Get a still frame during webcam video capture on Linux
You can have multiple outputs for FFmpeg. Combine your commands:
ffmpeg -f v4l2 -framerate 30 -video_size 1024x576 -i /dev/video0 myvideo.mp4 -r 1 -update 1 current_frame.jpg
What's the best library for video capture in Python on linux?
You should look at Gstreamer and its Python bindings. Here http://pygstdocs.berlios.de/pygst-tutorial/webcam-viewer.html is some sample code to display video from a webcam. To record the video you would have to change the pipeline definition from autovideosink
to an encoder and filesink.
Related Topics
Change The Default Find-Grep Command in Emacs
Exploiting a String-Based Overflow on X86-64 with Nx (Dep) and Aslr Enabled
How Syscall Knows Where to Jump
Driver Ch341 Usb Adapter Serial Port or Qserialport Not Works in Linux
Compile Swift Code to Native Executable for Linux
What Is The Safest Way to Empty a Directory in *Nix
How to Set Pthread CPU Affinity in Os X
How to Set Folder Permissions for a Particular Container on Elastic Beanstalk
Check The Output of "Make" and Exit Bash Script If It Fails
Building Helloworld C++ Program in Linux with Ncurses
Deleting Content of Folder with Shell Script
Linux Async (Io_Submit) Write V/S Normal (Buffered) Write
How to Write a Bash Script That Cuts Images into Pieces Using Image Magick