网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

java图像识别代码,图像识别开源代码

如何使用Java实现屏幕找图功能

测试代码

八宿ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18980820575(备注:SSL证书合作)期待与您的合作!

[java] view plain copy

public static void main(String[] args) throws Exception {

findImage4FullScreen(ImageCognition.SIM_ACCURATE_VERY);

}

public static void findImage4FullScreen(int sim) throws Exception {

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

int w = (int) screenSize.getWidth();

int h = 200;

Robot robot = new Robot();

BufferedImage screenImg = robot.createScreenCapture(new Rectangle(0, 0,

w, h));//对屏幕指定范围进行截图,保存到BufferedImage中

OutputStream out = new FileOutputStream("data/images/screen.png");

ImageIO.write(screenImg, "png", out);//将截到的BufferedImage写到本地

InputStream in = new FileInputStream("data/images/search.png");

BufferedImage searchImg = ImageIO.read(in);//将要查找的本地图读到BufferedImage

//图片识别工具类

ImageCognition ic = new ImageCognition();

ListCoordBean list = ic.imageSearch(screenImg, searchImg, sim);

for (CoordBean coordBean : list) {

System.out.println("找到图片,坐标是" + coordBean.getX() + ","

+ coordBean.getY());

//标注找到的图的位置

Graphics g = screenImg.getGraphics();

g.setColor(Color.BLACK);

g.drawRect(coordBean.getX(), coordBean.getY(),

searchImg.getWidth(), searchImg.getHeight());

g.setFont(new Font(null, Font.BOLD, 20));

g.drawString("←找到的图片在这里",

coordBean.getX() + searchImg.getWidth() + 5,

coordBean.getY() + 10 + searchImg.getHeight() / 2);

out = new FileOutputStream("data/images/result.png");

ImageIO.write(screenImg, "png", out);

}

}

额外的类

CoordBean

package cn.xt.imgCongnition;

public class CoordBean {

private int x;

private int y;

/**

* 获取x坐标

*

* @return x坐标

*/

public int getX() {

return x;

}

public void setX(int x) {

this.x = x;

}

/**

* 获取y坐标

*

* @return

*/

public int getY() {

return y;

}

public void setY(int y) {

this.y = y;

}

}

RgbImageComparerBean

package cn.xt.imgCongnition;

/**

* RGB 相关,图片相似度计算时使用

*

*/

public class RgbImageComparerBean {

/****** 颜色值数组,第一纬度为x坐标,第二纬度为y坐标 ******/

private int colorArray[][];

/*** 是否忽略此点,若为true,则不纳入比较的像素行列。 ***/

private boolean ignorePx[][];

/**** 图片的宽高 ****/

private int imgWidth;

private int imgHeight;

// 图片的像素总数

private int pxCount;

/**

* 获取图像的二维数组组成

*

* @return 图像的二维数组

*/

public int[][] getColorArray() {

return colorArray;

}

/**

* 要对比的像素总数,会自动筛选掉不对比的颜色

*

* @param pxCount

*/

public void setPxCount(int pxCount) {

this.pxCount = pxCount;

}

/**

* 设置颜色二维数组

*

* @param colorArray

* 颜色二维数组,一维为x轴,二维为y轴

*/

public void setColorArray(int[][] colorArray) {

this.colorArray = colorArray;

this.imgWidth = this.colorArray.length;

this.imgHeight = this.colorArray[0].length;

this.pxCount = this.imgWidth * this.imgHeight;

}

/**

* 是否忽略此点,若为true,则不纳入像素比较行列。

*

* @return 具体x,y坐标的那个像素点

*/

public boolean[][] getIgnorePx() {

return ignorePx;

}

/**

* 是否忽略此点,若为true,则不纳入像素比较行列。

*

* @param ignorePx

* 具体x,y坐标的那个像素点

*/

public void setIgnorePx(boolean[][] ignorePx) {

this.ignorePx = ignorePx;

}

/**

* 获取图像的宽度

*

* @return 图像宽度

*/

public int getImgWidth() {

return imgWidth;

}

/**

* 获取图像的高度

*

* @return 图像高度

*/

public int getImgHeight() {

return imgHeight;

}

/**

* 获取图像里像素的总数

*

* @return

*/

public int getPxCount() {

return pxCount;

}

}

Java 图像识别 数字图像处理 从一张JPG图片中识别出若干黑色小方块

你需要关注的主要是这个类:java.awt.image.BufferedImage

可以查阅相关的API。

java图像处理技术在《java核心技术8 下卷》中有比较详细的介绍。

相关技术要求和注意事项:RGB标准、ICC配置特性、

建议如果进行像素识别的话可以选取关键点的识别方式、而且确认像素是否符合要求使用RGB的范围识别而非精确识别。

至于具体的识别操作过程,需要你详细定义开始识别的位置标准(规定的或者识别图像获取)、边界标准、大小(识别块得SIZE)、分组(给识别块确定属性)等

Java 可不可以做图像识别的系统

当然可以。

一、纯JAVA开发的技术可行性,即JAVA是否能够实现图像识别的各种算法。

二、如果第一点没有问题,纯JAVA与C++相比,开发效率上的差异。效率要低很多,和具体问题有关。

三、如果第一点没有问题且第二点差异不太大时,纯JAVA与C++相比,相同算法的情况下,软件运行效率的差异。运行效率的差异也很大,也是和具体的算法有关。

怎么用java实现图片里面的数字识别

图片是由点组成(或者是别的方法),记录点的位置、颜色,控制点就行了。至于ocr,有难度,首先要制作文字的变化范围及整个字各部分的联系,这还是简单的。然后,图像分解就行了。额,我不会编程,稍微会点c++,所以这个回答就是假设如果我做这种程序的思路。

java适合做图像处理吗?

Java图像处理技巧四则

下面代码中用到的sourceImage是一个已经存在的Image对象

图像剪切

对于一个已经存在的Image对象,要得到它的一个局部图像,可以使用下面的步骤:

//import java.awt.*;

//import java.awt.image.*;

Image croppedImage;

ImageFilter cropFilter;

CropFilter =new CropImageFilter(25,30,75,75); //四个参数分别为图像起点坐标和宽高,即CropImageFilter(int x,int y,int width,int height),详细情况请参考API

CroppedImage= Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(sourceImage.getSource(),cropFilter));

如果是在Component的子类中使用,可以将上面的Toolkit.getDefaultToolkit().去掉。FilteredImageSource是一个ImageProducer对象。

图像缩放

对于一个已经存在的Image对象,得到它的一个缩放的Image对象可以使用Image的getScaledInstance方法:

Image scaledImage=sourceImage. getScaledInstance(100,100, Image.SCALE_DEFAULT); //得到一个100X100的图像

Image doubledImage=sourceImage. getScaledInstance(sourceImage.getWidth(this)*2,sourceImage.getHeight(this)*2, Image.SCALE_DEFAULT); //得到一个放大两倍的图像,这个程序一般在一个swing的组件中使用,而类Jcomponent实现了图像观察者接口ImageObserver,所有可以使用this。

//其它情况请参考API

灰度变换

下面的程序使用三种方法对一个彩色图像进行灰度变换,变换的效果都不一样。一般而言,灰度变换的算法是将象素的三个颜色分量使用R*0.3+G*0.59+ B*0.11得到灰度值,然后将之赋值给红绿蓝,这样颜色取得的效果就是灰度的。另一种就是取红绿蓝三色中的最大值作为灰度值。java核心包也有一种算法,但是没有看源代码,不知道具体算法是什么样的,效果和上述不同。

/* GrayFilter.java*/

/*@author:cherami */

/*email:cherami@163.net*/

import java.awt.image.*;

public class GrayFilter extends RGBImageFilter {

int modelStyle;

public GrayFilter() {

modelStyle=GrayModel.CS_MAX;

canFilterIndexColorModel=true;

}

public GrayFilter(int style) {

modelStyle=style;

canFilterIndexColorModel=true;

}

public void setColorModel(ColorModel cm) {

if (modelStyle==GrayModel

else if (modelStyle==GrayModel

}

public int filterRGB(int x,int y,int pixel) {

return pixel;

}

}

/* GrayModel.java*/

/*@author:cherami */

/*email:cherami@163.net*/

import java.awt.image.*;

public class GrayModel extends ColorModel {

public static final int CS_MAX=0;

public static final int CS_FLOAT=1;

ColorModel sourceModel;

int modelStyle;

public GrayModel(ColorModel sourceModel) {

super(sourceModel.getPixelSize());

this.sourceModel=sourceModel;

modelStyle=0;

}

public GrayModel(ColorModel sourceModel,int style) {

super(sourceModel.getPixelSize());

this.sourceModel=sourceModel;

modelStyle=style;

}

public void setGrayStyle(int style) {

modelStyle=style;

}

protected int getGrayLevel(int pixel) {

if (modelStyle==CS_MAX) {

return Math.max(sourceModel.getRed(pixel),Math.max(sourceModel.getGreen(pixel),sourceModel.getBlue(pixel)));

}

else if (modelStyle==CS_FLOAT){

return (int)(sourceModel.getRed(pixel)*0.3+sourceModel.getGreen(pixel)*0.59+sourceModel.getBlue(pixel)*0.11);

}

else {

return 0;

}

}

public int getAlpha(int pixel) {

return sourceModel.getAlpha(pixel);

}

public int getRed(int pixel) {

return getGrayLevel(pixel);

}

public int getGreen(int pixel) {

return getGrayLevel(pixel);

}

public int getBlue(int pixel) {

return getGrayLevel(pixel);

}

public int getRGB(int pixel) {

int gray=getGrayLevel(pixel);

return (getAlpha(pixel)24)+(gray16)+(gray8)+gray;

}

}

如果你有自己的算法或者想取得特殊的效果,你可以修改类GrayModel的方法getGrayLevel()。

色彩变换

根据上面的原理,我们也可以实现色彩变换,这样的效果就很多了。下面是一个反转变换的例子:

/* ReverseColorModel.java*/

/*@author:cherami */

/*email:cherami@163.net*/

import java.awt.image.*;

public class ReverseColorModel extends ColorModel {

ColorModel sourceModel;

public ReverseColorModel(ColorModel sourceModel) {

super(sourceModel.getPixelSize());

this.sourceModel=sourceModel;

}

public int getAlpha(int pixel) {

return sourceModel.getAlpha(pixel);

}

public int getRed(int pixel) {

return ~sourceModel.getRed(pixel);

}

public int getGreen(int pixel) {

return ~sourceModel.getGreen(pixel);

}

public int getBlue(int pixel) {

return ~sourceModel.getBlue(pixel);

}

public int getRGB(int pixel) {

return (getAlpha(pixel)24)+(getRed(pixel)16)+(getGreen(pixel)8)+getBlue(pixel);

}

}

/* ReverseColorModel.java*/

/*@author:cherami */

/*email:cherami@163.net*/

import java.awt.image.*;

public class ReverseFilter extends RGBImageFilter {

public ReverseFilter() {

canFilterIndexColorModel=true;

}

public void setColorModel(ColorModel cm) {

substituteColorModel(cm,new ReverseColorModel(cm));

}

public int filterRGB(int x,int y,int pixel) {

return pixel;

}

}

要想取得自己的效果,需要修改ReverseColorModel.java中的三个方法,getRed、getGreen、getBlue。

下面是上面的效果的一个总的演示程序。

/*GrayImage.java*/

/*@author:cherami */

/*email:cherami@163.net*/

import java.awt.*;

import java.awt.image.*;

import javax.swing.*;

import java.awt.color.*;

public class GrayImage extends JFrame{

Image source,gray,gray3,clip,bigimg;

BufferedImage bimg,gray2;

GrayFilter filter,filter2;

ImageIcon ii;

ImageFilter cropFilter;

int iw,ih;

public GrayImage() {

ii=new ImageIcon(\"images/11.gif\");

source=ii.getImage();

iw=source.getWidth(this);

ih=source.getHeight(this);

filter=new GrayFilter();

filter2=new GrayFilter(GrayModel.CS_FLOAT);

gray=createImage(new FilteredImageSource(source.getSource(),filter));

gray3=createImage(new FilteredImageSource(source.getSource(),filter2));

cropFilter=new CropImageFilter(5,5,iw-5,ih-5);

clip=createImage(new FilteredImageSource(source.getSource(),cropFilter));

bigimg=source.getScaledInstance(iw*2,ih*2,Image.SCALE_DEFAULT);

MediaTracker mt=new MediaTracker(this);

mt.addImage(gray,0);

try {

mt.waitForAll();

} catch (Exception e) {

}


当前题目:java图像识别代码,图像识别开源代码
文章源于:http://bjjierui.cn/article/hdgpjp.html

其他资讯