1. 概述

对图片的存贮以及搜索进行封装,方便用户进行调用

2. pom文件配置

在相关的pom.xml文件引入客户端依赖:

        <dependency>
            <groupId>com.redxun</groupId>
            <artifactId>jpaas-common-milvus</artifactId>
        </dependency>

3. nacos文件配置

在nacos-config.properties配置获取python服务器URL资源

#保存图片的URL
props.saveImageUrl=http://localhost:8080/saveImage
#搜索图片的URL
props.searchImageUrl=http://localhost:8080/searchImage

4. 调用

    @Autowired
    IImageService iImageService;

4.1 图片存贮

        JsonResult jsonResult = iImageService.saveImage("D:/photo/11.png");
        String result = "";
        if(jsonResult.isSuccess()){
            result = "milvus insert success! ID is: " + jsonResult.getData();
        }else{
            result = "milvus insert fail!";
        }

        return "invoke result: " + result;

结果:

invoke result: milvus insert success! ID is: 427216362718983008

将返回的ID【427216362718983008】跟图片进行绑定,方便后面进行图片搜索时,通过ID找到相应的图片

4.2 图片搜索

        JsonResult jsonResult = iImageService.searchImage("D:/photo/11.png");
        String result = "";
        if(jsonResult.isSuccess()){
            result = "milvus insert success! ID is: " + jsonResult.getData();
        }else{
            result = "milvus insert fail!";
        }

        return "invoke result: " + result;

结果:

invoke result: milvus search success! ID is: 427216362718983008,427216362718983025,427216362718982933,427216362718982919,427216362718982926,427216362718982865,427216362718982831,427216362718982882,427216362718982848,427216362718982400

通过返回的ID串【427216362718983008,427216362718983025,427216362718982933,427216362718982919,427216362718982926,427216362718982865,427216362718982831,427216362718982882,427216362718982848,427216362718982400】,获取上面已绑定的图片

文档更新时间: 2021-08-25 10:04   作者:朱方华