This code i write on python 3 and open cv3.but its can't show text "Unkonw" from unknow id.
Contact: scoutrider6@gmail.com
....Thank you....
import cv2
import numpy as np
import os
def assure_path_exists(path):
dir = os.path.dirname(path)
if not os.path.exists(dir):
os.makedirs(dir)
ret,img=cam.read()
#เก็บภาพในรูปแบบขาว-ดำ
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
#เก็บค่าใบหน้า
faces=faceDetect.detectMultiScale(gray,1.2,5)
for(x,y,w,h) in faces:
cv2.rectangle(img,(x-20,y-20),(x+w+20,y+h+20),(0,0,255),4)
Id,confidence=recognizer.predict(gray[y:y+h,x:x+w])
if(Id == 1):
Id = "Pensit {0:.2f}%".format(round(100-confidence,2))
#กรอบบนตัวอักษรcv2.rectangle(img,(x-22,y-90),(x+w+22,y-22),(0,255,0),-1)
#cv2.putText(img,str(Id),(x,y-40),font,1,(0,255,0),1)
#cv2.putText(img,'Pensit',(x,y),font,1,255,2)
elif(Id == 2):
Id = "Maneenuch {0:.2f}%".format(round(100-confidence,2))
# cv2.putText(img,str(Id),(x,y-40),font,1,(0,255,0),1)
elif(Id == 3):
Id = "Boonraksa {0:.2f}%".format(round(100-confidence,2))
# cv2.putText(img,str(Id),(x,y-40),font,1,(0,255,0),1)
**else: <-----This problem it's can't show text "unknow" for unknow id. but it's show text in id1**
Id = "Unknow {0:.2f}%".format(round(100-confidence,2))
cv2.putText(img,str(Id),(x,y-40),font,1,(0,255,0),1)
cv2.imshow("FaceRecognizer",img);
if cv2.waitKey(10)& 0xFF==ord('q'):
break
This code i write on python 3 and open cv3.but its can't show text "Unkonw" from unknow id. Contact: scoutrider6@gmail.com ....Thank you.... import cv2 import numpy as np import os
def assure_path_exists(path): dir = os.path.dirname(path) if not os.path.exists(dir): os.makedirs(dir)
ดึงข้อมูลมากจากLibary opev cv
faceDetect=cv2.CascadeClassifier('haarcascade_frontalface_default.xml');
ใช้กล้อง
cam=cv2.VideoCapture(0);
สร้างไบนารี่
recognizer=cv2.face.LBPHFaceRecognizer_create(); assure_path_exists("recognizer\")
ดึงข้อมูลมาจากไฟล์ Data
recognizer.read('recognizer\OneData.yml')
กำหนดตัวอักษร
font=cv2.FONT_HERSHEY_COMPLEX_SMALL
โปรแกรม(Loop)
while True:
กล้องอ่านค่า
cam.release() cv2.destroyAllWindows()