【发布时间】:2015-06-30 08:01:51
【问题描述】:
我想识别Pic1中的数字。
我做了一些工作,它返回到pic2
这是我的代码:
package captchadecproj;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
/*
* @author Mr__Hamid
*/
public class NewClass {
public static void main(String args[]) throws IOException {
int width = 110;
int heigth = 40;
BufferedImage image1 = new BufferedImage(width, heigth, BufferedImage.TYPE_INT_RGB);
BufferedImage num1 = new BufferedImage(width, heigth, BufferedImage.TYPE_INT_RGB);
BufferedImage image = null;
File f = null;
try {
f = new File("E:\\Desktop 2\\Captcha Project\\CaptchaDecoder\\captchaDecProj\\167.png");
image = new BufferedImage(width, heigth, BufferedImage.TYPE_INT_ARGB);
image = ImageIO.read(f);
System.out.println("Read!");
} catch (IOException e) {
System.out.println("Error" + e);
}
int[] pixel = null;
for (int y = 0; y < image.getHeight(); y++) {
for (int x = 0; x < image.getWidth(); x++) {
pixel = image.getRaster().getPixel(x, y, new int[3]);
if (pixel[0] < 30 & pixel[1] > 130 & pixel[2] < 110 & pixel[2] > 60) {
image1.setRGB(x, y, Integer.parseInt("ffffff".trim(), 16));
System.out.println(pixel[0] + " - " + pixel[1] + " - " + pixel[2] + " - " + (image.getWidth() * y + x));
} else {
image1.setRGB(x, y, 1);
System.out.println(pixel[0] + " - " + pixel[1] + " - " + pixel[2] + " - " + (image.getWidth() * y + x));
}
}
}
try {
f = new File("D:\\Original.jpg");
ImageIO.write(image, "jpg", f);
f = new File("D:\\black&White.jpg");
ImageIO.write(image1, "jpg", f);
System.out.println("Writed");
} catch (IOException e) {
System.out.println("Error" + e);
}
}
}
我有两个问题:
如何拆分这些数字?
我如何识别哪一个是我的号码?
例如上传的图片:7,1,6
【问题讨论】:
-
How can I split these numbers?将您的图像转换为 bw(白色背景,黑色文本),然后在具有最少黑色(0 像素)的列上拆分How can I recognize which one is my number? -
我的代码将图像转换为 bw(白色文本和黑色背景)。然后呢?
-
然后创建直方图,计算每列中非背景颜色的数量。然后从您的图像中提取仅具有非背景颜色的区域。这将是带有数字(或任何其他字符)的部分
-
你介意分享一些代码吗?
标签: java image image-processing numbers ocr