1 Star 0 Fork 16

jee / H5人脸识别系列实例

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
faceRecognitionControll.java 2.24 KB
一键复制 编辑 原始数据 按行查看 历史
package com.zfsoft.artificialIntelligence.faceRecognition.controller;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
/**
* 人脸识别服务 controller
* @author liyingming
*
*/
@Controller
@RequestMapping(value = "/faceRecognition")
public class faceRecognitionController {
/**
* 人脸检测测试页面
* @return
* @throws Exception
*/
@RequestMapping(value = "/test.do")
public ModelAndView queryVoi() throws Exception {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("/artificialIntelligence/faceRecognition/test");
return modelAndView;
}
/**
* 请求人脸检测
* @return
* @throws Exception
*/
@RequestMapping(value = "/save.do")
@ResponseBody
public Map<String, Object> queryService(@RequestParam("the_file") MultipartFile file) {
Map<String, Object> modelMap = new HashMap<String, Object>();
try {
//将数据转为流
InputStream content = file.getInputStream();
ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
byte[] buff = new byte[100];
int rc = 0;
while ((rc = content.read(buff, 0, 100)) > 0) {
swapStream.write(buff, 0, rc);
}
//获得二进制数组
byte[] in2b = swapStream.toByteArray();
//调用人脸检测的方法
Map<String, String> strmap = FaceDetect.detectby(in2b);
//将map数据封装json传到前台
//此处JsonUtil未提供,大家可以找一个转json的方法
//String strjson = JsonUtil.mapToJson(strmap);
modelMap.put("strjson", strjson);
modelMap.put("success", true);
} catch (Exception e) {
modelMap.put("success", false);
modelMap.put("data", e.getMessage());
}
return modelMap;
}
}
Java
1
https://gitee.com/jempson/faceRecognition.git
git@gitee.com:jempson/faceRecognition.git
jempson
faceRecognition
H5人脸识别系列实例
master

搜索帮助