Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
oule opened this issue Jul 4, 2019 · 1 comment
Open

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

oule opened this issue Jul 4, 2019 · 1 comment

Comments

@oule
Copy link

oule commented Jul 4, 2019

你好朋友,我在树莓派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
@Yonv1943
Copy link
Owner

Yonv1943 commented Sep 7, 2019

有两个问题。

问题1,你使用的是单线程,而我的方法是多线程。
First, you use single thread, and my method in GitHub using Python 'multiprocessing'.
上面的代码所示的方法是单线程的,这是官网的写法,不是我提供的多线程版本。
我用Python 自带的 multiprocessing 实现了多线程。多线程比单线程快。

问题2,你没有展示你的网络利用率。
Second, you should check your network utilization.
此外,你能否查看 【摄像机】→【处理设备】 之间的传输情况。
很多人的性能瓶颈都在【网络传输】上,与代码无关。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants