java文字识别代码实现 java文字编码

java中如何实现字符的识别

给你一段代码,看是否看得懂。我自己写得,可能不好。

成都创新互联公司专注于富拉尔基企业网站建设,成都响应式网站建设公司,商城开发。富拉尔基网站建设公司,为富拉尔基等地区提供建站服务。全流程定制开发,专业设计,全程项目跟踪,成都创新互联公司专业和态度为您提供的服务

/** *

* @param num

* @returnul

* 判断结果:

* litrue:整数

* lifalse:非整数

*/

public static boolean isInt(String num)

{

try {

Integer.parseInt(num);

} catch (NumberFormatException e) {

e.getMessage();

return false;

}

return true;

}

}

然后在需要的地方调用这个isInt方法就好了。这个是判断是否可以转换成数字。

我是这样调用的

/* 总行数为空的时候*/

if (classTotalLineString == null || classTotalLineString.equals("")

|| !Utils.isInt(classTotalLineString)){

totalLineErrorFlag = true;

2:还可以用正则表达式

判断是否是整数的正则表达式是:"^-?\\d+$"//整数

正整数是这个:"^[0-9]*[1-9][0-9]*$"//正整数

在需要的地方if判断下这个字符就好。

java怎么识别一个字符串中有汉字

可以使用正则表达式+中文字符编码区间验证一个字符串中是否包含汉字

代码如下:

public static void main(String[] args) {

int count = 0;

String regEx = "[\\u4e00-\\u9fa5]";

//System.out.println(regEx);

String str = "中文fdas ";

//System.out.println(str);

Pattern p = Pattern.compile(regEx);

Matcher m = p.matcher(str);

while (m.find()) {

for (int i = 0; i = m.groupCount(); i++) {

count = count + 1;

}

}

System.out.println("共有 " + count + "个 ");

}

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 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文字识别代码实现 java文字编码
URL标题:http://scjbc.cn/article/doedigd.html

其他资讯