OpenCV: Difference between revisions

From David's Wiki
No edit summary
Line 27: Line 27:
codec = cv2.VideoWriter_fourcc(*"avc1")
codec = cv2.VideoWriter_fourcc(*"avc1")
fps = 15
fps = 15
output_video.open("video_output.mp4", codec, fps, face_image_size, True)
image_size = (100, 100)
output_video.open("video_output.mp4", codec, fps, image_size, True)
if not output_video.isOpened():
if not output_video.isOpened():
     print("Error opening output video")
     print("Error opening output video")

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
image_size = (100, 100)
output_video.open("video_output.mp4", codec, fps, 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()

Resources