简单验证码去干扰线

// 验证码识别.cpp: 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include "opencv2/opencv.hpp"
using namespace cv;


int main()
{
    Mat src, grayImage, thresholdImage;
    src = imread("charc.png");
    if (src.empty()) {
        return -1;
    }
    namedWindow("src");
    imshow("src",src);

    //转换成灰度图像
    cvtColor(src, grayImage, CV_BGRA2GRAY);
    namedWindow("gray");
    imshow("gray", grayImage);


    //转换成二值图像
    adaptiveThreshold(grayImage, thresholdImage, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY, 15, 3);
    namedWindow("thresholdImage");
    imshow("thresholdImage", thresholdImage);


    Mat temp1,temp2;
    Mat kelner = getStructuringElement(MORPH_RECT, Size(3, 3), Point(-1, -1));
    erode(~thresholdImage,temp1, kelner, Point(-1,-1)); //腐蚀
    dilate(temp1, temp2, kelner, Point(-1, -1)); //膨胀
    bitwise_not(temp2, temp2); //图像反色
    namedWindow("morph");
    imshow("morph", temp2);

    waitKey();
    return 0;
}


简单验证码去干扰线_第1张图片

你可能感兴趣的:(opencv,opencv,验证码去干扰线)