「java照片识别」java识别图片内容

博主:adminadmin 2023-03-20 17:10:07 650

今天给各位分享java照片识别的知识,其中也会对java识别图片内容进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

java识别照片是彩色还是黑白照

你可以判断图片的其中一个像素点,彩色图一般都是RGB组合成的,格式是那种3*3的矩阵,而黑白图像的像素点是通过一个固定的公式转换来的,转换后的像素点是1*3的矩阵

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中提供了ImageInputStream类来对文件是否为图片进行判断,示例如下:

/** 

  * 判断文件是否为图片br 

  * br 

  * @param pInput 文件名br 

  * @param pImgeFlag 判断具体文件类型br 

  * @return 检查后的结果br 

  * @throws Exception 

  */ 

public static boolean isPicture(String  pInput, 

                           String pImgeFlag) throws Exception{ 

  // 文件名称为空的场合 

  if(Check.isNull(pInput)){ 

   // 返回不和合法 

   return false; 

  } 

  // 获得文件后缀名 

  String tmpName = pInput.substring(pInput.lastIndexOf(".") + 1, 

                              pInput.length()); 

  // 声明图片后缀名数组 

  String imgeArray [][] = { 

    {"bmp", "0"}, {"dib", "1"}, {"gif", "2"}, 

    {"jfif", "3"}, {"jpe", "4"}, {"jpeg", "5"}, 

    {"jpg", "6"}, {"png", "7"} ,{"tif", "8"}, 

    {"tiff", "9"}, {"ico", "10"} 

  }; 

  // 遍历名称数组 

  for(int i = 0; iimgeArray.length;i++){ 

   // 判断单个类型文件的场合 

   if(! Check.isNull(pImgeFlag) 

       imgeArray [i][0].equals(tmpName.toLowerCase()) 

    imgeArray [i][1].equals(pImgeFlag)){ 

    return true; 

   } 

   // 判断符合全部类型的场合 

   if(Check.isNull(pImgeFlag) 

       imgeArray [i][0].equals(tmpName.toLowerCase())){ 

    return true; 

   } 

  } 

  return false; 

}

java照片识别的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java识别图片内容、java照片识别的信息别忘了在本站进行查找喔。