通过 Flask 路由获取人脸识别 python 脚本以响应本机应用程序
GET Face recognition python script via flask route to react native app
I am creating an application using react native and flask as backend. I have various routes in my app.py and another python file for capturing face and recognition. I need to call this file in app.py, cretae route and GET that route(embed) in my react-native frontend. I tried below:
**This is my app.py file where all my routes are configured.**
from flask_restful import Api
from flask_pymongo import PyMongo
from flask import Flask, request, json, Response
from pymongo import MongoClient
from flask import jsonify
import pymongo
import recognition
@app.route('/candidates', methods=['GET'])
def candidates():
cand = mongo.db.Candidates
candidates =[]
candidate = cand.find()
for j in candidate:
j.pop('_id')
candidates.append(j)
print(candidates)
return jsonify(candidates)
@app.route('/getFace', methods=['GET'])
def get_face():
return recognition
但是有了这个,相机会立即启动,然后我的其他路线就不起作用了。有人可以建议我如何实现此流程吗?
[![Folder Structure for Project][1]][1]
[1]: https://i.stack.imgur.com/Att32.png
I managed to achieve this as follow:
1. Capture face via video/camera from react native and post to flask as file.
2. Create a python script with opencv face recognition which will accept video/image from frontend and save as frames while returning count of frames and identified face names.
3.In app.py file create an api to call the script file and check the return value and send response based on the values returned.
import auth. //auth is the recognition script
@app.route('/getFace', methods=['POST'])
def get_face():
frame = request.files['frame']
print(frame)
face_names = auth.face_rec()
if(face_names):
message = "FACE FOUND"
print(message)
return message
else:
message = "FACE NOT FOUND"
print(message)
return message
I am creating an application using react native and flask as backend. I have various routes in my app.py and another python file for capturing face and recognition. I need to call this file in app.py, cretae route and GET that route(embed) in my react-native frontend. I tried below:
**This is my app.py file where all my routes are configured.**
from flask_restful import Api
from flask_pymongo import PyMongo
from flask import Flask, request, json, Response
from pymongo import MongoClient
from flask import jsonify
import pymongo
import recognition
@app.route('/candidates', methods=['GET'])
def candidates():
cand = mongo.db.Candidates
candidates =[]
candidate = cand.find()
for j in candidate:
j.pop('_id')
candidates.append(j)
print(candidates)
return jsonify(candidates)
@app.route('/getFace', methods=['GET'])
def get_face():
return recognition
但是有了这个,相机会立即启动,然后我的其他路线就不起作用了。有人可以建议我如何实现此流程吗?
[![Folder Structure for Project][1]][1]
[1]: https://i.stack.imgur.com/Att32.png
I managed to achieve this as follow:
1. Capture face via video/camera from react native and post to flask as file.
2. Create a python script with opencv face recognition which will accept video/image from frontend and save as frames while returning count of frames and identified face names.
3.In app.py file create an api to call the script file and check the return value and send response based on the values returned.
import auth. //auth is the recognition script
@app.route('/getFace', methods=['POST'])
def get_face():
frame = request.files['frame']
print(frame)
face_names = auth.face_rec()
if(face_names):
message = "FACE FOUND"
print(message)
return message
else:
message = "FACE NOT FOUND"
print(message)
return message