JAVA使用Marvin在图片中搜索图片
marvin
Marvin是一个Java开源图像处理框架
项目地址
使用非常简单,按照tutorials一步一步就知道怎么部署代码。
依赖只需要添加marvin/framework/marvin_1.5.5.jar到classpath。
例子:
import marvin.image.MarvinImage;
import marvin.image.MarvinSegment;
import marvin.io.MarvinImageIO;
import java.awt.*;
import java.io.File;
import static marvin.MarvinPluginCollection.*;
public class Subimage {
public Subimage(){
MarvinImage window = MarvinImageIO.loadImage("E:\\msC_desktop\\batlogo.jpg");
MarvinImage eclipse = MarvinImageIO.loadImage("E:\\msC_desktop\\wxlogo.jpg");
MarvinSegment seg1;
int startx = 500, starty = 0;
seg1 = findSubimage(eclipse, window, startx, starty, 0.75);
if(seg1 != null){
System.out.println("Found:" + seg1.x1 + " " + seg1.y1 + " width:"+ (seg1.x2-seg1.x1) + " height:"+(seg1.y2-seg1.y1) );
drawRect(window, seg1.x1, seg1.y1, seg1.x2-seg1.x1, seg1.y2-seg1.y1);
MarvinImageIO.saveImage(window, "E:\\msC_desktop\\window_out.png");
}else{
System.out.println("NOT FOUND");
}
}
private void drawRect(MarvinImage image, int x, int y, int width, int height){
x-=4; y-=4; width+=8; height+=8;
image.drawRect(x, y, width, height, Color.red);
}
public static void main(String[] args) {
new Subimage();
}
}
效果如下:
函数也可以查阅javadoc.