加强版十六章视频读写

VideoCapture capture(0)用来打开系统摄像头



#include<opencv2/opencv.hpp>

#include<iostream>

using namespace std;

using namespace cv;

int main(int argv, char** argc) {

VideoCapture capture(0);

if (!capture.isOpened()) {

printf("0");

}

namedWindow("frame", WINDOW_AUTOSIZE);

Mat frame;

while (true) {

bool ret = capture.read(frame);

if (!ret)break;

imshow("ret", frame);

char c = waitKey(50);

if (c == 27) {

break;

}

}

waitKey(0);

destroyAllWindows();

}
读取摄像头



读取视频文件

获取帧数等信息

#include<opencv2/opencv.hpp>

#include<iostream>

using namespace std;

using namespace cv;

int main(int argv, char** argc) {

//VideoCapture capture(0);

VideoCapture capture("C:/newword/image/20.avi");

if (!capture.isOpened()) {

printf("0");

}

namedWindow("frame", WINDOW_AUTOSIZE);

int fps = capture.get(CAP_PROP_FPS);

int width = capture.get(CAP_PROP_FRAME_WIDTH);

int heigh = capture.get(CAP_PROP_FRAME_HEIGHT);

int num_of_frame = capture.get(CAP_PROP_FRAME_COUNT);

printf("frame size(f=%d,w=%d,h=%d,m=%d)", fps, width, heigh, num_of_frame);

Mat frame;

while (true) {

bool ret = capture.read(frame);

if (!ret)break;

imshow("ret", frame);

char c = waitKey(50);

if (c == 27) {

break;

}

}

waitKey(0);

destroyAllWindows();

}



读取视频文件或摄像头,将读取视频的保存

#include<opencv2/opencv.hpp>

#include<iostream>

using namespace std;

using namespace cv;

int main(int argv, char** argc) {

VideoCapture capture(0);

//VideoCapture capture("C:/newword/image/20.avi");

if (!capture.isOpened()) {

printf("0");

}

namedWindow("frame", WINDOW_AUTOSIZE);

int fps = capture.get(CAP_PROP_FPS);

int width = capture.get(CAP_PROP_FRAME_WIDTH);

int heigh = capture.get(CAP_PROP_FRAME_HEIGHT);

int num_of_frame = capture.get(CAP_PROP_FRAME_COUNT);

int type = capture.get(CAP_PROP_FOURCC);

printf("frame size(f=%d,w=%d,h=%d,m=%d)", fps, width, heigh, num_of_frame);

Mat frame;

VideoWriter writer("C:/newword/image/232320.mp4", type, fps, Size(width, heigh), true);

while (true) {

bool ret = capture.read(frame);

if (!ret)break;

imshow("ret", frame);

writer.write(frame);

char c = waitKey(50);

if (c == 27) {

break;

}

}

waitKey(0);

destroyAllWindows();

}

相关推荐
Blossom.1182 小时前
机器学习在智能供应链中的应用:需求预测与物流优化
人工智能·深度学习·神经网络·机器学习·计算机视觉·机器人·语音识别
叶子爱分享11 小时前
计算机视觉与图像处理的关系
图像处理·人工智能·计算机视觉
cver12311 小时前
野生动物检测数据集介绍-5,138张图片 野生动物保护监测 智能狩猎相机系统 生态研究与调查
人工智能·pytorch·深度学习·目标检测·计算机视觉·目标跟踪
kyle~13 小时前
目标检测在国防和政府的应用实例
人工智能·目标检测·计算机视觉
Akttt14 小时前
【T2I】R&B: REGION AND BOUNDARY AWARE ZERO-SHOT GROUNDED TEXT-TO-IMAGE GENERATION
人工智能·深度学习·计算机视觉·text2img
jndingxin15 小时前
OpenCV CUDA模块设备层-----反向二值化阈值处理函数thresh_binary_inv_func()
人工智能·opencv·计算机视觉
jndingxin16 小时前
OpenCV CUDA模块设备层-----在 GPU 上执行类似于 std::copy 的操作函数warpCopy()
人工智能·opencv·计算机视觉
晓131316 小时前
OpenCV篇——项目(二)OCR文档扫描
人工智能·python·opencv·pycharm·ocr
jndingxin17 小时前
OpenCV CUDA模块设备层-----在GPU 上高效地执行两个 uint 类型值的最大值比较函数vmax2()
人工智能·opencv·计算机视觉
顾道长生'18 小时前
(Arxiv-2024)自回归模型优于扩散:Llama用于可扩展的图像生成
计算机视觉·数据挖掘·llama·自回归模型·多模态生成与理解