“Video di Python tanpa CV2” Kode Jawaban

cara membaca video di 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()
Disturbed Dove

Video di Python tanpa CV2

def read_frames(path, res):
    """Read numpy arrays of video frames. Path is the file path
       and res is the resolution as a tuple."""
    args = [
        "ffmpeg",
        "-i",
        path,
        "-f",
        "image2pipe",
        "-pix_fmt",
        "rgb24",
        "-vcodec",
        "rawvideo",
        "-",
    ]

    pipe = subprocess.Popen(
        args,
        stdout=subprocess.PIPE,
        stderr=subprocess.DEVNULL,
        bufsize=res[0] * res[1] * 3,
    )

    while pipe.poll() is None:
        frame = pipe.stdout.read(res[0] * res[1] * 3)
        if len(frame) > 0:
            array = np.frombuffer(frame, dtype="uint8")
            yield array.reshape((res[1], res[0], 3))
Vasilije Dimitrijevic

Jawaban yang mirip dengan “Video di Python tanpa CV2”

Pertanyaan yang mirip dengan “Video di Python tanpa CV2”

Lebih banyak jawaban terkait untuk “Video di Python tanpa CV2” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya