Commit 4d5405c7 by 侯昆
2 parents f18c678a a829637e
......@@ -133,7 +133,7 @@ public class AipImageClassifyClient {
List<ImageResult> imageResultList2 = this.getPlantDetect(image,ImageInputTypeEnum.BASE64);
imageResultList.addAll(imageResultList2);
log.info(JSON.toJSONString(imageResultList));
return imageResultList.stream().filter(x->x.getScore()>0.1).filter(x-> !Objects.equals(x.getName(), "非动物")).sorted(Comparator.comparing(ImageResult::getScore).reversed()).findFirst().orElse(new ImageResult());
return imageResultList.stream().filter(x->x.getScore()>0.2).filter(x-> !Objects.equals(x.getName(), "非动物")).sorted(Comparator.comparing(ImageResult::getScore).reversed()).findFirst().orElse(new ImageResult());
}
}
......@@ -68,11 +68,13 @@ public class AipOcrClient {
// 参数为本地图片路径
if(typeEnum == ImageInputTypeEnum.PATH){
res = client.basicGeneral(image, options);
}else{
}else if(typeEnum == ImageInputTypeEnum.BASE64){
image = AipUtils.fixImage(image);
byte[] file = Base64Utils.decodeFromString(image);
res = client.basicGeneral(file, options);
log.info(image);
}else{
res = client.basicGeneralUrl(image, options);
}
return parseResult(res);
......
......@@ -26,7 +26,8 @@ import com.dookay.coral.common.core.enums.IEnum;
public enum ImageInputTypeEnum implements IEnum {
PATH(1, "本地路径"),
BASE64(2,"base64图像数据");
BASE64(2,"base64图像数据"),
URL(3,"url地址");
private int value;
private String description;
......
......@@ -22,7 +22,7 @@ public class AipDefaultClientTest extends CihaiCoreApplicationTests {
@Test
public void scan() throws Exception {
File file = ResourceUtils.getFile("classpath:baidu.txt");
File file = ResourceUtils.getFile("classpath:daxiang.txt");
String image = AipUtils.txt2String(file);
......
......@@ -26,7 +26,7 @@ public class AipOcrClientTest extends CihaiCoreApplicationTests {
@Test
public void generalRecognition() throws Exception {
File file = ResourceUtils.getFile("classpath:wenzi.txt");
File file = ResourceUtils.getFile("classpath:2.txt");
String image = AipUtils.txt2String(file);
GeneralRecognitionResult result = aipOcrClient.generalRecognition(image, ImageInputTypeEnum.BASE64);
log.info(JSON.toJSONString(result));
......@@ -40,6 +40,14 @@ public class AipOcrClientTest extends CihaiCoreApplicationTests {
log.info(JSON.toJSONString(result));
}
@Test
public void generalRecognition3() throws Exception {
File file = ResourceUtils.getFile("classpath:daxiang.txt");
String image = AipUtils.txt2String(file);
GeneralRecognitionResult result = aipOcrClient.generalRecognition("http://ip-27-hexun-wexin.coralcodes.com/static/xiang.png", ImageInputTypeEnum.URL);
log.info(JSON.toJSONString(result));
}
/**
* 读取txt文件的内容
* @param file 想要读取的文件对象
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!