OpenCV之视频读写

Posted MachineLP

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OpenCV之视频读写相关的知识,希望对你有一定的参考价值。

python代码:

import cv2 as cv
import numpy as np


capture = cv.VideoCapture("./test.avi")
# capture = cv.VideoCapture(0) 打开摄像头
height = capture.get(cv.CAP_PROP_FRAME_HEIGHT)
width = capture.get(cv.CAP_PROP_FRAME_WIDTH)
count = capture.get(cv.CAP_PROP_FRAME_COUNT)
fps = capture.get(cv.CAP_PROP_FPS)
print(height, width, count, fps)
out = cv.VideoWriter("./test_cp.avi", cv.VideoWriter_fourcc(\'D\', \'I\', \'V\', \'X\'), 15,
                     (np.int(width), np.int(height)), True)
while True:
    ret, frame = capture.read()
    if ret is True:
        cv.imshow("video-input", frame)
        out.write(frame)
        c = cv.waitKey(50)
        if c == 27: # ESC
            break
    else:
        break

capture.release()
out.release()

C++代码:

#include<opencv2/opencv.hpp>
#include<iostream>

using namespace 

以上是关于OpenCV之视频读写的主要内容,如果未能解决你的问题,请参考以下文章

OpenCV-视频读写(java版)

OpenCV读写视频

OpenCV读写视频

OpenCV对视频读写播放

OpenCV之图像像素读写

opencv--视频操作