Skip to content

关于读取摄像头数据帧卡顿问题 #1

Description

@oule

你好朋友,我在树莓派3B+上编译了opencv-4.1.0版,用如下代码获取数据帧时只能得到不超过每秒10帧的数据,用imshow显示就是卡顿,摄像头是720P的,而且在windows10中用系统自带的照相机程序录制可以达到每秒接近30帧,这明显不是摄像头问题,是我代码写的有问题,还是树莓派硬件性能不行,望赐教。代码如下:

import cv2
import time

cap=cv2.VideoCapture(0)
cap.set(6,cv2.VideoWriter_fourcc(*'MJPG'))
cap.set(3,1280)
cap.set(4,720)
cap.set(5,30)
print cap.get(3)
print cap.get(4)
print cap.get(5)
count=0
t=int(time.time())
while True:
    ret,frame=cap.read()
    if ret:
        if int(time.time())-t==0:
            count+=1
        else:
            print("%s: %s" % ('fps',count))
            count=0
    t=int(time.time())

运行结果输出:

1280.0
720.0
30.0
fps: 0
fps: 6
fps: 10
fps: 10

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions