OpenCV: Difference between revisions
(→Usage) |
No edit summary |
||
Line 1: | Line 1: | ||
OpenCV is a very popular computer vision and image processing library for Python | OpenCV is a very popular computer vision and image processing library.<br> | ||
There are bindings for C++, Java, JavaScript, and Python | |||
==Installation== | ==Installation== | ||
Line 15: | Line 16: | ||
# Use 0 to read in grayscale | # Use 0 to read in grayscale | ||
my_image = cv2.imread("my_image.png", 0) | my_image = cv2.imread("my_image.png", 0) | ||
</syntaxhighlight> | |||
==Video== | |||
===Reading Video=== | |||
===Writing Video=== | |||
[https://docs.opencv.org/master/d7/d9e/tutorial_video_write.html C++ Video Write]<br> | |||
Note that OpenCV does not handle audio. | |||
<syntaxhighlight lang="bash"> | |||
output_video = cv2.VideoWriter() | |||
codec = cv2.VideoWriter_fourcc(*"avc1") | |||
fps = 15 | |||
output_video.open("video_output.mp4", codec, fps, face_image_size, True) | |||
if not output_video.isOpened(): | |||
print("Error opening output video") | |||
# Write all of your frames | |||
# while have_frames: | |||
# output_video.write(my_frame) | |||
# Release the video | |||
output_video.release() | |||
</syntaxhighlight> | </syntaxhighlight> | ||
==Resources== | ==Resources== | ||
* [https://docs.opencv.org/master/d6/d00/tutorial_py_root.html OpenCV Tutorial] | * [https://docs.opencv.org/master/d6/d00/tutorial_py_root.html OpenCV Python Tutorial] |
Revision as of 14:02, 12 December 2019
OpenCV is a very popular computer vision and image processing library.
There are bindings for C++, Java, JavaScript, and Python
Installation
- Download Python 3
pip install opencv-python
Usage
Getting Started
import cv2
# Use 0 to read in grayscale
my_image = cv2.imread("my_image.png", 0)
Video
Reading Video
Writing Video
C++ Video Write
Note that OpenCV does not handle audio.
output_video = cv2.VideoWriter()
codec = cv2.VideoWriter_fourcc(*"avc1")
fps = 15
output_video.open("video_output.mp4", codec, fps, face_image_size, True)
if not output_video.isOpened():
print("Error opening output video")
# Write all of your frames
# while have_frames:
# output_video.write(my_frame)
# Release the video
output_video.release()