Java-SSM-百度-人脸识别

一、配置:

1.人脸识别官网:http://ai.baidu.com/

2.API文档地址:http://ai.baidu.com/docs#/Face-Java-SDK/top

二、项目:

1.后端接口:

1.1 pom.xml文件 添加jar包

<!-- Face Java SDK -->
<dependency>
	<groupId>com.baidu.aip</groupId>
	<artifactId>java-sdk</artifactId>
	<version>4.1.0</version>
</dependency>

1.2 Controller

@Controller
@RequestMapping("/FaceRecognitionApi/facedetect")
public class FacedetectApiController {
	
	@Autowired
	private IUserInformationService userInformationService;
	
//	@Autowired
//	private ICommonService commonService;
	
	@Autowired
	private IConventionService conventionService;
	
	
	/** 
	 * 人脸检测+注册
	 * @param file 
	 * @return
	 * @throws IOException 
	 */
	@RequestMapping(value="/picdetect",method = RequestMethod.POST)
	@ResponseBody
	public ResResult facedetect(@RequestParam(value = "file") CommonsMultipartFile file,HttpServletRequest request,HttpServletResponse response,FacedetectAddForm form,
			UserInfo userInfo,ConventionUser conventionUser) throws IOException{
		
		ResResult res = new ResResult();
		if(userInfo == null || StringUtils.isBlank(userInfo.getWechatNum())){
			res.setCode(-1);
			res.setMsg("微信号不能为空");
			res.setRe(new ArrayList<String[]>());
			return res;  
		}else if(form == null || StringUtils.isBlank(form.getUserInfo())){
			res.setCode(-1);
			res.setMsg("用户资料不能为空");
			res.setRe(new ArrayList<String[]>());
			return res;  
		}
		else {
			UserInfoForm userInfoForm = new UserInfoForm();
			userInfoForm.setWechatNum(userInfo.getWechatNum());
			UserInfoVO vo = userInformationService.detailsUser(userInfoForm);
			if(vo != null ){
				res.setCode(-1);
				res.setMsg("该用户已注册");
				res.setRe(new ArrayList<String[]>());
				return res;
			}
		}
		
		if (file.isEmpty()) {
	        res.setCode(0);
			res.setMsg("上传文件为空");
			res.setRe(new ArrayList<String[]>());
			return res;  
	    }
		ResResult res1 = PicUtil.savePic(request, file);//上传照片到本地
		
		if(res1.getCode()==1){
			/**
			 * 人脸检测
			 */
			AipFace client = new AipFace(APIConstants.APPID, APIConstants.API_KEY, APIConstants.SERCET_KEY);
		    HashMap<String, String> options = new HashMap<String, String>();
		    options.put("max_face_num", "1");//图片人数,默认为1
		    options.put("face_fields", "qualities");
		    
		    JSONObject jsonObject = client.detect(res1.getRe().toString(), options);
		    System.out.println("---------------人脸检测Return:"+jsonObject.toString());
		    
		    FacedetectReturnVO vo =  JsonUtil.parse(jsonObject.toString(), FacedetectReturnVO
  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值