图片解析
来源:互联网 发布:扫码枪软件下载 编辑:程序博客网 时间:2024/05/06 09:00
/** * 测试验证码解析 * @author hanmanyi * */public class TestOCR {/** * @param args * @throws IOException */public static void main(String[] args) throws IOException {String path = "E:\\ZGCCZJworksp\\HMYTicket\\image\\passCode.jpg";//String path = "E:\\ZGCCZJworksp\\HMYTicket\\image\\untitled.bmp";//for (int i = 0; i < 100; i++) {try {filter(path);//String valCode = new OCR().recognizeText("C:\\Program Files\\Tesseract-OCR\\",new File(path), "jpg");//String valCode = new OCR().recognizeText("C:\\Program Files\\Tesseract-OCR\\",new File(path), "bmp");//valCode = valCode.replace("\r\n\r\n", "");//System.out.println(i+"|"+valCode);//} catch (IOException e) {//e.printStackTrace();} catch (Exception e) {e.printStackTrace();}//}}/** * 过滤掉图片中的直线和孤立点 * 用被使用最多的颜色(即背景色)代替 * */public static void filter(String path) {InputStream instream;OutputStream out;String newpath = "E:\\ZGCCZJworksp\\HMYTicket\\image\\new_passCode.jpg";try {BufferedImage imgOrg = ImageIO.read(new File(path));instream = convert(imgOrg);//instream = new FileInputStream(new File(path));out = new FileOutputStream(new File(newpath));int byteread = 0;byte[] tmp = new byte[1];while ((byteread = instream.read(tmp)) != -1) {out.write(tmp);}} catch (Exception e) {e.printStackTrace();}}/** * 用被使用最多的颜色(即背景色)代替 * @param imgOrg */private static InputStream convert(BufferedImage img) {InputStream is = null;int width = img.getWidth();int height = img.getHeight();for (int j = 0; j < height; j++) {for (int i = 0; i < width; i++) {Long RGB = Long.parseLong(""+img.getRGB(i, j));Map<Long, Integer> map = getMaxColor(img,i,j);Integer c = map.get(RGB);System.out.println(RGB);System.out.println(map);if (c != null && c >1) {img.setRGB(i, j, 0xFF0000);}}}img.flush();ImageOutputStream imOut;ByteArrayOutputStream bs = new ByteArrayOutputStream();try {imOut = ImageIO.createImageOutputStream(bs);ImageIO.write(img, "jpg",imOut);is= new ByteArrayInputStream(bs.toByteArray());} catch (IOException e) {e.printStackTrace();}return is;}/** * 周围使用最多的颜色 * @param imgOrg */private static Map<Long, Integer> getMaxColor(BufferedImage img,int x,int y){int width = img.getWidth();int height = img.getHeight();int range = 2;Map<Long, Integer> map = new HashMap<Long, Integer>();for (int j = y-range < 0?0:y-range; j < height && j<=y+range ; j++) {for (int i = x-range < 0?0:x-range; i < width && i<=x+range; i++) {long RGB = img.getRGB(i, j);Integer c = map.get(RGB);if (c == null) {map.put(RGB, 1);} else {map.put(RGB, c + 1);}}}return map;}}
0 0
- 图片解析
- 图片解析
- 解析图片
- BitMap解析图片显示图片
- marquee 解析 图片滚动
- MTK图片解析流程
- MTK图片解析流程
- BMP图片解析
- TinyXML解析word图片
- 解析图片二维码
- cocos2dx 图片缓存解析
- dedecms 图片标签解析
- bmp图片解析
- 解析响应式图片
- 解析本地二维码图片
- BitmapFactory.Options 图片解析
- 图片压缩CompressUtil解析
- 解析下拉图片放大
- 四大牛人看外国文献的方法
- Android学习——异常(1)
- GCD 之一: Dispatch Queue
- Map遍历四种方法
- 余凯在清华的讲座笔记
- 图片解析
- php进制转换
- 运行和学习高通提供的一些例子
- No WebApplicationContext found: no ContextLoaderListener registered?
- 自动点击屏幕-调用android隐藏的功能
- POJ1161 Walls(Floyd+建图)
- android Intent传递 object , list<object>,list<Map<String,Object>>
- 使用Ganglia对hadoop进行监控
- ZOJ 3432 Find the Lost Sock