1. 程式人生 > >opencv閾值分割

opencv閾值分割

cv::threshold()

double cv::threshold(
    cv::InputArray src, // 輸入影象
    cv::OutputArray dst, // 輸出影象
    double thresh, // 閾值
    double maxValue, // 向上最大值
    int thresholdType // 閾值化操作的型別 
)

這裡寫圖片描述

#include "opencv2/opencv.hpp"
#include <iostream>

using namespace std;
using namespace cv;

int main()
{
        Mat srcImage = imread("D:\\cpp_practice\\lena_gray.tif"
); imshow("原圖", srcImage); if (!srcImage.data) { cout << "fail to load image" << endl; return 0; } Mat dstImage1,dstImage2,dstImage3,dstImage4; double thresh = 100; int maxVal = 255; cv::threshold(srcImage, dstImage1, thresh, maxVal, cv::THRESH_BINARY); imshow("THRESH_BINARY"
, dstImage1); cv::threshold(srcImage, dstImage2, thresh, maxVal, cv::THRESH_BINARY_INV); imshow("THRESH_BINARY_INV", dstImage2); cv::threshold(srcImage, dstImage3, thresh, maxVal, cv::THRESH_TRUNC); imshow("THRESH_TRUNC", dstImage3); cv::threshold(srcImage, dstImage4, thresh, 150
, cv::THRESH_TOZERO); imshow("THRESH_TOZERO", dstImage4); cout << dstImage1 << endl; waitKey(0); return 0; }

opencv3 大津法ostu