Video Capture on Linux

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



Leave a reply



Submit