c_cpp opencv threshold cal

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp opencv threshold cal相关的知识,希望对你有一定的参考价值。

#include <opencv/cv.h>
#include <iostream>

using namespace cv;

// sum up given row
long int sumup(Mat row, int width)
{
    std::cout << "Sumup" << std::endl;
    long int total = 0;
    for (int i = 0; i < width; i++)
    {
        total += row.at<uchar>(0, i);
    }
    std::cout << "total: " << total << std::endl;
    return total;
}


// find the bottom threshold value.
int find_bottom(Mat img, int threshold)
{
    int rows = img.rows;
    int cols = img.cols;

    int total_rows;
    int bottom;

    bottom = -1;
    for (int i = rows - 1; i >= 0; i --)
    {
        total_rows = sumup(img.row(i), cols);

        if (total_rows > threshold)
        {
            bottom = i;
            break;
        }
    }

    return bottom;
}


// test img function
void test()
{
    Mat img = Mat::ones(3, 3, CV_8UC1);
    img.at<uchar>(0, 0) = 2;
    int bottom = find_bottom(img, 3);
    std::cout << "Bottom: "<< bottom << std::endl;
}

int main()
{
    test();
    return 0;
}

以上是关于c_cpp opencv threshold cal的主要内容,如果未能解决你的问题,请参考以下文章

opencv基本函数和文档阅读技巧

OpenCV的二值化处理函数threshold()详解

OpenCV-中cv2.threshold详解

opencv2学习之threshold:实现图像阈值分割

使用OpenCV实现Halcon算法dyn_threshold算子

opencv阈值处理--threshold函数自适应阈值处理Otsu处理(大津法)