Answers for "play video with opencv python"

7

how to read video in opencv python

import numpy as np
import cv2
cap = cv2.VideoCapture('videos/wa.avi')
while(cap.isOpened()):
  ret, frame = cap.read()
  gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  cv2.imshow('frame',gray)
  if cv2.waitKey(1) & 0xFF == ord('q'):
    break

cap.release()
cv2.destroyAllWindows()
Posted by: Guest on June-18-2020
0

read video opencv python

import cv2
filename_video = "path_to_your_video"

input_video = cv2.VideoCapture(filename_video)
if input_video.isOpened() == False:
  print("Video not found")
  sys.exit(1)
else:
  # Read until the video is completed
  while(input_video.isOpened()):
    # Capture frame by frame
    ret, frame = input_video.read()
    if ret == True:
      frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
      cv2.imshow('frame',frame)
    else:
      break
	
  input_video.release()
  cv2.destroyAllWindows()
Posted by: Guest on June-04-2021

Python Answers by Framework

Browse Popular Code Answers by Language