| | |
| | | import com.arcsoft.face.FaceEngine; |
| | | import com.arcsoft.face.toolkit.ImageFactory; |
| | | import com.arcsoft.face.toolkit.ImageInfo; |
| | | import com.whyc.constant.YamlProperties; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.factory.FaceEngineFactory; |
| | | import com.whyc.pojo.PermitGroup; |
| | |
| | | @ApiOperation(value = "在线激活人脸识别引擎",notes = "只需要刚开始时调用一次,会导致appId与硬件设备绑定,必须有外部网络,否则激活会失败!" + |
| | | "后续使用无需再调用激活,可以离线使用") |
| | | public Response activeOnline(){ |
| | | Response model = new Response(); |
| | | boolean b = FaceIdentifyUtil.activeOnline(); |
| | | boolean b = FaceIdentifyUtil.active(1); |
| | | if(b){ |
| | | return new Response().set(1,true,"引擎激活成功"); |
| | | }else{ |
| | | return new Response().set(1,false,"引擎激活失败,请检查网络是否为外网并确认appId和key是否正确!"); |
| | | } |
| | | } |
| | | |
| | | @GetMapping("activeOffline") |
| | | @ApiOperation(value = "离线激活人脸识别引擎,增值版使用") |
| | | public Response activeOffline(){ |
| | | boolean b = FaceIdentifyUtil.active(2); |
| | | if(b){ |
| | | return new Response().set(1,true,"引擎激活成功"); |
| | | }else{ |
| | |
| | | public Response add(@RequestBody Map<String,Object> paramMap ){ |
| | | String fileData = (String) paramMap.get("fileData"); |
| | | String uName = (String) paramMap.get("uName"); |
| | | //过滤 uName的特殊字符,避免路径遍历攻击 |
| | | uName = ActionUtil.filterFileName(uName); |
| | | Integer uId = Integer.parseInt((String)paramMap.get("uId")); |
| | | //传参 uId,uName,fileData--文件流 |
| | | fileData = fileData.replaceAll(" ", "+"); |
| | |
| | | File jarFile = applicationHome.getDir(); |
| | | |
| | | //存储人脸图片的文件夹 |
| | | String fileDirName = jarFile.getParentFile().toString()+File.separator+"fg_photo"; |
| | | String fileDirName; |
| | | if(YamlProperties.runModel == 1) { |
| | | fileDirName = jarFile.getParentFile().toString() + File.separator + "fg_photo"; |
| | | }else{ |
| | | fileDirName = jarFile.toString() + File.separator + "fg_photo"; |
| | | } |
| | | |
| | | File file = new File(fileDirName); |
| | | //不存在则创建该文件夹 |
| | |
| | | |
| | | //文件全路径 |
| | | String fileName = fileDirName + File.separator + uName + ".jpg"; |
| | | |
| | | FileOutputStream fot=null; |
| | | try { |
| | | FileOutputStream fot = new FileOutputStream(fileName); |
| | | |
| | | fot = new FileOutputStream(fileName); |
| | | fot.write(dataBytes); |
| | | fot.flush(); |
| | | fot.close(); |
| | | |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | }finally { |
| | | if(fot!=null){ |
| | | try { |
| | | fot.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /*=========数据库表更新===========*/ |
| | |
| | | * 人脸库管理: 更新 |
| | | * @return |
| | | */ |
| | | @PutMapping |
| | | @PostMapping("update") |
| | | @ApiOperation(value = "更新") |
| | | public Response update(@RequestBody String fileData,@RequestParam String uName){ |
| | | //传参,uName,fileData--文件流 |
| | | |
| | | //过滤 uName的特殊字符,避免路径遍历攻击 |
| | | uName = ActionUtil.filterFileName(uName); |
| | | //由于图片字符串是由base64编码的,解码成字节数组 |
| | | fileData = fileData.replaceAll(" ", "+"); |
| | | fileData = fileData.split(",")[1]; |
| | |
| | | File jarFile = applicationHome.getDir(); |
| | | |
| | | //存储人脸图片的文件夹 |
| | | String fileDirName = jarFile.getParentFile().toString()+File.separator+"fg_photo"; |
| | | String fileDirName; |
| | | if(YamlProperties.runModel == 1) { |
| | | fileDirName = jarFile.getParentFile().toString() + File.separator + "fg_photo"; |
| | | }else{ |
| | | fileDirName = jarFile.toString() + File.separator + "fg_photo"; |
| | | } |
| | | |
| | | File file = new File(fileDirName); |
| | | //不存在则创建该文件夹 |
| | |
| | | |
| | | //文件全路径 |
| | | String fileName = fileDirName + File.separator + uName + ".jpg"; |
| | | |
| | | FileOutputStream fot =null; |
| | | try { |
| | | FileOutputStream fot = new FileOutputStream(fileName); |
| | | |
| | | fot = new FileOutputStream(fileName); |
| | | fot.write(dataBytes); |
| | | fot.flush(); |
| | | fot.close(); |
| | | |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | }finally { |
| | | if(fot!=null){ |
| | | try { |
| | | fot.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | return new Response().setII(1,"更新成功"); |
| | | } |
| | |
| | | * 人脸库管理: 删除 |
| | | * @return |
| | | */ |
| | | @DeleteMapping |
| | | @PostMapping("delete") |
| | | @ApiOperation(value = "删除") |
| | | @Transactional |
| | | public Response delete(@RequestParam Integer uId,@RequestParam Integer faceId, |
| | | @RequestParam String uName,HttpServletRequest request){ |
| | | |
| | | //过滤 uName的特殊字符,避免路径遍历攻击 |
| | | uName = ActionUtil.filterFileName(uName); |
| | | //更新user_inf和face表 |
| | | service.update(uId,faceId); |
| | | |
| | |
| | | }else{ |
| | | for (UserInf temp:userInfList){ |
| | | String filePath = temp.getFace().getUrl(); |
| | | ImageInfo imageInfo2 = ImageFactory.getRGBData(new File(filePath)); |
| | | File file = new File(filePath); |
| | | //不存在则不继续执行 |
| | | if(!file.exists()){ |
| | | continue; |
| | | } |
| | | ImageInfo imageInfo2 = ImageFactory.getRGBData(file); |
| | | res = FaceIdentifyUtil.faceCompare(faceEngine, imageInfo, imageInfo2); |
| | | //对比成功,记录用户登录信息 |
| | | if(res.getCode()==1){ |