拿到的图片是webp格式的,然后系统无法处理。只能使用google code的dwebp工具,把图片转成png或者jpg的。
这一步是ok了。
但是转成的图片是RGBA的,系统只能处理RGB。。。
报了下面的错:
java.lang.ArrayIndexOutOfBoundsException: 3
at java.awt.image.ComponentSampleModel.getPixel(ComponentSampleModel.java:750)
at java.awt.image.Raster.getPixel(Raster.java:1519)
at net.semanticmetadata.lire.imageanalysis.features.global.AutoColorCorrelogram.hsvImage(AutoColorCorrelogram.java:230)
at net.semanticmetadata.lire.imageanalysis.features.global.AutoColorCorrelogram.extract(AutoColorCorrelogram.java:242)
at net.semanticmetadata.lire.builders.GlobalDocumentBuilder.extractGlobalFeature(GlobalDocumentBuilder.java:199)
at net.semanticmetadata.lire.builders.GlobalDocumentBuilder.getGlobalDescriptorFields(GlobalDocumentBuilder.java:217)
at net.semanticmetadata.lire.builders.GlobalDocumentBuilder.createDescriptorFields(GlobalDocumentBuilder.java:265)
at net.semanticmetadata.lire.builders.GlobalDocumentBuilder.createDocument(GlobalDocumentBuilder.java:287)
at net.semanticmetadata.lire.sampleapp.Indexer.main(Indexer.java:121)
还得把RGBA转成RGB格式。
试了下面的方法:
1,python 的pillow库,有损;
2,imageMagick(
http://www.imagemagick.org/script/index.php
),有损;
最后找到了这个:
https://github.com/dermotte/LIRE/blob/master/src/main/docs/developer-docs/docs/imageread.md
也就是使用imageJ这个库
<!-- https://mvnrepository.com/artifact/net.imagej/ij -->
<dependency>
<groupId>net.imagej</groupId>
<artifactId>ij</artifactId>
<version>1.49c</version>
</dependency>
代码:
package com.liyao;
import ij.ImagePlus;
import ij.process.ImageConverter;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class RGBConvert {
public static void main(String args[]){
BufferedImage oldRGBA = openImage("src/main/resources/whatsapp.png");
File outputfile = new File("E:\\saved.png");
try {
ImageIO.write(oldRGBA, "png", outputfile);
} catch (IOException e) {
e.printStackTrace();
}
}
public static BufferedImage openImage(String path) {
ImagePlus imgPlus = new ImagePlus(path);
// converting the image to RGB
ImageConverter imageConverter = new ImageConverter(imgPlus);
imageConverter.convertToRGB();
// returning the BufferedImage instance
return imgPlus.getBufferedImage();
}
}
亲测无损。下面是结果:
这是RGBA 的图片:
我的cbir系统无法处理。
下面是使用python处理以后的RGB:
代码:
import PIL.Image as Image
rgba_image = Image.open('wechat.png')
rgba_image.save('new.png')
这个图片会报之前的错。
下面是使用imageJ处理以后的RGB:
没有报错。
python print int python print int和str不能一起
1 tup = (['a','a1'],['b','b2'],['c','c3'])
2 ls = [['d',1,],['e',2],['f',3]]
3 b = []
5 #for i in range(2):
6 # a = ls[0][i] + ":" + ls[1][i] + ":" + ls[2][i] #该条指令会报错
7 # b.append(a)