java图片识别高效代码 java图片识别高效代码怎么用-成都快上网建站

java图片识别高效代码 java图片识别高效代码怎么用

java 实现图片的文字识别

摘要图像识别是目前很热门的研究领域,涉及的知识很广,包括信息论、模式识别、模糊数学、图像编码、内容分类等等。本文仅对使用Java实现了一个简单的图像文本二值处理,关于识别并未实现。

十载的昌图网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。营销型网站建设的优势是能够根据用户设备显示端的尺寸不同,自动调整昌图建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。成都创新互联从事“昌图网站设计”,“昌图网站推广”以来,每个客户项目都认真落实执行。

步骤

建立文本字符模板二值矩阵

对测试字符进行二值矩阵化处理

代码

/*

* @(#)StdModelRepository.java

*

* This program is free software; you can redistribute it and/or modify

* it under the terms of the GNU General Public License as published by

* the Free Software Foundation; either version 3 of the License, or

* (at your option) any later version.

*

* This program is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

* GNU Library General Public License for more details.

* You should have received a copy of the GNU General Public License

* along with this program; if not, write to the Free Software

* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

*/

package cn.edu.ynu.sei.recognition.util;import java.awt.Image;import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import java.util.ArrayList;import java.util.List;import java.util.logging.Level;import java.util.logging.Logger;import javax.imageio.ImageIO;/** * Hold character charImgs as standard model repository.

* @author 88250

* @version 1.0.0.0, Mar 20, 2008

*/

public class StdModelRepository {

/** * hold character images

*/ List charImgs = new ArrayList();

/** * default width of a character

*/ static int width = 16 /** * default height of a character

*/ static int height = 28 /** * standard character model matrix

*/ public int[][][] stdCharMatrix = new int[27][width][height];

/** * Default constructor.

*/ public StdModelRepository() {

BufferedImage lowercase = null try {

lowercase = ImageIO.read(new File("lowercase.png"));

} catch (IOException ex) {

Logger.getLogger(StdModelRepository.class.getName()).

log(Level.SEVERE, null, ex);

}

for (int i = 0 i 26 i++) {

charImgs.add(lowercase.getSubimage(i * width,

0,

width,

height));

}

for (int i = 0 i charImgs.size(); i++) {

Image image = charImgs.get(i);

int[] pixels = ImageUtils.getPixels(image,

image.getWidth(null),

image.getHeight(null));

stdCharMatrix[i] = ImageUtils.getSymbolMatrix(pixels, 0).clone();

ImageUtils.displayMatrix(stdCharMatrix[i]);

}

}

}

/*

* @(#)ImageUtils.java

*

* This program is free software; you can redistribute it and/or modify

* it under the terms of the GNU General Public License as published by

* the Free Software Foundation; either version 3 of the License, or

* (at your option) any later version.

*

* This program is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

* GNU Library General Public License for more details.

* You should have received a copy of the GNU General Public License

* along with this program; if not, write to the Free Software

* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

*/

package cn.edu.ynu.sei.recognition.util;import java.awt.Image;import java.awt.image.PixelGrabber;import java.util.logging.Level;import java.util.logging.Logger;/** * Mainipulation of image data.

* @author 88250

* @version 1.0.0.3, Mar 20, 2008

*/

public class ImageUtils {

/** * Return all of the pixel values of sepecified codeimage .* @param image the sepecified image

* @param width width of the image

* @param height height of the image

* @return */ public static int[] getPixels(Image image, int width, int height) {

int[] pixels = new int[width * height];

try {

new PixelGrabber(image, 0, 0, width, height, pixels, 0, width).grabPixels();

} catch (InterruptedException ex) {

Logger.getLogger(ImageUtils.class.getName()).

log(Level.SEVERE, null, ex);

}

return pixels;

}

资源来自:

JAVA识别图片验证码

package com.he;

import javax.servlet.*;

import javax.servlet.http.*;

import java.io.*;

import java.util.*;

import java.awt.*;

import java.awt.image.*;

import javax.imageio.*;

public class CodeFact

extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response) throws

ServletException, IOException {

//设置页面不缓存

response.setHeader("Pragma", "No-cache");

response.setHeader("Cache-Control", "no-cache");

response.setDateHeader("Expires", 0);

// 在内存中创建图象

int width = 60, height = 20;

BufferedImage image = new BufferedImage(width, height,

BufferedImage.TYPE_INT_RGB);

// 获取图形上下文

Graphics g = image.getGraphics();

//生成随机类

Random random = new Random();

// 设定背景色

g.setColor(getRandColor(200, 250));

g.fillRect(0, 0, width, height);

//设定字体

g.setFont(new Font("Times New Roman", Font.PLAIN, 18));

//画边框

g.setColor(new Color(33,66,99));

g.drawRect(0,0,width-1,height-1);

// 随机产生155条干扰线,使图象中的认证码不易被其它程序探测到

g.setColor(getRandColor(160, 200));

for (int i = 0; i 155; i++) {

int x = random.nextInt(width);

int y = random.nextInt(height);

int xl = random.nextInt(12);

int yl = random.nextInt(12);

g.drawLine(x, y, x + xl, y + yl);

}

// 取随机产生的认证码(4位数字)

String sRand = "";

for (int i = 0; i 4; i++) {

String rand = String.valueOf(random.nextInt(10));

sRand += rand;

// 将认证码显示到图象中

g.setColor(new Color(20 + random.nextInt(110), 20 + random.nextInt(110),

20 + random.nextInt(110))); //调用函数出来的颜色相同,可能是因为种子太接近,所以只能直接生成

g.drawString(rand, 13 * i + 6, 16);

}

// 将认证码存入SESSION

HttpSession session = request.getSession();

session.setAttribute("rand", sRand);

// 图象生效

g.dispose();

// 输出图象到页面

ImageIO.write(image, "JPEG", response.getOutputStream());

}

public void doPost(HttpServletRequest request, HttpServletResponse response) throws

ServletException, IOException {

doGet(request, response);

}

//给定范围获得随机颜色

private Color getRandColor(int fc, int bc) {

Random random = new Random();

if (fc 255) {

fc = 255;

}

if (bc 255) {

bc = 255;

}

int r = fc + random.nextInt(bc - fc);

int g = fc + random.nextInt(bc - fc);

int b = fc + random.nextInt(bc - fc);

return new Color(r, g, b);

}

}

你试试!!

java根据ocr识别名片,谁有java处理图片的代码,要效果好一点、识别效率高的、

云脉OCR SDK开发者平台上有提供名片识别API接口,支持Java、C++、C、object pascal及objective-C等多种语言,识别速度快,平均识别时间少于0.6秒,识别率高,字符识别率97.37%,用户登录后即可自主下载接口.....

通过文字搜索图片 java代码实现及说明

import ja.io.*;

//获取文件夹内容

public class getthing

{

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

{

System.out.println(welstr);

listFile(new File("e:\\aa")); //想要搜索的路径

}

public static void listFile(File file) throws Exception

{

if(file.isFile())

{

//输出的是完整的文件夹内文件的路径

System.out.println("File :"+file.getAbsolutePath());

//01.jpg就是你要找的图片

if (file.getAbsolutePath().endsWith("01.jpg"))

System.out.println("有搜索的图片");

}

else

{

System.out.println("Dir :"+file.getAbsolutePath());

File[] files =file.listFiles();

for(int i=0;ifiles.length;i++)

{

listFile(files[i]);

System.out.println("回车");

}

}

}

}

1 首先确定你要搜索的目录

2 要搜索的关键字 如“花”

3 只搜索图片类型 .jpg .gif .png .bmp之类的

4 在文本框里获得搜索的关键字

5 取得要搜索目录下的所有图片类型的名字

6 用关键字和取得的文件名一一进行对比

7 若有关键字 记录该图片的名字

8 若都没关键字 表示无该名字的图片

9 空白区域你可以用一个窗体来表示

10 把搜索到的图片都显示在这个窗体。

求一个实现java图片数字识别并储存在一个数组里的的代码

//byte数组到图片到硬盘上

public void byte2image(byte[] data,String path){

if(data.length3||path.equals("")) return;//判断输入的byte是否为空

try{

FileImageOutputStream imageOutput = new FileImageOutputStream(new File(path));//打开输入流

imageOutput.write(data, 0, data.length);//将byte写入硬盘

imageOutput.close();

System.out.println("Make Picture success,Please find image in " + path);

} catch(Exception ex) {

System.out.println("Exception: " + ex);

ex.printStackTrace();

}

}


本文名称:java图片识别高效代码 java图片识别高效代码怎么用
文章分享:http://kswjz.com/article/hiegcg.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流