1. 程式人生 > >簡單驗證碼去幹擾線

簡單驗證碼去幹擾線

// 驗證碼識別.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; }

這裡寫圖片描述