Compare commits

...

2 Commits

Author SHA1 Message Date
lzCodeGarden 542c9e10c1 Merge remote-tracking branch 'origin/master'
1 year ago
lzCodeGarden a806630cbc 新增缩略图
1 year ago

@ -27,7 +27,11 @@
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
</dependency>
<dependency>
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>0.4.14</version> <!-- 或者最新版本 -->
</dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>

@ -323,6 +323,16 @@ public class OcrPicture implements BaseDto, java.io.Serializable {
@TableField(exist = false)
private String result;
@ApiModelProperty(value = "缩略图服务器绝对路径")
@Schema(description = "缩略图服务器绝对路径")
@TableField(value = "local_thumbnail_url")
private String localThumbnailUrl;
@ApiModelProperty(value = "缩略图请求地址")
@Schema(description = "缩略图请求地址")
@TableField(value = "server_thumbnail_url")
private String serverThumbnailUrl;
//图片分类
@TableField(exist = false)
private OcrPictureclass ocrPictureclass;
@ -398,7 +408,9 @@ public class OcrPicture implements BaseDto, java.io.Serializable {
new SimpleEntry<>("field17", "field17"),
new SimpleEntry<>("field18", "field18"),
new SimpleEntry<>("localpictrueurl", "localpictrueurl"),
new SimpleEntry<>("imgHash", "imgHash")
new SimpleEntry<>("imgHash", "imgHash"),
new SimpleEntry<>("serverThumbnailUrl", "serverThumbnailUrl"),
new SimpleEntry<>("localThumbnailUrl", "localThumbnailUrl")
)
.collect(Collectors.toMap(SimpleEntry::getKey, SimpleEntry::getValue));

@ -101,4 +101,6 @@ public interface OcrPictureService extends BaseService<OcrPicture> {
ResultVo createPackageTask(List<OcrPicture> pageList, String tenantId, UserToken userToken, String searchMonth, HttpServletRequest req, String buessinessno);
Map<String,String> getOcrPictureClassifyAndHash(String img);
String getServerUrl();
}

@ -54,6 +54,10 @@ public class OcrPictureServiceImpl extends BaseServiceImpl<OcrPictureMybatisDao,
private String similarityPath;
@Value("${image.classifyPath}")
private String classifyPath;
@Value("${image.serverUrl}")
private String serverUrl;
@Resource
private OcrPictureMybatisDao ocrpicturemybatisdao;
@ -312,9 +316,11 @@ public class OcrPictureServiceImpl extends BaseServiceImpl<OcrPictureMybatisDao,
boolean havePoint = false;
//二次遍历进行比对
for (OcrPicture ocrPictureNext : ocrPictureList) {
//分类不一致的也不需要进行比对
if (ocrPictureNext.getId().longValue() == ocrPicture.getId().longValue()) {
continue;
}
//分类不一致的也不需要进行比对
//TODO 接口请求判断重复情况
logService.addLog(103, "AI获取图片相似度接口", sysUser, "sendParams");
if(StringUtils.isBlank(ocrPicture.getImgHash())){
@ -410,6 +416,11 @@ public class OcrPictureServiceImpl extends BaseServiceImpl<OcrPictureMybatisDao,
}
}
@Override
public String getServerUrl() {
return serverUrl;
}
public OcrTaskchildPicture updateTaskChild(OcrPicture ocrPicture, Long packageid, String buessinessno) {
OcrTaskchildPicture ocrTaskchildPicture = ocrTaskchildPictureService.getOne(new LambdaQueryWrapper<OcrTaskchildPicture>().eq(OcrTaskchildPicture::getPictureid, ocrPicture.getId()));
ocrTaskchildPicture.setBuessinessno(buessinessno);

@ -10,11 +10,14 @@ import cn.jyjz.xiaoyao.ocr.service.OcrPictureService;
import cn.jyjz.xiaoyao.ocr.thread.entity.PictureImgToLocalEntity;
import cn.jyjz.xiaoyao.ocr.util.DownloadImgUtil;
import cn.jyjz.xiaoyao.ocr.util.ImageClassUtil;
import cn.jyjz.xiaoyao.ocr.util.ImageUtils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import net.coobird.thumbnailator.Thumbnails;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@ -48,6 +51,12 @@ public class PictureImgToLocalTask implements Runnable {
if (ObjectUtil.isNotEmpty(picture)) {
picture.setLocalpictrueurl(pictureImgToLocal.getLocalPath());
picture.setIsdownload(1);
try {
picture.setLocalThumbnailUrl(ImageUtils.generateThumbnail(pictureImgToLocal.getLocalPath(),182));
picture.setServerThumbnailUrl(ocrPictureService.getServerUrl()+ImageUtils.getFileExtension(picture.getLocalpictrueurl()));
} catch (IOException e) {
throw new RuntimeException(e);
}
Map<String, String> ocrPictureClassifyAndHash = ocrPictureService.getOcrPictureClassifyAndHash(picture.getLocalpictrueurl());
if(ocrPictureClassifyAndHash!=null){
picture.setImgHash(ocrPictureClassifyAndHash.get("hash"));

@ -0,0 +1,49 @@
package cn.jyjz.xiaoyao.ocr.util;
import net.coobird.thumbnailator.Thumbnails;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.UUID;
/**
* @Title:
* @Description:
* @Author
* @Date 2024-03-18 15:29
* @Version V1.0
*/
public class ImageUtils {
public static String generateThumbnail(String inputImagePath, Integer newWidth) throws IOException {
if(newWidth==null){
newWidth=182;
}
String directoryPath = inputImagePath.substring(0, inputImagePath.lastIndexOf("/") + 1);
File inputFile = new File(inputImagePath);
String outputImagePath = directoryPath+ "thumbnail_" + inputFile.getName();
BufferedImage bufferedImage = Thumbnails.of(inputFile).scale(1).asBufferedImage();
int width = bufferedImage.getWidth();
int height = bufferedImage.getHeight();
int newHeight = (int) Math.round((double) height * newWidth / width);
Thumbnails.of(inputFile).size(newWidth, newHeight).outputFormat( getFileExtension(inputFile.getName())).toFile(new File(outputImagePath));
return outputImagePath;
}
public static String getFileExtension(String fileName) {
if (fileName.lastIndexOf(".") != -1 && fileName.lastIndexOf(".") != 0) {
return fileName.substring(fileName.lastIndexOf(".") + 1);
} else {
return "jpg"; // 没有后缀名或者文件名以点号开头
}
}
public static void main(String[] args) throws IOException {
String url="C:\\Users\\郭向斌\\Downloads\\1-星浩.png";
String s = generateThumbnail(url,180);
System.out.println(s);
}
}

@ -289,3 +289,4 @@ ocr:
image:
similarityPath: http://127.0.0.1:8000/api/similarity/
classifyPath: http://127.0.0.1:8000/api/classify/
serverUrl: http://47.93.59.251/api/image/
Loading…
Cancel
Save