python 网络摄像头 检测行为_python – 这个网络摄像头人脸检测有什么问题?

Dlib有一个非常方便,快速和有效的物体检测程序,我想制作一个类似于示例

here的酷脸部跟踪示例.

广泛支持的OpenCV具有相当快的VideoCapture模块(快照的五分之一秒与1秒或更长时间相比,用于调用唤醒网络摄像头并获取图片的程序).我将它添加到Dlib中的面部检测器Python示例中.

如果您直接显示和处理OpenCV VideoCapture输出,它看起来很奇怪,因为显然OpenCV存储BGR而不是RGB顺序.调整后,它可以工作,但很慢:

from __future__ import division

import sys

import dlib

from skimage import io

detector = dlib.get_frontal_face_detector()

win = dlib.image_window()

if len( sys.argv[1:] ) == 0:

from cv2 import VideoCapture

from time import time

cam = VideoCapture(0) #set the port of the camera as before

while True:

start = time()

retval, image = cam.read() #return a True bolean and and the image if all go right

for row in image:

for px in row:

#rgb expected... but the array is bgr?

r = px[2]

px[2] = px[0]

px[0] = r

#import matplotlib.pyplot as plt

#plt.imshow(image)

#plt.show()

print( "readimage: " + str( time() - start ) )

start = time()

dets = detector(image, 1)

print "your faces: %f" % len(dets)

for i, d in enumerate( dets ):

print("Detection {}: Left: {} Top: {} Right: {} Bottom: {}".format(

i, d.left(), d.top(), d.right(), d.bottom()))

print("from left: {}".format( ( (d.left() + d.right()) / 2 ) / len(image[0]) ))

print("from top: {}".format( ( (d.top() + d.bottom()) / 2 ) /len(image)) )

print( "process: " + str( time() - start ) )

start = time()

win.clear_overlay()

win.set_image(image)

win.add_overlay(dets)

print( "show: " + str( time() - start ) )

#dlib.hit_enter_to_continue()

for f in sys.argv[1:]:

print("Processing file: {}".format(f))

img = io.imread(f)

# The 1 in the second argument indicates that we should upsample the image

# 1 time. This will make everything bigger and allow us to detect more

# faces.

dets = detector(img, 1)

print("Number of faces detected: {}".format(len(dets)))

for i, d in enumerate(dets):

print("Detection {}: Left: {} Top: {} Right: {} Bottom: {}".format(

i, d.left(), d.top(), d.right(), d.bottom()))

win.clear_overlay()

win.set_image(img)

win.add_overlay(dets)

dlib.hit_enter_to_continue()

# Finally, if you really want to you can ask the detector to tell you the score

# for each detection. The score is bigger for more confident detections.

# Also, the idx tells you which of the face sub-detectors matched. This can be

# used to broadly identify faces in different orientations.

if (len(sys.argv[1:]) > 0):

img = io.imread(sys.argv[1])

dets, scores, idx = detector.run(img, 1)

for i, d in enumerate(dets):

print("Detection {}, score: {}, face_type:{}".format(

d, scores[i], idx[i]))

从这个程序的时间输出来看,似乎处理和抓取图片每个都需要五分之一秒,所以你会认为它应该每秒显示一次或两次更新 – 但是,如果你举手,它显示在5秒左右后的网络摄像头视图!

是否有某种内部缓存使其无法抓取最新的网络摄像头图像?我可以调整或多线程网络摄像头输入过程来解决滞后问题吗?这是在带有16GB RAM的Intel i5上.

更新

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值