Java text image recognition (1) [88250 original]__java

Source: Internet
Author: User
  SummaryImage recognition is a very popular research field, involving a wide range of knowledge, including information theory, pattern recognition, fuzzy mathematics, Image coding, content classification and so on. This article only uses Java to implement a simple image text binary processing, on the recognition is not implemented.

Steps Create a text character template two value matrix two-valued matrix processing of test characters Code/*
* @ (#) Stdmodelrepository.java
*
* This are 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 are distributed in the hope that it'll be useful,
* but without any WARRANTY; Without even the implied warranty of
* merchantability or FITNESS for A particular purpose. 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., Temple Place-suite, 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 < bufferedimage > Charimgs = new ArrayList < BufferedImage > ();

/**
* 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 [][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 < 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 are 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 are distributed in the hope that it'll be useful,
* but without any WARRANTY; Without even the implied warranty of
* merchantability or FITNESS for A particular purpose. 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., Temple Place-suite, 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 <code>image</code>.
* @param image The sepecified image
* @param width width of the <code>image</code>
* @param height of the <code>image</code>
* @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;
}

/**
* Get a matrix that described the <code>pixels</code>.
* <p>
* For example, the result is the matrix like this:
* <center>
* 0000000000000000<br>
* 0000000000000000<br>
* 0001111111110000<br>
* 0011111111111000<br>
* 0011111111111100<br>
* 0011000000011100<br>
* 0000000000011100<br>
* 0000111111111100<br>
* 0011111111111100<br>
* 0011111110011100<br>
* 0111100000011100<br>
* 0111100000011100<br>
* 0111100000111100<br>
* 0111100001111110<br>
* 0011111111111100<br>
* 0011111111111100<br>
* 0001111111111100<br>
* 0000000000000000<br>
* 0000000000000000<br>
* </center>
* It describes the Alphbet ' a '.
* </p>
* @param pixels the pixel array
* @param sparsefactor sparse factor
* @return A matrix that describes a Alphbet
*/
public static int [] Getsymbolmatrix (int [] pixels, int sparsefactor) {
Final int width = stdmodelrepository.width;
Final int height = stdmodelrepository.height;
int [] [] ret = new int [width][height];

for (int i = 0; i < height; i + +) {
for (int j = 0; J < width; j + +) {
if (pixels[i * width + j] = = 1) {
Ret[j][i] = 0;
} else {
Ret[j][i] = 1;
}
}
}

return ret;
}

/**
* Print the <code>matrix</code> under console.
* @param matrix the sepecified matrix data
*/
public static void Displaymatrix (int [] matrix) {
System.out.println ("");

for (int i = 0; I < matrix[0].length i + +) {
for (int j =

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.