Intelligent mirror design based on Dragonboard 410c (5) - user identification through human face

According to the previous design scheme, in the design of the dragon mirror 410c-based smart mirror, it is necessary to collect the face data through the USB camera according to the ultrasonic detection when the person approaches, and then perform face matching and recognition according to the face data in the database. The identity of the user, ultimately displaying different messages and pushing different content according to the user's identity, this blog will focus on the principle and process of face detection and recognition processing in the smart mirror.

Need to perform face-based user identification, first need to detect the face, and then according to the detected face and the face in the database to match, and finally get the matching degree, according to the matching degree to determine the identity of the face, here From these two aspects, we will introduce how to implement face identity detection in smart mirrors. In fact, in the previous series of blogs, we have introduced the implementation method of face recognition and detection. Here we are combining intelligent magic. The mirror code design will show you how to apply the previously designed face detection and recognition code to focus on the application in the smart mirror.

In the article based on USB camera face recognition, I have already told everyone how to use Python and OpenCV to build face detection code. We have built a getFac.py file in this file to detect face by getFac class. In fact, it is a package of the previous blog method, the specific code is as follows:

Def getface(self,device):
Cap = cv2.VideoCapture(device)
Faces=[]
Num=self.maxFrames
While(True):
Ret, img=cap.read()
Ret, img=cap.read()
Ret, img=cap.read()
Ret, img=cap.read()
If ret==True:
Gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
Faces = self.face_cascade.detectMulTIScale(gray,1.3,5)
i=0
For(x,y,w,h) in faces:
Face=img[y:y+h,x:x+w]
Print("get face sucessful")
Cap.release()
Cv2.imwrite('./temp.jpg',face)
Return True
Num=num-1
If num==0:
Print("get face failed")
Cap.release()
Return False
Else:
Cap.release()
Return False

With the above class, we can detect and obtain the face image. Next we need to use the detected face image to match the face image in the database to realize the face recognition. The method and the front use USB camera. The face recognition article--the second method is the same as the face recognition interface provided by opencv, but here to rewrite the previous blog method in order to call in the magic mirror, build a peopleIdenTIficaTIon.py class To realize the face identity detection in the magic mirror, a peopleDetected class is encapsulated here to realize the face recognition. The code after re-encapsulation is slightly different from the previous code. The specific design is as follows:

Class peopleDetected:
Def __init__(self,trainImgPath):

Self.threshold=6000
Self.model = cv2.createFisherFaceRecognizer()
self.trainModel('./usrImg')
#load all user img create Train table
#imgPath is user img path
Def trainModel(self,trainImgPath):
Names=[]
Lables=[]
userImgDir=os.listdir(trainImgPath)
#print(userImgDir)
For imgDir in userImgDir:
Print("userID dir is:")
#print(imgDir)
Format="%s/%s"
Values=(trainImgPath,imgDir)
dirPath=format % values
#find current user img
allimgPath=os.listdir(dirPath)
#print(allimgPath)
For name in allimgPath:
Names.append(dirPath+'/'+name)
Lables.append(int(imgDir))
Print("save sucessful:")
Print(names)
Print(lables)
#return names,lables
trainImg=[]
For imgloadPath in names:
Obj=cv2.resize(cv2.imread(imgloadPath,0),(400,500))
trainImg.append(obj)
Self.model.train(trainImg,np.array(lables))
Print(lables)
Def getPeopleID(self, faceImgPath):
faceImg=cv2.imread(faceImgPath,0)
Face=cv2.resize(faceImg,(400,500))
Result = self.model.predict(face)
predicTID=result[0]
predictError=result[1]
Print(predictID)
Print(predictError)
#print(result)
If predictError>self.threshold:
Return -1
Else:
Print("get people ID")
Return predictID
Def getPeopleID2(self, faceImg):
Face=cv2.resize(faceImg,(400,500))
Result = self.model.predict(face)
predictID=result[0]
predictError=result[1]
#print(predictID)
#print(predictError)
#print(result)
If predictError>self.threshold:
Return -1
Else:
Return predictID

With these two classes, we can easily construct the face recognition sub-module of the mirror. Here we only need to use face detection and face recognition by the following code:

GF=getFace()

Rs=GF.getface(0)

PD=peopleDetected("./usrImg")

peopleID=PD.getPeopleID('./temp.jpg')

In the process of constructing the PD, the user information in ./userImg is imported as training data.

Each detected face is saved in ./temp.jpg.

The follow-up blog will further introduce how to use the above two classes, and complete the face identity detection and preservation of the entire mirror based on the ultrasonic detection results.

Mono Solar Panels 150-180w

150 Watt Solar Panel,Suntech Mono Solar Panel,Mono Cell Solar Panels,Lg Mono Solar Panel

Zhejiang G&P New Energy Technology Co.,Ltd , https://www.solarpanelgp.com

Posted on