python 网络摄像头 检测行为_此网络摄像头面部检测有什么问题?

from__future__importdivisionimportsysfromtimeimporttime,sleepimportthreadingimportdlibfromskimageimportiodetector=dlib.get_frontal_face_detector()win=dlib.image_window()classwebCamGrabber(threading.Thread):def__init__(self):threading.Thread.__init__(self)#Lock for when you can read/write self.image:#self.imageLock = threading.Lock()self.image=Falsefromcv2importVideoCapture,cvfromtimeimporttimeself.cam=VideoCapture(0)#set the port of the camera as before#self.cam.set(cv.CV_CAP_PROP_FPS, 1)defrun(self):whileTrue:start=time()#self.imageLock.acquire()retval,self.image=self.cam.read()#return a True bolean and and the image if all go rightprint(type(self.image))#import matplotlib.pyplot as plt#plt.imshow(image)#plt.show()#print( "readimage: " + str( time() - start ) )#sleep(0.1)iflen(sys.argv[1:])==0:#Start webcam reader thread:camThread=webCamGrabber()camThread.start()#Setup window for resultsdetector=dlib.get_frontal_face_detector()win=dlib.image_window()whileTrue:#camThread.imageLock.acquire()ifcamThread.imageisnotFalse:print("enter")start=time()myimage=camThread.imageforrowinmyimage:forpxinrow:#rgb expected... but the array is bgr?r=px[2]px[2]=px[0]px[0]=rdets=detector(myimage,0)#camThread.imageLock.release()print"your faces: %f"%len(dets)fori,dinenumerate(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(camThread.image[0])))print("from top: {}".format(((d.top()+d.bottom())/2)/len(camThread.image)))print("process: "+str(time()-start))start=time()win.clear_overlay()win.set_image(myimage)win.add_overlay(dets)print("show: "+str(time()-start))#dlib.hit_enter_to_continue()forfinsys.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)))fori,dinenumerate(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)fori,dinenumerate(dets):print("Detection {}, score: {}, face_type:{}".format(d,scores[i],idx[i]))

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值