本文主要是介绍【图像处理】如何获取30FPS的1080P视频流,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
使用Logitech摄像头进行视频数据采集,发现在OpenCV中只能获取到5FPS的1080P数据。如果设置为30FPS,所获取到的分辨率会自动修改为640*480。原因在于摄像头默认的编码方式。
1.获取当前设备
$ lsusb
$ ls /dev/video*
下载luvcview,安装
sudo dpkg -i *.deb
查看设备信息
luvcview -d /dev/video0 -L
输出格式
Device information:Device path: /dev/video0
{ pixelformat = 'YUYV', description = 'YUYV 4:2:2' }
{ discrete: width = 640, height = 480 }Time interval between frame: 1/30, 1/24, 1/20, 1/15, 1/10, 2/15, 1/5,
{ discrete: width = 160, height = 90 }Time interval between frame: 1/30, 1/24, 1/20, 1/15, 1/10, 2/15, 1/5,
...
表示在不同的视频格式下面,帧于帧之间的时间差。
2.测试
直接将获取到的视频分辨率设置为1920*1080,测试时间。
import cv2
import timecap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)while True:time1 = time.time()ret, frame = cap.read()time2 = time.time()print('Frame time is: ', time2 - time1)if cv2.waitKey(1) & 0xFF == ord('q'):breakcap.release()
cv2.destroyAllWindows()
测试结果为:
Frame time is: 0.1978147029876709
Frame time is: 0.20276236534118652
Frame time is: 0.1972665786743164
Frame time is: 0.19614434242248535
Frame time is: 0.19997501373291016
...
大约是每秒钟五帧。
修改编码格式(使用OpenCV的Fourcc)
import cv2
import timecap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter.fourcc('M', 'J', 'P', 'G'))
while True:time1 = time.time()ret, frame = cap.read()time2 = time.time()print('Frame time is: ', time2 - time1)if cv2.waitKey(1) & 0xFF == ord('q'):breakcap.release()
cv2.destroyAllWindows()
再次测试速度:
Frame time is: 0.03886866569519043
Frame time is: 0.027163267135620117
Frame time is: 0.0348970890045166
Frame time is: 0.040320634841918945
Frame time is: 0.03423023223876953
Frame time is: 0.02848196029663086
Frame time is: 0.04337716102600098
Frame time is: 0.027630090713500977
Frame time is: 0.022168397903442383
...
这篇关于【图像处理】如何获取30FPS的1080P视频流的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!