def predit_face(faces, clf, pca): """uses facial recognition model to predict the user's name" inputs: faces - list of detected faces clf - facial recognition classifier pca - Principle component analysis used for classifying faces""" cropped = followDot.cropImage(frame, faces) reshaped = manipulateImage(cropped) X_test_pca = pca.transform([reshaped]) number = clf.predict(X_test_pca) with open("nameToNumber.txt", "r") as inf: numberToName = eval(inf.read()) name = numberToName[number[0]] return name
pitches = [] running = True while running == True: # reads camera ret, frame = camera.read() # detects faces faces = face_cascade.detectMultiScale(frame, scaleFactor=1.2, minSize=(20, 20)) # draws rectangle on face for (x, y, w, h) in faces: cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255)) # see if there is a face in the image, enter try if there is if len(faces) > 0: cropped = followDot.cropImage(frame, faces) reshaped = manipulateImage(cropped) yaw, pitch = ridgeRegression.ridge_predict([reshaped], ridge) yaws.append(yaw) pitches.append(pitch) plt.scatter(yaws, pitches) previous12values, newYaw, newPitch = updateAverage(previous12values, yaw, pitch) sendToNeato(pub, twist, newYaw, newPitch) else: # When no face is detected, stop neato twist.angular.z = 0 twist.linear.x = 0 pub.publish(twist) # show the camera with face detection square cv2.imshow("frame", frame)