当前位置:网站首页 > Java教程 > 正文

tesseract java教程



 1 package zhen; 2 import java.awt.Color; 3 import java.awt.image.BufferedImage; 4 import java.io.File; 5 import java.io.FileInputStream; 6 import java.io.IOException; 7 8 import javax.imageio.ImageIO; 9 10 11 public class LineMark{ 12 public static void clean(String fromPath,String toPath) throws IOException{ 13 File file1 = new File(fromPath); 14 BufferedImage image = ImageIO.read(file1); 15 16 BufferedImage sourceImg =ImageIO.read(new FileInputStream(file1)); // 获取图片的长宽 17 int width = sourceImg.getWidth(); 18 int height = sourceImg.getHeight(); 19 20 / 21 * 创建3维数组用于保存图片rgb数据 22 */ 23 int[][][] array = new int[width][height][3]; 24 for(int i=0;i<width;i++){ // 获取图片中所有像素点的rgb 25 for(int j=0;j<height;j++){ 26 int pixel = image.getRGB(i, j); //获得坐标(i,j)的像素 27 int red = (pixel & 0xff0000) >> 16; 28 int green = (pixel & 0xff00) >> 8; 29 int blue = (pixel & 0xff); //通过坐标(i,j)的像素值获得r,g,b的值 30 array[i][j][0] = red; 31 array[i][j][1] = green; 32 array[i][j][2] = blue; 33 } 34 } 35 36 / 37 * 清除表格线: 38 * 竖线:绝大多数点的x值都为255 39 */ 40 for(int i=0;i<width;i++){ 41 int nums = 0; 42 for(int j=0;j<height;j++){ 43 if(array[i][j][0]<128 && array[i][j][1]<128 && array[i][j][2]<128){ 44 nums += 1; 45 } 46 } 47 if(nums > height * 0.8){ 48 for(int n=0;n<height;n++){ 49 array[i][n][0] = 255; 50 array[i][n][1] = 255; 51 array[i][n][2] = 255; 52 } 53 } 54 } 55 / 56 * 清除表格线: 57 * 横线:绝大多数点的y值都为255 58 */ 59 for(int j=0;j<height;j++){ 60 int nums = 0; 61 for(int i=0;i<width;i++){ 62 if(array[i][j][0]<128 && array[i][j][1]<128 && array[i][j][2]<128){ 63 nums += 1; 64 } 65 } 66 if(nums > height * 0.8){ 67 for(int n=0;n<width;n++){ 68 array[n][j][0] = 255; 69 array[n][j][1] = 255; 70 array[n][j][2] = 255; 71 } 72 } 73 } 74 / 75 * 大点 76 */ 77 for(int i=0;i<width;i++){ 78 for(int j=0;j<height;j++){ 79 int cover = new Color(array[i][j][0],array[i][j][1],array[i][j][2]).getRGB(); 80 image.setRGB(i,j,cover); 81 } 82 } 83 File file2 = new File(toPath); 84 ImageIO.write(image, "png", file2); 85 } 86 87 / 88 * 测试 89 * @param args 90 */ 91 public static void main(String[] args){ 92 String fromPath = "E:\testData\tess\111.png"; 93 String toPath = "E:\testData\tess\112.png"; 94 try { 95 LineMark.clean(fromPath,toPath); 96 } catch (IOException e) { 97 e.printStackTrace(); 98 } 99 } 100 }

  • 上一篇: 谭浩强java教程
  • 下一篇: java异常教程
  • 版权声明


    相关文章:

  • 谭浩强java教程2025-01-27 14:18:00
  • java领域编程教程2025-01-27 14:18:00
  • java安装32位教程2025-01-27 14:18:00
  • java函数接口教程2025-01-27 14:18:00
  • java myeclipse教程视频2025-01-27 14:18:00
  • java异常教程2025-01-27 14:18:00
  • java数据抓取教程2025-01-27 14:18:00
  • java数据采集教程2025-01-27 14:18:00
  • java 5天教程2025-01-27 14:18:00
  • java教程 自营2025-01-27 14:18:00