opencv设置采集视频分辨率方式

yipeiwu_com7年前Python基础

如下所示:

#include <opencv2\opencv.hpp> 
 
#include<ctime>
using namespace cv; 
using namespace std;
 
int main( ) 
{ 
	//【1】从摄像头读入视频
	VideoCapture capture(0);
 
	//【2】循环显示每一帧
	int j=0;
 
	 capture.set(CV_CAP_PROP_FRAME_WIDTH, 1080); 
  capture.set(CV_CAP_PROP_FRAME_HEIGHT,720); 
	while(1&&(j<100)) 
	{  clock_t start,finish;
    start=clock();
		j++;
		Mat frame; //定义一个Mat变量,用于存储每一帧的图像
		capture>>frame; //读取当前帧
		imshow("读取视频",frame); //显示当前帧
		cout<<frame.size()<<endl;
		imwrite("1.jpg",frame);
		finish=clock();
 
    cout << finish-start  << "/" << CLOCKS_PER_SEC << " (s) "<< endl;
		waitKey(1); //延时30ms
	} 
	return 0;   
} 

摄像头要支持设置不同的分辨率。

1920x1080采集用时0.1s。

1080x720采集用时0.04s。

640x480采集用时0.02s。

以上这篇opencv设置采集视频分辨率方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python模块常用用法实例详解

1、time模块(※※※※) import time #导入时间模块 print(time.time()) #返回当前时间的时间戳,可用于计算程序运行时间 print(time.l...

Pytorch释放显存占用方式

如果在python内调用pytorch有可能显存和GPU占用不会被自动释放,此时需要加入如下代码 torch.cuda.empty_cache() 我们来看一下官方文档的说明 Relea...

python range()函数取反序遍历sequence的方法

python中的range函数取反序有两种方式 第一种:先构建一个列表,然后对列表中的元素进行反转。 例如: a=range(5) for i in reversed(a):...

python集合用法实例分析

本文实例讲述了python集合用法。分享给大家供大家参考。具体分析如下: # sets are unordered collections of unique hashable el...

Queue 实现生产者消费者模型(实例讲解)

Python中,队列是线程间最常用的交换数据的形式。 Python Queue模块有三种队列及构造函数: 1、Python Queue模块的FIFO队列先进先出。 class Queue...