async def predict_api(file: UploadFile = File(...)): extension = file.filename.split(".")[-1] in ("jpg", "jpeg", "png") if not extension: return "Image must be jpg or png format!" image = read_imagefile(await file.read()) prediction = frc.classify_face(image) return prediction
async def upload_image(file: UploadFile=File(...)): contents = await file.read() nparr = np.fromstring(contents, np.uint8) img = cv2.imdecode(nparr, cv2.IMREAD_COLOR) matched_image = frc.classify_face(img) #print("hii") img = cv2.imread('matched_image.png') # return frc.classify_face(img) return FileResponse("matched_image.png", media_type='application/octet-stream',filename="matched_image.png")
def snapshot(self): # Get a frame from the video source ret, frame = self.vid.get_frame() print(classify_face(frame)) if ret: cv2.imwrite( "snapshot/IMG-" + time.strftime("%d-%m-%Y-%H-%M-%S") + ".jpg", cv2.cvtColor(frame, cv2.COLOR_RGB2BGR))
def home(): if request.method == "POST": if request.files: image = request.files["image"] print(image) image.save( os.path.join(app.config["IMAGE_UPLOADS"], image.filename)) names = classify_face(image.filename) os.remove(image.filename) return render_template("response.html", names=names) return render_template("index.html")
def Facereco(): file = request.files['image_url'] if file == '': response = jsonify({'message': 'gambar belum di upload'}) response.status_code = 400 return response if allowed_file(file.filename) == True: file_name = secure_filename(file.filename) file.save(os.path.join('images/', file_name)) path_image = 'images/' + file_name data = classify_face(path_image) response = {'status': True, 'name': data} return jsonify(response)
def who_is(message): if message.photo != None: print("Новое фото! Скачиваю...") file_id = message.json['photo'][0]['file_id'] file = bot.get_file(file_id) downloaded_file = bot.download_file(file.file_path) src = (f"download/{file_id}.jpg") with open(src, 'wb') as new_file: new_file.write(downloaded_file) print("Файл загружен.") people = [] ans = "" for person in classify_face(src): if person == "Unknown": sended_msg = bot.send_message(message.chat.id, 'Я не знаю этого человека.\nСкажи мне как его называть, чтобы я запомнил его, или напиши "Отмена".') bot.register_next_step_handler(sended_msg, set_name, downloaded_file) else: ans = ans + person + "\n" if ans != "": bot.send_message(message.chat.id, (f"Это {ans}")) else: bot.send_message(message.chat.id, "Это не фото 🤠")
def recog(self): ret, frame = self.vid.get_frame() print(classify_face(frame))
frame75 = rescale_frame(frame, percent=75) gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray, scaleFactor=1.2, minNeighbors=5) for (x, y, w, h) in faces: #print(x,y,w,h) roi_gray = gray[y:y + h, x:x + w] #(ycord_start, ycord_end) roi_color = frame[y:y + h + 50, x:x + w + 50] img_item = "sample.jpg" cv2.imwrite(img_item, roi_color) color = (255, 0, 0) #BGR 0-255 stroke = 2 end_cord_x = x + w + 50 end_cord_y = y + h + 50 cv2.rectangle(frame, (x, y), (end_cord_x, end_cord_y), color, stroke) # Display the resulting frame cv2.imshow('frame', frame) classify_face("sample.jpg") if cv2.waitKey(20) & 0xFF == ord('q'): break # When everything done, release the capture cap.release() cv2.destroyAllWindows()
Bot.speak("If u have issues u can press the emergency button for help") if UART.interrupt_check(): tour.alert() clientName = Bot.listen() for name in f_names: if name == clientName: # in the name list UART.open_gate() client_id = sql.read_where('ID', f'F_name = {name}') log(client_id, coming_plate) time.sleep(10) UART.close_gate() else: # not in the name list tour.alert() else: face_id = face_rec.classify_face( 'test_faces/test.jpg') # take face photo registered_plate_id = sql.read_where('ID', f'car_num = {car_num}') if face_id == registered_plate_id: print('opened') UART.open_gate() log(face_id, car_num) else: # num working face not working Bot.speak( "Hello welcome to guardsmarter! your face is not matching the correct plate number, is this your car?" ) carValidate = Bot.listen() # Waiting for yes or no if carValidate == ynList[0]: Bot.speak("Ok, may i have your personal ID number?") clientID = Bot.listen() for cID in ID: if cID == clientID: # ID match