Commit 0894b5d6 authored by zhangjianqian's avatar zhangjianqian

人脸识别

parent d84127f5
......@@ -93,6 +93,11 @@
<systemPath>${project.basedir}/arcsoft_lib/arcsoft-sdk-face-3.0.0.0.jar</systemPath>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
</dependencies>
<build>
......
......@@ -52,7 +52,7 @@ public class FaceEngineUtils {
//引擎配置
EngineConfiguration engineConfiguration = new EngineConfiguration();
engineConfiguration.setDetectMode(DetectMode.ASF_DETECT_MODE_IMAGE);
engineConfiguration.setDetectFaceOrientPriority(DetectOrient.ASF_OP_0_ONLY);
engineConfiguration.setDetectFaceOrientPriority(DetectOrient.ASF_OP_ALL_OUT);
engineConfiguration.setDetectFaceMaxNum(detectFaceMaxNum);
engineConfiguration.setDetectFaceScaleVal(detectFaceScaleVal);
......
......@@ -2,16 +2,30 @@ package com.zehong.web.controller.arcfacecompare;
import com.arcsoft.face.toolkit.ImageFactory;
import com.arcsoft.face.toolkit.ImageInfo;
import com.zehong.common.core.domain.entity.SysUser;
import com.zehong.common.core.domain.model.LoginUser;
import com.zehong.common.utils.ServletUtils;
import com.zehong.framework.web.service.TokenService;
import com.zehong.web.arcface.util.FaceEngineUtils;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.http.entity.ContentType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
......@@ -26,6 +40,10 @@ public class FaceCompareController {
@Autowired
private FaceEngineUtils faceEngineUtil;
@Autowired
private TokenService tokenService;
@Value("${zehong.profile}")
public String uploadUrl;
/**
* 图片比对
......@@ -49,4 +67,81 @@ public class FaceCompareController {
return result;
}
}
@PostMapping(value = "/compareOne")
public Map<String,Object> compareOne(@RequestParam(value = "file")MultipartFile file){
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
SysUser user = loginUser.getUser();
Map<String,Object> result = new HashMap<>(16);
try {
//MultipartFile file2 = createFileItem(user.getCertificateUrl());
MultipartFile file2 = createMfileByPath(user.getCertificateUrl());
ImageInfo rgbData1 = ImageFactory.getRGBData(file.getBytes());
ImageInfo rgbData2 = ImageFactory.getRGBData(file2.getBytes());
result.put("code","0");
result.put("faceSimilar",faceEngineUtil.compareFace(rgbData1,rgbData2));
return result;
} catch (Exception e) {
result.put("code","1");
result.put("msg",e.getMessage());
logger.error("图片比对系统错误:" + e);
return result;
}
}
/**
* url转变为 MultipartFile对象
* @return
* @throws Exception
*/
public MultipartFile createMfileByPath(String path) {
MultipartFile mFile = null;
path = uploadUrl + "/upload"+path.split("upload")[1];
//path = "D:\\zehong\\uploadPath\\upload\\2023\\02\\07\\b8d62b74-eee3-46fc-8918-8fd2a2b8ba31.jpg";
try {
File file = new File(path);
FileInputStream fileInputStream = new FileInputStream(file);
String fileName = file.getName();
fileName = fileName.substring((fileName.lastIndexOf("/") + 1));
mFile = new MockMultipartFile(fileName, fileName, ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
} catch (Exception e) {
e.printStackTrace();
}
return mFile;
}
/**
* url转变为 MultipartFile对象
* @param url
* @return
* @throws Exception
*/
private MultipartFile createFileItem(String url) throws Exception{
FileItem item = null;
String fileName = "123.jpg";
try {
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
conn.setReadTimeout(30000);
conn.setConnectTimeout(30000);
//设置应用程序要从网络连接读取数据
conn.setDoInput(true);
conn.setRequestMethod("GET");
if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
InputStream is = conn.getInputStream();
FileItemFactory factory = new DiskFileItemFactory(16, null);
String textFieldName = "uploadfile";
item = factory.createItem(textFieldName, ContentType.APPLICATION_OCTET_STREAM.toString(), false, fileName);
OutputStream os = item.getOutputStream();
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = is.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytesRead);
}
os.close();
is.close();
}
} catch (IOException e) {
throw new RuntimeException("文件下载失败", e);
}
return new CommonsMultipartFile(item);
}
}
......@@ -92,6 +92,16 @@ public class SysUser extends BaseEntity
/** 岗位组 */
private Long[] postIds;
private String certificateUrl;
public String getCertificateUrl() {
return certificateUrl;
}
public void setCertificateUrl(String certificateUrl) {
this.certificateUrl = certificateUrl;
}
public SysUser()
{
......
......@@ -114,7 +114,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
.antMatchers(
HttpMethod.POST,
"/subscription/**",
"/system/result/**"
"/system/result/**","/arcFace/compare"
).permitAll()
.antMatchers("/profile/**").anonymous()
.antMatchers("/common/download**").anonymous()
......
......@@ -23,6 +23,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
<result property="certificateUrl" column="certificate_url" />
<association property="dept" column="dept_id" javaType="SysDept" resultMap="deptResult" />
<collection property="roles" javaType="java.util.List" resultMap="RoleResult" />
</resultMap>
......@@ -47,7 +48,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<sql id="selectUserVo">
select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
d.dept_id, d.parent_id, d.dept_name, d.order_num, d.leader, d.status as dept_status,
d.dept_id, d.parent_id, d.dept_name, d.order_num, d.leader, d.status as dept_status,u.certificate_url,
r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status
from sys_user u
left join sys_dept d on u.dept_id = d.dept_id
......@@ -56,7 +57,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</sql>
<select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult">
select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader from sys_user u
select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,u.certificate_url, d.dept_name, d.leader from sys_user u
left join sys_dept d on u.dept_id = d.dept_id
where u.del_flag = '0' and u.user_staff='0'
<if test="userName != null and userName != ''">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment