導航:首頁 > 文字圖片 > 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提取圖片中的文字相關的資料

熱點內容
老北京網鞋價格及圖片 瀏覽:209
動漫戰友圖片 瀏覽:886
兒童連心發型圖片 瀏覽:15
男生圖片帥氣高清頭像圖片 瀏覽:503
暖心的圖片唯美的女孩圖片 瀏覽:134
美女的小便真圖片大全 瀏覽:181
如何製作圖片電子書 瀏覽:634
手工水果擺盤簡單圖片 瀏覽:167
列印圖片怎麼居中 瀏覽:647
碎花點可愛圖片壁紙 瀏覽:785
中國紅包文字圖片大全 瀏覽:873
如何能看圖片上模糊的字 瀏覽:159
男生qq拍照圖片 瀏覽:639
李曉璐發型圖片 瀏覽:147
女孩閨蜜頭像圖片 瀏覽:988
可愛小斗圖圖片 瀏覽:504
用ps怎麼裁剪圖片 瀏覽:52
小林變成男生的圖片 瀏覽:508
男生女生頭部的簡筆畫圖片 瀏覽:714
頭像孩子圖片大全可愛 瀏覽:271