import org.apache.xmlgraphics.image.codec.tiff.TIFFEncodeParam;
import org.apache.xmlgraphics.image.codec.util.ImageEncoder;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
public class ImageUtil {
public static void main(String[] args) throws IOException {
File testDataDir = new File("pic");
final String destDir = "picimages";
for (File file : testDataDir.listFiles()) {
cleanLinesInImage(file, destDir);
cleanLinesInImage(file, destDir);
cleanLinesInImage(file, destDir);
}
}
/**
* @param sfile 需要去噪的图像
* @param destDir 去噪后的图像保存地址
* @throws IOException
*/
public static void cleanLinesInImage(File sfile, String destDir) throws IOException {
File destF = new File(destDir);
if (!destF.exists()) {
destF.mkdirs();
}
BufferedImage bufferedImage = ImageIO.read(sfile);
int h = bufferedImage.getHeight();
int w = bufferedImage.getWidth();
// 灰度化
int[][] gray = new int[w][h];
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
int argb = bufferedImage.getRGB(x, y);
// 图像加亮(调整亮度识别率非常高)
int r = (int) (((argb >> 16) & 0xFF) * 1.1 + 30);
int g = (int) (((argb >> 8) & 0xFF) * 1.1 + 30);
int b = (
tesseract图片文字识别 - 滤波 降噪 灰度 二值化 去除文本边框 去除验证码干扰线
最新推荐文章于 2024-03-21 22:37:35 发布