抓拍修复
parent
6ac7a6db1d
commit
4e92556e24
|
@ -22,6 +22,7 @@ public class CompreFaceApiResponse {
|
|||
private Box box;
|
||||
private List<Subject> subjects;
|
||||
private List<List<Integer>> landmarks;
|
||||
private Camera camera;
|
||||
|
||||
public Age getAge() {
|
||||
return age;
|
||||
|
@ -68,8 +69,17 @@ public class CompreFaceApiResponse {
|
|||
}
|
||||
|
||||
public void setLandmarks(List<List<Integer>> landmarks) {
|
||||
|
||||
this.landmarks = landmarks;
|
||||
}
|
||||
|
||||
public Camera getCamera() {
|
||||
return camera;
|
||||
}
|
||||
|
||||
public void setCamera(Camera camera) {
|
||||
this.camera = camera;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Age {
|
||||
|
|
|
@ -0,0 +1,235 @@
|
|||
package com.zyh.common.domain.dto;
|
||||
|
||||
import java.util.List;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.zyh.common.domain.Camera;
|
||||
|
||||
public class CompreFaceApiResponseDto {
|
||||
|
||||
private List<Result> result;
|
||||
|
||||
public List<Result> getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(List<Result> result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public static class Result {
|
||||
private Age age;
|
||||
private Gender gender;
|
||||
private Pose pose;
|
||||
private Box box;
|
||||
private List<Subject> subjects;
|
||||
private List<List<Integer>> landmarks;
|
||||
private Camera camera;
|
||||
|
||||
public Age getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(Age age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public Gender getGender() {
|
||||
return gender;
|
||||
}
|
||||
|
||||
public void setGender(Gender gender) {
|
||||
this.gender = gender;
|
||||
}
|
||||
|
||||
public Pose getPose() {
|
||||
return pose;
|
||||
}
|
||||
|
||||
public void setPose(Pose pose) {
|
||||
this.pose = pose;
|
||||
}
|
||||
|
||||
public Box getBox() {
|
||||
return box;
|
||||
}
|
||||
|
||||
public void setBox(Box box) {
|
||||
this.box = box;
|
||||
}
|
||||
|
||||
public List<Subject> getSubjects() {
|
||||
return subjects;
|
||||
}
|
||||
|
||||
public void setSubjects(List<Subject> subjects) {
|
||||
this.subjects = subjects;
|
||||
}
|
||||
|
||||
public List<List<Integer>> getLandmarks() {
|
||||
return landmarks;
|
||||
}
|
||||
|
||||
public void setLandmarks(List<List<Integer>> landmarks) {
|
||||
|
||||
this.landmarks = landmarks;
|
||||
}
|
||||
|
||||
public Camera getCamera() {
|
||||
return camera;
|
||||
}
|
||||
|
||||
public void setCamera(Camera camera) {
|
||||
this.camera = camera;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Age {
|
||||
private Double probability;
|
||||
private Integer high;
|
||||
private Integer low;
|
||||
|
||||
public Double getProbability() {
|
||||
return probability;
|
||||
}
|
||||
|
||||
public void setProbability(Double probability) {
|
||||
this.probability = probability;
|
||||
}
|
||||
|
||||
public Integer getHigh() {
|
||||
return high;
|
||||
}
|
||||
|
||||
public void setHigh(Integer high) {
|
||||
this.high = high;
|
||||
}
|
||||
|
||||
public Integer getLow() {
|
||||
return low;
|
||||
}
|
||||
|
||||
public void setLow(Integer low) {
|
||||
this.low = low;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Gender {
|
||||
private Double probability;
|
||||
private String value;
|
||||
|
||||
public Double getProbability() {
|
||||
return probability;
|
||||
}
|
||||
|
||||
public void setProbability(Double probability) {
|
||||
this.probability = probability;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Pose {
|
||||
private Double pitch;
|
||||
private Double roll;
|
||||
private Double yaw;
|
||||
|
||||
public Double getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
|
||||
public void setPitch(Double pitch) {
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
public Double getRoll() {
|
||||
return roll;
|
||||
}
|
||||
|
||||
public void setRoll(Double roll) {
|
||||
this.roll = roll;
|
||||
}
|
||||
|
||||
public Double getYaw() {
|
||||
return yaw;
|
||||
}
|
||||
|
||||
public void setYaw(Double yaw) {
|
||||
this.yaw = yaw;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Box {
|
||||
private Double probability;
|
||||
private Integer xMax;
|
||||
private Integer yMax;
|
||||
private Integer xMin;
|
||||
private Integer yMin;
|
||||
|
||||
public Double getProbability() {
|
||||
return probability;
|
||||
}
|
||||
|
||||
public void setProbability(Double probability) {
|
||||
this.probability = probability;
|
||||
}
|
||||
|
||||
public Integer getxMax() {
|
||||
return xMax;
|
||||
}
|
||||
|
||||
public void setxMax(Integer xMax) {
|
||||
this.xMax = xMax;
|
||||
}
|
||||
|
||||
public Integer getyMax() {
|
||||
return yMax;
|
||||
}
|
||||
|
||||
public void setyMax(Integer yMax) {
|
||||
this.yMax = yMax;
|
||||
}
|
||||
|
||||
public Integer getxMin() {
|
||||
return xMin;
|
||||
}
|
||||
|
||||
public void setxMin(Integer xMin) {
|
||||
this.xMin = xMin;
|
||||
}
|
||||
|
||||
public Integer getyMin() {
|
||||
return yMin;
|
||||
}
|
||||
|
||||
public void setyMin(Integer yMin) {
|
||||
this.yMin = yMin;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Subject {
|
||||
private String subject;
|
||||
private Double similarity;
|
||||
|
||||
public String getSubject() {
|
||||
return subject;
|
||||
}
|
||||
|
||||
public void setSubject(String subject) {
|
||||
this.subject = subject;
|
||||
}
|
||||
|
||||
public Double getSimilarity() {
|
||||
return similarity;
|
||||
}
|
||||
|
||||
public void setSimilarity(Double similarity) {
|
||||
this.similarity = similarity;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,10 +21,10 @@ public class ComprefaceController {
|
|||
private ComprefaceService comprefaceService;
|
||||
|
||||
@PostMapping("/compreFace")
|
||||
public Result<CompreFaceApiResponse.Result> compareFaces(@RequestParam("file") MultipartFile file) throws IOException {
|
||||
public Result<CompreFaceApiResponse.Result> compareFaces(@RequestParam("file") MultipartFile file,@RequestParam String cameraId) throws IOException {
|
||||
|
||||
// 调用Compreface服务进行人脸比对
|
||||
return comprefaceService.compareWithSingleFace(file);
|
||||
return comprefaceService.compareWithSingleFace(file,cameraId);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -15,4 +15,6 @@ public interface CameraMapper {
|
|||
Integer cameraAdd(Camera camera);
|
||||
|
||||
Integer cameraUpdate(Camera camera);
|
||||
|
||||
Camera selectCamera(@Param("cameraId") String cameraId);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.zyh.system.mapper;
|
||||
|
||||
import com.zyh.common.domain.Camera;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@Mapper
|
||||
public interface ComprefaceMapper {
|
||||
|
|
|
@ -8,5 +8,5 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
import java.io.IOException;
|
||||
|
||||
public interface ComprefaceService {
|
||||
Result<CompreFaceApiResponse.Result> compareWithSingleFace(MultipartFile targetImage) throws IOException;
|
||||
Result<CompreFaceApiResponse.Result> compareWithSingleFace(MultipartFile targetImage,String cameraId) throws IOException;
|
||||
}
|
||||
|
|
|
@ -2,9 +2,12 @@ package com.zyh.system.service.impl;
|
|||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.zyh.common.constants.RabbitMQQueueNameConstants;
|
||||
import com.zyh.common.domain.Camera;
|
||||
import com.zyh.common.domain.CompreFaceApiResponse;
|
||||
import com.zyh.common.domain.dto.CompreFaceApiResponseDto;
|
||||
import com.zyh.common.result.Result;
|
||||
import com.zyh.common.util.ComprefaceUtils;
|
||||
import com.zyh.system.mapper.CameraMapper;
|
||||
import com.zyh.system.mapper.ComprefaceMapper;
|
||||
import com.zyh.system.service.ComprefaceService;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
|
@ -20,31 +23,35 @@ public class ComprefaceServicempl implements ComprefaceService {
|
|||
|
||||
|
||||
@Autowired
|
||||
private ComprefaceMapper comprefaceMapper;
|
||||
private CameraMapper cameraMapper;
|
||||
@Autowired
|
||||
private EsServicempl esServicempl;
|
||||
private ComprefaceMapper comprefaceMapper;
|
||||
|
||||
|
||||
@Autowired
|
||||
RabbitTemplate rabbitTemplate;
|
||||
|
||||
@Override
|
||||
public Result<CompreFaceApiResponse.Result> compareWithSingleFace(MultipartFile targetImage) throws IOException {
|
||||
public Result<CompreFaceApiResponse.Result> compareWithSingleFace(MultipartFile targetImage, String cameraId) throws IOException {
|
||||
byte[] bytes = targetImage.getBytes();
|
||||
// 将接收到的图片路径转换为 base64
|
||||
|
||||
Result<CompreFaceApiResponse.Result> result = ComprefaceUtils.recognizeFace(bytes);
|
||||
CompreFaceApiResponse.Result data = result.getData();
|
||||
//查询设备信息
|
||||
Camera camera = cameraMapper.selectCamera(cameraId);
|
||||
data.setCamera(camera);
|
||||
|
||||
|
||||
// esServicempl.add(data);
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
String jsonString = objectMapper.writeValueAsString(data);
|
||||
|
||||
rabbitTemplate.convertAndSend(RabbitMQQueueNameConstants.SEND_SMS_QUEUE_NAME, jsonString,message -> {
|
||||
rabbitTemplate.convertAndSend(RabbitMQQueueNameConstants.SEND_SMS_QUEUE_NAME, jsonString, message -> {
|
||||
|
||||
message.getMessageProperties().setMessageId(UUID.randomUUID().toString().replaceAll("-", ""));
|
||||
return message;
|
||||
});
|
||||
|
||||
|
||||
|
||||
return Result.success(data);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
package com.zyh.system.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.zyh.common.domain.CompreFaceApiResponse;
|
||||
import com.zyh.system.service.EsService;
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.action.index.IndexResponse;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Service
|
||||
public class EsServicempl implements EsService {
|
||||
@Autowired
|
||||
private RestHighLevelClient restHighLevelClient;
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
|
||||
private final static String INDEX_NAME = "face";
|
||||
|
||||
|
||||
public void pushToElasticsearch(CompreFaceApiResponse.Result data) {
|
||||
try {
|
||||
IndexRequest indexRequest = new IndexRequest(INDEX_NAME);
|
||||
|
||||
// 不设置文档 ID,由 Elasticsearch 自动生成一个唯一 ID
|
||||
// indexRequest.id(data.getYourId());
|
||||
|
||||
String jsonData = objectMapper.writeValueAsString(data);
|
||||
indexRequest.source(jsonData, XContentType.JSON);
|
||||
|
||||
IndexResponse indexResponse = restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
|
||||
|
||||
// 可以根据 indexResponse 获取有关索引操作的信息
|
||||
System.out.println("Elasticsearch Index Response: " + indexResponse);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void add(CompreFaceApiResponse.Result data) {
|
||||
try {
|
||||
IndexRequest indexRequest = new IndexRequest(INDEX_NAME)
|
||||
.source(JSONObject.toJSONString(data), XContentType.JSON);
|
||||
|
||||
restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -20,4 +20,7 @@
|
|||
<select id="cameraList" resultType="com.zyh.common.domain.Camera">
|
||||
select * from camera
|
||||
</select>
|
||||
<select id="selectCamera" resultType="com.zyh.common.domain.Camera">
|
||||
select * from camera where camera_id = #{cameraId}
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue