zoukankan      html  css  js  c++  java
  • 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;
    }
    

      

  • 相关阅读:
    layui框架如何在停止服务用户操作任何步骤自动跳转登录页
    h5移动端和ios以及安卓客户端的接口联调
    sublime 主要使用方法
    内外边距、浮动、布局相关
    js介绍
    css的三个特性 背景透明设置
    选择器 导航制作相关
    表单综合
    自定义列表dl
    相对路径和绝对路径
  • 原文地址:https://www.cnblogs.com/haiboxiaobai/p/11239541.html
Copyright © 2011-2022 走看看