文档图像SauvolA二值化算法C++实现

这个二值化算法主要针对文档图像,原理较复杂,感兴趣的同学可以自己搜一下论文看看。下面先给出代码

void SauvolA(vector<string> &FilesVec,vector<Mat> &outputImg,string root)
{
    char version;
    int c;
    int winx = 0, winy = 0;
    float optK = 0.5;
    bool didSpecifyK = false;
    string Saveroot;
    // Determine the method
    for (int i = 0;i < FilesVec.size();i++)
    {
        cout << "image name: " << FilesVec[i] << endl;
        Mat input = imread(FilesVec[i], CV_LOAD_IMAGE_GRAYSCALE);
        if ((input.rows <= 0) || (input.cols <= 0))
        {
            cout << "*** ERROR: Couldn't read input image " << FilesVec[i] << endl;
            exit(1);
        }
        Saveroot.clear();
        Saveroot = root;
        Saveroot = root + (FilesVec[i].substr(FilesVec[i].find_last_of("\\") + 1));
        winy = (int)(2.0 * input.rows - 1) / 3;
        winx = (int)input.cols - 1 < winy ? input.cols - 1 : winy;
        if (winx > 100)
            winx = winy = 40;
        Mat output(input.rows, input.cols, CV_8U);
        NiblackSauvolaWolfJolion(input, output, winx, winy, optK, 128);
        outputImg.push_back(output);
        cerr << "Writing binarized image to file '" << Saveroot << "'.\n";
        imwrite(Saveroot, output);
    }
    cout << "end" << endl;
}

void NiblackSauvolaWolfJolion(Mat im, Mat output, int winx, int winy, double k, double dR)//k=0.5,dR=128;
{
    double m, s, max_s;
    double th = 0;
    double min_I, max_I;
    int wxh = winx / 2;
    int wyh = winy / 2;
    in

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值