Commit c7810746 by 侯昆
2 parents a7f41c42 71b99fbe
......@@ -21,7 +21,9 @@ import com.dookay.cihai.core.aip.enums.ScanResultTypeEnum;
import com.dookay.cihai.core.aip.model.GeneralRecognitionResult;
import com.dookay.cihai.core.aip.model.ImageResult;
import com.dookay.cihai.core.aip.model.ScanResult;
import com.dookay.coral.common.core.exception.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -51,15 +53,20 @@ public class AipDefaultClient {
*/
public ScanResult scan(String imageBase64) throws JSONException {
ScanResult result = new ScanResult();
GeneralRecognitionResult generalRecognitionResult = aipOcrClient.generalRecognition(imageBase64, ImageInputTypeEnum.BASE64);
if(generalRecognitionResult.getWordsResultNum()>0){
result.setType(ScanResultTypeEnum.WORDS.getValue());
result.setWordsList(generalRecognitionResult.getWordsResult());
}else{
ImageResult imageResult = aipImageClassifyClient.getImageResult(imageBase64);
if(StringUtils.isNoneBlank(imageResult.getName())){
result.setType(ScanResultTypeEnum.PICTURE.getValue());
ImageResult imageResult = aipImageClassifyClient.getImageResult(imageBase64);
result.setWordsList(Collections.singletonList(imageResult.getName()));
}
else{
GeneralRecognitionResult generalRecognitionResult = aipOcrClient.generalRecognition(imageBase64, ImageInputTypeEnum.BASE64);
if(generalRecognitionResult.getWordsResultNum()>0){
result.setType(ScanResultTypeEnum.WORDS.getValue());
result.setWordsList(generalRecognitionResult.getWordsResult());
}else{
throw new ServiceException("图片识别失败");
}
}
return result;
}
......
......@@ -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-> !Objects.equals(x.getName(), "非动物")).sorted(Comparator.comparing(ImageResult::getScore).reversed()).findFirst().orElse(new ImageResult());
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());
}
}
......@@ -22,7 +22,7 @@ public class AipDefaultClientTest extends CihaiCoreApplicationTests {
@Test
public void scan() throws Exception {
File file = ResourceUtils.getFile("classpath:daxiang.txt");
File file = ResourceUtils.getFile("classpath:baidu.txt");
String image = AipUtils.txt2String(file);
......
......@@ -22,7 +22,7 @@ public class AipImageClassifyClientTest extends CihaiCoreApplicationTests {
@Test
public void getImageResult() throws Exception {
File file = ResourceUtils.getFile("classpath:mudan.txt");
File file = ResourceUtils.getFile("classpath:wenzi.txt");
System.out.println(AipUtils.txt2String(file));
String image = AipUtils.txt2String(file);
log.info(image);
......
This diff could not be displayed because it is too large.
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!