【发布时间】:2017-10-10 19:29:45
【问题描述】:
我刚得到一个高端 1080p 网络摄像头,在 Windows 10 的“相机”应用程序中打开它,以 25 或 30fps 的速度完美显示它,但是当使用 opencv 时它非常滞后,我在循环中设置了一个计时器,同时禁用了显示每帧之间我有大约 200 毫秒。
为什么?
import numpy as np
import cv2
import time
def getAvailableCameraIds(max_to_test):
available_ids = []
for i in range(max_to_test):
temp_camera = cv2.VideoCapture(i)
if temp_camera.isOpened():
temp_camera.release()
print "found camera with id {}".format(i)
available_ids.append(i)
return available_ids
def displayCameraFeed(cameraId, width, height):
cap = cv2.VideoCapture(cameraId)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
while(True):
start = time.time()
ret, frame = cap.read()
rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
end = time.time()
print "time to read a frame : {} seconds".format(end-start)
#DISABLED
#cv2.imshow('frame', frame)
#if cv2.waitKey(1) & 0xFF == ord('q'):
#break
cap.release()
cv2.destroyAllWindows()
#print getAvailableCameraIds(100)
displayCameraFeed(0, 1920, 1080)
谢谢
Windows 10 x64 上的 Opencv 3.1,带有 python 2.7 x64
【问题讨论】:
-
你的系统有什么CPU? Python 在解释器中运行,因此比 Windows 网络摄像头查看器所具有的编译代码慢得多。
-
i7 4720HQ@2.6Ghz
-
我怀疑这与它在 python 上运行的事实有关,这篇文章可能会对您有所帮助:Faster video file FPS with cv2.VideoCapture and OpenCV
-
好吧,明天我会在我的桌面上试试,它有更强大的硬件,我会用 C++ 试试
-
@Totoro : 我看不出这里的线程会有什么帮助,原子操作 '.read()' 需要 200 毫秒
标签: python python-2.7 opencv webcam