「java图像文字」java语言图片

博主:adminadmin 2022-12-17 10:09:06 67

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

本文目录一览:

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如何把图片和文字从前端传图片到后端

1.在 eclipse中创建一个web工

程项目。然后在lib文件夹中

添加文件上传需要用到的组合中。

2. FileUploadServlet.java的内

容显示出来。

3.编辑好

FileUploadServlet java文件后

在web.xm文件中配置映射。

如何利用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 zhi/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;itext1.length;i++)

{

g.drawString(text1[i],0,fontsize+i*fontsize);

}

g.dispose();

FileOutputStream out = new FileOutputStream("E:\\dian zi za zhi/789.jpg");

JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);

encoder.encode(image);

out.close(); 答案补充 public static void main(String[] args) {

// TODO Auto-generated method stub

hh("sdakljsdhwwbr/asdasdbr/a");

}

}

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

关于java图像文字和java语言图片的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2022-12-17,除非注明,否则均为首码项目网原创文章,转载请注明出处。