项目作者: blueshen

项目描述 :
图片相似度计算Image Compare
高级语言: Java
项目地址: git://github.com/blueshen/pica-pica.git
创建时间: 2014-01-16T12:04:02Z
项目社区:https://github.com/blueshen/pica-pica

开源协议:

下载


Build Status

pica pica (Magpie)

介绍

用于对图片进行对比,并标识出不同区域的应用。

Usage

  1. mvn tomcat7:run

open http://localhost:8080/pica-pica

Thanks:

http://www.lac.inpe.br/JIPCookbook

http://blog.csdn.net/jia20003/article/details/7771651

开放的API接口

1./api/image/compare

http请求方式:POST[multipart/form-data]

  1. **form参数:**
  2. sourceFile 源图片
  3. candidateFile 要比较的图片
  4. col 图片切分为几列
  5. row 图片切分为几行
  6. similarityThreshold 阈值,低于这个相似度认为图片是不同的

返回JSON:

  1. {"match":true,"diffImageId":"038d245a-ae22-460d-b123-66dd11fcdaf5","links":[]}
如何调用?
  • 使用Spring RestTemplate

    1. long beginTime = System.currentTimeMillis();
    2. RestTemplate template = new RestTemplate();
    3. MultiValueMap<String, Object> form = new LinkedMultiValueMap<String, Object>();
    4. form.add("sourceFile", new FileSystemResource("/home/shenyanchao/Pictures/ubuntu-011.jpg"));
    5. form.add("candidateFile", new FileSystemResource("/home/shenyanchao/Pictures/ubuntu-011.jpg"));
    6. form.add("col", 20);
    7. form.add("row", 20);
    8. form.add("similarityThreshold", 0.8);
    9. ResponseEntity<String> responseEntity = template.postForEntity("http://localhost:8080/pica-pica/api/image/compare", form, String.class);
    10. String result = responseEntity.getBody();
    11. long endTime = System.currentTimeMillis();
    12. System.out.println(result);
    13. System.out.println("耗时(ms):" + (endTime - beginTime));
  • 使用httpclient

    1. HttpClient client = new DefaultHttpClient();
    2. HttpPost post = new HttpPost("http://localhost:8080/pica-pica/api/image/compare");
    3. MultipartEntity entity = new MultipartEntity();
    4. entity.addPart("sourceFile", new FileBody(new File("/home/shenyanchao/Pictures/ubuntu-011.jpg")));
    5. entity.addPart("candidateFile", new FileBody(new File("/home/shenyanchao/Pictures/ubuntu-011.jpg")));
    6. entity.addPart("col", new StringBody("20"));
    7. entity.addPart("row", new StringBody("20"));
    8. entity.addPart("similarityThreshold", new StringBody("0.8"));
    9. post.setEntity(entity);
    10. HttpResponse response = client.execute(post);
    11. String returnStr = EntityUtils.toString(response.getEntity());
    12. client.getConnectionManager().shutdown();
    13. System.out.println(returnStr);

2. /api/image/${id}

  1. **http请求方式**:GET
  2. 参数:id 上面返回的diffImageId
如何调用?
  1. InputStream is =
  2. new URL("http://localhost:8080/pica-pica/api/image/d38719d1-3246-4e96-b444-6d7310156fad").openStream();
  3. FileOutputStream out = new FileOutputStream(new File("/home/shenyanchao/change.png"));
  4. IOUtils.copy(is, out);
  5. out.close();
  6. is.close();

或者可以直接在浏览器查看http://localhost:8080/pica-pica/upload/d38719d1-3246-4e96-b444-6d7310156fad.png