推广 热搜: 未来    中国  企业  服务  政策  公司  快速  上海  设备 

人脸识别

   日期:2024-12-05     作者:caijiyuan    caijiyuan   评论:0    移动:http://xiaoguoguo.dbeile.cn/mobile/news/2674.html
核心提示:from django.shortcuts import render,redirect,reverse from jyapp import models from django.views import View from django.

from django.shortcuts import render,redirect,reverse from jyapp import models from django.views import View from django.http import HttpResponse,JsonResponse

人脸识别

import base64

import random import urllib import http.client

from django.apps import AppConfig from aip import AipFace

from django.db import transaction

class AppConfig(AppConfig): name = ‘jyapp’ APP_ID = ‘16538158’ API_KEY = ‘HZI4cNgG8BGwry0v2GgQPxjm’ SECRECT_KEY = ‘pcPY2QIuNnkS9gFDmjvH0SI7whlb2ml9’ client = AipFace(APP_ID,API_KEY,SECRECT_KEY) client.setConnectionTimeoutInMillis(10005) client.setSocketTimeoutInMillis(10005)

class Index(View): def get(self,request): return render(request,‘contact.html’)

class Regist(View): def get(self,request): return render(request,‘moban_index.html’) def post(self,request): # 获取前端数据 imagecontent = request.POST.get(‘imagecontent’) username = request.POST.get(‘username’) mobile = request.POST.get(‘mobile’) password = request.POST.get(‘password’) if not all([imagecontent,username,mobile,password]): return JsonResponse({‘code’:100,‘result’:‘注册信息不能为空’}) # if mobile_code != mobile_code_right: # return JsonResponse({‘code’:111,‘result’:‘请输入正确的验证码’}) else: # 验证该用户是否存在 user = models.User.objects.filter(mobile=mobile) if user: return JsonResponse({‘code’:123,‘result’:‘该用户已存在,请直接登录’}) else: try: # 引入事务 with transaction.atomic(): # 分割字符串 base_data = imagecontent.split(’,’)[1] # base64解码 base64_decode = base64.b64decode(base_data) # 图片写入本地 with open(‘static/image/’+mobile+’.jpeg’, ‘wb’) as f: f.write(base64_decode) # 添加到mysql数据库 models.User.objects.create( imagecontent = ‘static/image/’+mobile+’.jpeg’, username = username, mobile = mobile, password = password, ) imageType = ‘base64’ groupId = ‘usergroup’ userId = mobile # 加入可选参数 options = {} options[‘user_info’] = username options[‘quality_control’] = ‘NORMAL’ options[‘liveness_control’] = ‘LOW’ result = AppConfig.client.addUser(base_data,imageType,groupId,userId,options) print(result) error_code = result[‘error_code’] if isinstance(error_code,int) and error_code == 0: request.session[‘mobile’] = mobile return JsonResponse({‘code’:200,‘result’:‘注册成功’}) # return JsonResponse({‘result’:‘注册成功’}) else: error = ErrorCode().getErrorInfo(error_code) return JsonResponse({‘result’:’{}’.format(error)}) except: return JsonResponse({‘code’:333,‘result’:‘注册失败’})

class Login(View): def get(self,request): return render(request,‘moban_index.html’) def post(self,request): mobile = request.POST.get(‘mobile’) password = request.POST.get(‘password’) print(mobile,password) if not all([mobile,password]): return JsonResponse({‘code’:100,‘mes’:‘登录信息不完整’}) else: user = models.User.objects.filter(mobile=mobile,password=password) if user: request.session[‘mobile’] = mobile return JsonResponse({‘code’:200,‘mes’:‘登录成功’}) else: return JsonResponse({‘code’:333,‘mes’:‘登录账号或密码错误’})

class Login_face(View): def get(self,request): return render(request,‘moban_index.html’) def post(self,request): imagecontent = request.POST.get(‘imagecontent’) mobile = request.POST.get(‘mobile’) if not all([imagecontent,mobile]): return JsonResponse({‘code’:100,‘result’:‘登录信息不能为空’}) else: user = models.User.objects.filter(mobile=mobile) if not user: return JsonResponse({‘code’:113,‘result’:‘用户不存在’}) else: base_data = imagecontent.split(’,’)[1] imageType = ‘base64’ groupIdList = ‘usergroup’ # 加入可选参数 options = {} options[‘max_user_num’] = 1 options[‘quality_control’] = ‘NORMAL’ options[‘liveness_control’] = ‘LOW’ # options[‘user_id’] = mobile result = AppConfig.client.search(base_data,imageType,groupIdList,options) print(result) error_code = result[‘error_code’] # try: user_id = result[‘result’][‘user_list’][0][‘user_id’] score = result[‘result’][‘user_list’][0][‘score’] if isinstance(error_code,int) and error_code == 0 and user_id == mobile and score >= 90: request.session[‘mobile’] = mobile return JsonResponse({‘code’:200,‘result’:‘快速登录成功’}) else: return JsonResponse({‘code’:111,‘result’:‘快速登录失败’}) # except: # return JsonResponse({‘code’:158,‘result’:‘未检测到人脸’})

本文地址:http://xiaoguoguo.dbeile.cn/news/2674.html    多贝乐 http://xiaoguoguo.dbeile.cn/ , 查看更多
 
 
更多>同类行业资讯
0相关评论

新闻列表
企业新闻
推荐企业新闻
推荐图文
推荐行业资讯
点击排行
网站首页  |  关于我们  |  联系方式  |  使用协议  |  版权隐私  |  网站地图  |  排名推广  |  广告服务  |  积分换礼  |  网站留言  |  RSS订阅  |  违规举报  |  鄂ICP备2023001713号