加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main_flask.py 1.68 KB
一键复制 编辑 原始数据 按行查看 历史
QQ技术 提交于 2021-03-19 15:56 . 初始化代码
import face_dll
import face_class
from ctypes import *
import cv2
import face_function as fun
import face_feature_extract
import video_camera
import time
from flask import Flask, abort, request, jsonify, Response
app = Flask(__name__)
Appkey = b'HzvxgWfqcyMDo8HPsgdhbRioWogjqb5Yoa63uWMGfmVU'
SDKey = b'Apr1zXT5pAJuMsoegfM9NN4hKG6C1BPgGpG5Raab37uo'
'''
存放人脸库的信息,key为对应的图片名即为1.jpg或者2.jpg
'''
faceInfos = {'1':{'name':'Ju Jingyi','gender':'girl','age':'25','image':'images/1.jpg'},'2':{'name':'Ju Jingyi','gender':'girl','age':'25','image':'images/2.jpg'}}
'''
激活sdk,激活一次即可
'''
def active():
ret = fun.active(Appkey, SDKey)
if ret == 0 or ret == 90114:
print('激活成功:', ret)
else:
print('激活失败:', ret)
pass
def init():
# 初始化 1 视频(0x00000000)或图片(0xFFFFFFFF)模式,
ret = fun.init(0x00000000)
if ret[0] == 0:
print('初始化成功:', ret, '句柄', fun.Handle)
else:
print('初始化失败:', ret)
def gen():
videoCamera = video_camera.VideoCamera(faceFeatures, faceInfos)
while True:
ret, frame = videoCamera.get_frame()
if ret:
yield (b'--frame\r\n'b'Content-Type: image/jpeg\r\n\r\n' + frame.tobytes() + b'\r\n\r\n')
time.sleep(0.1)
'''
返回图片流
'''
@app.route('/video_feed/')
def video_feed():
return Response(gen(),mimetype='multipart/x-mixed-replace; boundary=frame')
if __name__ == "__main__":
active()
# 加载人脸资源
faceFeatures = face_feature_extract.load_face_feature(faceInfos)
init()
app.run(host="0.0.0.0", port=8080, debug=True, threaded=True, processes=True)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化