python 用opencv调用训练好的模型进行识别的方法
程序员文章站
2022-05-02 11:29:06
此程序为先调用opencv自带的人脸检测模型,检测到人脸后,再调用我自己训练好的模型去识别人脸,使用时更改模型地址即可
#!usr/bin/env python...
此程序为先调用opencv自带的人脸检测模型,检测到人脸后,再调用我自己训练好的模型去识别人脸,使用时更改模型地址即可
#!usr/bin/env python import cv2 font=cv2.font_hershey_simplex cascade1 = cv2.cascadeclassifier("d:\\opencv249\\opencv\\sources\\data\\haarcascades\\haarcascade_frontalface_alt_tree.xml") cascade2 = cv2.cascadeclassifier("d:\\opencv249\\opencv\\sources\\data\\haarcascades\\xml.xml") cap = cv2.videocapture(0) while true: ret,frame = cap.read() gray = cv2.cvtcolor(frame,cv2.color_bgr2gray) rect = cascade1.detectmultiscale(gray,scalefactor=1.3,minneighbors=9,minsize=(50,50),flags = cv2.cv.cv_haar_scale_image) if not rect is (): for x,y,z,w in rect: roiimg = gray[y:y+w,x:x+z] rect1 = cascade2.detectmultiscale(roiimg,scalefactor=1.3,minneighbors=9,minsize=(50,50),flags = cv2.cv.cv_haar_scale_image) if not rect1 is (): for (a,b,c,d) in rect1: print "rect",rect1 cv2.puttext(frame,'chenym',(x,y), font, 2,(0,0,255),2) cv2.rectangle(frame,(x+a,y+b),(x+a+c,y+b+d),(0,0,255),2) cv2.imshow('frame',frame) if cv2.waitkey(1) &0xff == ord('q'): break cap.release() cv2.destroyallwindows()
以上这篇python 用opencv调用训练好的模型进行识别的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。