Dict.CN 在线词典, 英语学习, 在线翻译 ------------- MyGitee 朱秋贵内科诊所 My腾云code

验证码识别技术(三)去除噪音

对于去除噪音的技术,没有一个统一的算法,但是一个网站的验证码噪音,一定是有一定的规则的。只有分析出这个规则,就可以写相应的代码去除干扰。

例如,通过第二步,我们已经去除了一个验证码图片的背景,

很明显能看出,这个验证码图片,被后期的的时候,加入了一条干扰线,而且干扰线出像素点事一致的,那就好办了,我们可以写一个程序,顺序的扫描这条干扰线,然后动态的去除。可以按照第二步的分析像素的方法分析,可以容易的分析出干扰数据。

具体的代码如下所示:

复制代码
/**
     * 去噪音(去除干扰线)
     * 
     * @param image
     *            原图片
     * @return 去噪音后的图片
     */
    public static BufferedImage StartDenoising(BufferedImage img) {

        int width = img.getWidth();
        int height = img.getHeight();

        for (int x = 0; x < width; x++) {
            // 记录数列的点
            List<PixColorShow> PixColorShowList = new ArrayList<PixColorShow>();
            for (int y = 0; y < height; y++) {
                Color color = new Color(img.getRGB(x, y));

                PixColorShow pColorShow = new PixColorShow();
                pColorShow.pixValue = color.getRed();
                pColorShow.YCoordinate = y;
                PixColorShowList.add(pColorShow);
            }

            //判断连续点
            StringBuffer sBuffer = new StringBuffer();
            for (int index = 0; index < PixColorShowList.size(); index++) {
                if (PixColorShowList.get(index).pixValue < 100) {
                    sBuffer.append("1");
                } else {
                    sBuffer.append("0");
                }
            }
            
            String showString=sBuffer.toString();
            
            //System.out.println(showString);
                    
            ArrayList<Integer> seriesPointList=new ArrayList<Integer>();            
            Pattern pattern = Pattern.compile("0110");
            Matcher matcher = pattern.matcher(showString);
    
            while (matcher.find()) {
                int startpoise =matcher.start();
                int endpoise=matcher.end();            
                while (startpoise<endpoise) {
                    seriesPointList.add(startpoise);
                    startpoise++;        
                }            
            }
                                
            // 去除连续点
            for (int i=0;i<seriesPointList.size();i++) {

                img.setRGB(x, seriesPointList.get(i), Color.WHITE.getRGB());
            }

        }

        return img;
    }

http://www.cnblogs.com/nyist2007/p/4758460.html

posted @ 2016-06-08 17:32  cn2023  阅读(1647)  评论(0编辑  收藏  举报