• OpenCV (十二)阈值操作


    阈值二值化:

                    

    阈值反二值化:

                

    阈值截断:

                

     阈值取零:

               

    #include<opencv2opencv.hpp>
    #include<iostream>	
    #include<math.h>
    
    using namespace std;
    using namespace cv;
    
    Mat src, dst;
    
    int threshold_demo = 127;
    int max_threshold = 255;
    int threshold_type = 0;//0:阈值二值化, 1:阈值反二值化, 2:阈值阶段, 3:阈值取零, 4阈值反取零;
    int max_type = 4;
    
    void demo_threshold(int, void*);
    
    int main(int argc, char** argv) {
    	src = imread("D:/OpenCVprj/image/test1.jpg");
    	if (!src.data) {
    		printf("Could not load image...
    ");
    		return -1;
    	}
    	imshow("src", src);
    	namedWindow("output image", CV_WINDOW_AUTOSIZE);
    	createTrackbar("threshold", "output image", &threshold_demo, max_threshold, demo_threshold);
    	createTrackbar("threshold_type", "output image", &threshold_type, max_type, demo_threshold);
    	demo_threshold(0, 0);
    
    	waitKey(0);
    	return 0;
    }
    
    void demo_threshold(int, void*) {
    	Mat temp;
    	if (src.channels() == 3) {
    		cvtColor(src, temp, CV_BGR2GRAY);
    	}
    	else {
    		temp = src;
    	}
    	threshold(temp, dst, threshold_demo, max_threshold, threshold_type);
    	imshow("output image", dst);
    	return;
    }
    

      

  • 相关阅读:
    c++ isdigit函数
    c++ swap函数
    1.2Hello, World!的大小
    1.2整型与布尔型的转换
    1.2打印ASCII码
    leetcode[170]Two Sum III
    leetcode[167]Two Sum II
    leetcode[1]Two Sum
    leetcode[2]Add Two Numbers
    leetcode[3]Longest Substring Without Repeating Characters
  • 原文地址:https://www.cnblogs.com/haiboxiaobai/p/11239541.html
Copyright © 2020-2023  润新知