Commit cca6919c by 陈皓

.

parent 89139b59
......@@ -7,7 +7,7 @@ import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.zq.imgproc.server.ImgProcService;
import com.zq.imgproc.utils.*;
import com.zq.imgproc.vo.DetectionResVo3;
import com.zq.imgproc.vo.DetectionVO;
import com.zq.imgproc.vo.OptimizationReq;
import com.zq.imgproc.vo.OptimizationVO;
import io.swagger.annotations.ApiOperation;
......@@ -53,7 +53,7 @@ public class ApiController {
@ApiOperation("图片检测")
@PostMapping ("/detection")
public ResultVo<DetectionResVo3> detection(@RequestBody OptimizationReq req) throws Exception {
public ResultVo<DetectionVO> detection(@RequestBody OptimizationReq req) throws Exception {
AssertUtils.hasText(req.getFileContent(), "缺少文件内容");
AssertUtils.hasText(req.getFilename(), "缺少文件名");
return ResultVo.success(service.detection2(req));
......
......@@ -66,7 +66,7 @@ public class ImgProcService {
public List<ImgVO> detection(List<ImgVO> pathList) throws Exception {
List<ImgVO> res = new ArrayList<>(pathList.size());
for (ImgVO one : pathList) {
DetectionResVo2 vo = new DetectionResVo2();
DetectionVO vo = new DetectionVO();
String path = one.getUrl();
Mat image = Imgcodecs.imread(path);
// 检测图片的分辨率
......@@ -83,6 +83,9 @@ public class ImgProcService {
vo.setAngle(getAngle(image));
// 检测图片的黑边
vo.setBlack(ImageUtil.blackDetection(image));
// 图片弯曲检测
BendResult bendResult = BendUtil.getBendResult(path);
vo.setBend(bendResult.getConfidence());
one.setDetectionRes(vo);
res.add(one);
}
......@@ -108,7 +111,7 @@ public class ImgProcService {
return res;
}
public DetectionResVo3 detection2(OptimizationReq req) throws Exception {
public DetectionVO detection2(OptimizationReq req) throws Exception {
// 1. 临时保存图片
String ext = FileUtil.extName(req.getFilename());
String yyyyMMdd = new SimpleDateFormat("/yyyyMM/dd/").format(new Date());
......@@ -121,7 +124,7 @@ public class ImgProcService {
ImageIO.write(bufferedImage, "jpg", new File(filePath));
}
DetectionResVo3 res = new DetectionResVo3();
DetectionVO res = new DetectionVO();
Mat image = Imgcodecs.imread(filePath);
// 检测图片的分辨率
res.setWidthResolution(image.width());
......@@ -136,6 +139,9 @@ public class ImgProcService {
res.setAngle(Deskew.getDeskewAngle(image));
// 检测图片的黑边
res.setBlack(ImageUtil.blackDetection(image));
// 图片弯曲检测
BendResult bendResult = BendUtil.getBendResult(filePath);
res.setBend(bendResult.getConfidence());
image.release();
FileUtil.del(filePath);
return res;
......@@ -700,7 +706,7 @@ public class ImgProcService {
}
public ResponseEntity<Resource> getDetection(List<ImgVO> pathList) throws Exception {
if (pathList == null || pathList.size() == 0) {
if (pathList == null || pathList.isEmpty()) {
return ResponseEntity.badRequest().build();
}
pathList = detection(pathList);
......@@ -724,7 +730,7 @@ public class ImgProcService {
private List<DetectionDTO> getData(List<ImgVO> pathList) {
List<DetectionDTO> dtos = new ArrayList<>(pathList.size());
for (ImgVO imgVO : pathList) {
DetectionResVo2 detectionRes = imgVO.getDetectionRes();
DetectionVO detectionRes = imgVO.getDetectionRes();
DetectionDTO dto = new DetectionDTO();
dto.setFilename(imgVO.getFileName());
dto.setResolution(detectionRes.getWidthResolution() + " x " + detectionRes.getHeightResolution());
......
......@@ -7,7 +7,7 @@ import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.zq.imgproc.vo.DetectionResVo3;
import com.zq.imgproc.vo.DetectionVO;
import com.zq.imgproc.vo.OptimizationReq;
import com.zq.imgproc.vo.OptimizationVO;
......@@ -34,7 +34,7 @@ public class DemoUtil {
System.out.println(System.currentTimeMillis() - start);
String res = response.body();
JSONObject object = JSONUtil.parseObj(res);
DetectionResVo3 detectionRes = object.get("data", DetectionResVo3.class);
DetectionVO detectionRes = object.get("data", DetectionVO.class);
System.out.println(JSONUtil.toJsonStr(detectionRes));
}
}
......
......@@ -6,7 +6,7 @@ import com.drew.imaging.ImageMetadataReader;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;
import com.drew.metadata.Tag;
import com.zq.imgproc.vo.DetectionResVo3;
import com.zq.imgproc.vo.DetectionVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.imaging.ImageInfo;
import org.apache.commons.imaging.Imaging;
......@@ -65,8 +65,8 @@ public class TestUtil {
}
}
public static DetectionResVo3 detection(String src) throws Exception {
DetectionResVo3 res = new DetectionResVo3();
public static DetectionVO detection(String src) throws Exception {
DetectionVO res = new DetectionVO();
Mat image = Imgcodecs.imread(src);
// 检测图片的分辨率
res.setWidthResolution(image.width());
......
package com.zq.imgproc.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* <p>
*
* </p>
*
* @author yww
* @since 2023/4/21
*/
@NoArgsConstructor
@AllArgsConstructor
@Data
@Builder
public class DetectionResVo3 {
@ApiModelProperty("图片的水平分辨率")
private Integer widthResolution;
@ApiModelProperty("图片的垂直分辨率")
private Integer heightResolution;
@ApiModelProperty("图片的DPI")
private Integer dpi;
@ApiModelProperty("图片平均亮度值")
private double brightness;
@ApiModelProperty("图片的清晰度指标,值越大越清晰")
private double clarity;
@ApiModelProperty("图片的倾斜角度")
private double angle;
@ApiModelProperty("图片的黑边检测,true表示可能存在黑边,false表示不存在黑边")
private Boolean black;
}
......@@ -2,21 +2,23 @@ package com.zq.imgproc.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* <p>
* 图片返回结果封装类(带指标)
* </p>
* 检测结果
* </P>
*
* @author chenhao
* @since 2023/3/10 16:48
* @since 2023/11/26
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Data
public class DetectionResVo2 {
public class DetectionVO {
@ApiModelProperty("图片的水平分辨率")
private Integer widthResolution;
......@@ -36,8 +38,10 @@ public class DetectionResVo2 {
@ApiModelProperty("图片的倾斜角度")
private double angle;
@ApiModelProperty("图片弯曲检测置信度")
private double bend;
@ApiModelProperty("图片的黑边检测,true表示可能存在黑边,false表示不存在黑边")
private Boolean black;
}
......@@ -25,6 +25,6 @@ public class ImgVO {
String url;
DetectionResVo2 detectionRes;
DetectionVO detectionRes;
}
......@@ -24,6 +24,11 @@ imgconfig:
deskewpy: /opt/tianjin/lib/correct.py
#imgconfig:
# opencv: /opt/tianjin/lib/opencv_java460.so
# deskew: /opt/tianjin/lib/Deskew/Bin/deskew
# deskewpy: /opt/tianjin/lib/correct.py
#imgconfig:
# opencv: D:/project/imgproc/lib/opencv_java460.dll
# deskew: C:/Users/11419/Desktop/Deskew/Bin/deskew.exe
# deskewpy: D:/project/imgproc/lib/correct.py
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