导航:首页 > 文字图片 > java提取图片中的文字

java提取图片中的文字

发布时间:2022-05-01 13:39:43

Ⅰ java 实现图片的文字识别

摘要图像识别是目前很热门的研究领域,涉及的知识很广,包括信息论、模式识别、模糊数学、图像编码、内容分类等等。本文仅对使用Java实现了一个简单的图像文本二值处理,关于识别并未实现。
步骤
建立文本字符模板二值矩阵
对测试字符进行二值矩阵化处理
代码
/*
* @(#)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 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.e.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 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.e.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 <code>image< .>* @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;
}
资源来自:
http://blog.csdn.net/chief1985/article/details/2229572

如何用Java及OCR开发批量图片内容转文字

可以到云脉OCR SDK开发者平台下载文档识别API接口文档啊,开发支持Java、C++、C、 object pascal及objective-C等多种语言!可以用接入的OCR识别功能轻松实现批量图片内容转文字的操作

Ⅲ java是否可以从图片中抠出里面的数字 Java SE

你好很高兴告诉你:JAVA可以做到,你只要学习到了JAVA的IO机制 就知道该怎么做了。

Ⅳ 用java怎么获得一张图片上的一个文字的坐标点 求高手解答

//提示:坐标依次打印在命令符窗口
//提示:坐标依次打印在命令符窗口
//提示:坐标依次打印在命令符窗口
//不就是监听鼠标事件吗?
importjavax.swing.*;
importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.border.Border;

/**
*我想建立个界面,可以加载本机中图片。
*加载后可以通过鼠标点击获得图片上任意点坐标。
*提问者:sunny929929-试用期一级
*/
{
privateJLabeltipLabel;

/**
*main()
*/
publicstaticvoidmain(String[]args){
MyPictureframe=newMyPicture();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}

/**
*constructor
*/
publicMyPicture(){
setSize(800,600);//根据要求调整大小
setLocation(100,100);
setTitle("获得图片上任意点坐标");
setResizable(false);

Containercon=getContentPane();

ImageIconbgIcon=newImageIcon("bgpic.jpg");//注意图片的路径
ImagePanelbackpicPanel=newImagePanel(bgIcon);
backpicPanel.addMouseListener(this);
con.add(backpicPanel,BorderLayout.CENTER);

tipLabel=newJLabel("--------------------提示:坐标依次打印在屏幕上!--------------------");
con.add(tipLabel,BorderLayout.SOUTH);
}

/**
*
*/
publicvoidmousePressed(MouseEvente){
intx=e.getX();
inty=e.getY();
Stringmessage="("+x+","+y+")";
tipLabel.setText(message);
System.out.println(message);

}

publicvoidmouseReleased(MouseEvente){

}

publicvoidmouseEntered(MouseEvente){

}

publicvoidmouseExited(MouseEvente){

}

publicvoidmouseClicked(MouseEvente){

}

}

/**
*类ImagePanel,用于添加背景图片
*/
classImagePanelextendsJPanel{
privateImageimg;
publicImagePanel(ImageIconimageIcon){
img=imageIcon.getImage();
}

publicvoidpaintComponent(Graphicsg){
super.paintComponent(g);
g.drawImage(img,0,0,this);
}

}

Ⅳ java有读取图片里面文字的方法吗

使用tesseract-ocr,可以识别简单的验证码,中文没尝试过

Ⅵ 如何利用java在图片上添加文字

// 读取模板图片内容
BufferedImage image = ImageIO.read(new FileInputStream("c:\\test.jpg"));
Graphics2D g = image.createGraphics();// 得到图形上下文
g.setColor(Color.BLACK); // 设置画笔颜色
// 设置字体
g.setFont(new Font("宋体", Font.LAYOUT_LEFT_TO_RIGHT, 15));// 写入签名
// 下面这一句中的43,image.getHeight()-10可以改成你要的坐标。
g.drawString("这是新加入的文字", 43, image.getHeight() - 10);
g.dispose();
FileOutputStream out = new FileOutputStream("c:\\test1.jpg");
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
out.close();
希望我的回答能帮助你 谢谢 呵呵 答案补充 肯定了 在一张纸上写字 肯定会自动换行的 否则写外面?逻辑都通不过去~ 答案补充 把你的意思说出了 是不是随便的写字然后就提交 就把字写在了图片上还是?多少字 有没有约束? 答案补充 g.drawString("这是新加入的文字", 43, image.getHeight() - 10);

在这个做处理 你规定了字体的大小 那么获取字符的长度*大小 一次判断不要大于宽度 否则image.getHeight() - 10++ 你试试 应该可以的 我这里没有Eclipse 答案补充 public class mains {

/**
* @param args
*/

private static int fontsize = 15;

static String jj(String str)
{
String sContent = str;
sContent=sContent.replaceAll(" "," ");
sContent=sContent.replaceAll("<br/>","/");
sContent=sContent.replaceAll("<br>","/");

return sContent;
} 答案补充 static void hh(String str)
{
BufferedImage image;
try {
image = ImageIO.read(new FileInputStream("E:\\dian zi za /789.jpg"));
Graphics2D g = image.createGraphics();// 得到图形上下文
g.setColor(Color.BLACK); // 设置画笔颜色
// 设置字体
g.setFont(new Font("宋体", Font.LAYOUT_LEFT_TO_RIGHT, fontsize));// 写入签名
// 下面这一句中的43,image.getHeight()-10可以改成你要的坐标。

String text = jj(str); 答案补充 String [] text1 = text.split("/");

int h = image.getHeight();
int w = image.getWidth();
for(int i=0;i<text1.length;i++)
{

g.drawString(text1[i],0,fontsize+i*fontsize);
}
g.dispose();
FileOutputStream out = new FileOutputStream("E:\\dian zi za /789.jpg");
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
out.close(); 答案补充 public static void main(String[] args) {
// TODO Auto-generated method stub

hh("sdakljsdhww<br/>asdasd<br/>a");
}

}
试试 可以换行 答案补充 关于 图片的尺寸以及字体是否超出 你自己试着解决下 不要过于依赖问

Ⅶ 用Java读取一张图片,并识别图中的所有汉字,怎么解决

这个要是自己去写,估计很难,需要用到很多AI智能的算法,可以调用谷歌或者网络的识图API

Ⅷ 用JAVA编写一个程序识别图片上的文字

这种想法太疯狂了。。目前能实现辨别图片里的数字是正常的,辨别英文也有点难度,中文就更难了。。辨别图像里面的文字数字,不是想象的那么简单的,要从像素着手的,比较特定区域的像素,然后程序做出判断,程序实现起来还是比较复杂的

Ⅸ Java如何实现从一个指定图片中提取出内容!例如图片中的完整车牌!

java本身无法实现。估计要调用第三方程序。

阅读全文

与java提取图片中的文字相关的资料

热点内容
老北京网鞋价格及图片 浏览:212
动漫战友图片 浏览:890
儿童连心发型图片 浏览:18
男生图片帅气高清头像图片 浏览:508
暖心的图片唯美的女孩图片 浏览:135
美女的小便真图片大全 浏览:182
如何制作图片电子书 浏览:635
手工水果摆盘简单图片 浏览:168
打印图片怎么居中 浏览:648
碎花点可爱图片壁纸 浏览:786
中国红包文字图片大全 浏览:875
如何能看图片上模糊的字 浏览:160
男生qq拍照图片 浏览:640
李晓璐发型图片 浏览:148
女孩闺蜜头像图片 浏览:989
可爱小斗图图片 浏览:504
用ps怎么裁剪图片 浏览:53
小林变成男生的图片 浏览:508
男生女生头部的简笔画图片 浏览:715
头像孩子图片大全可爱 浏览:272