OpenCV基础课程笔记15基本阈值操作

写在前面

阈值二值化操作肯定在灰度图像使用。
阈值类型
THRESH_BINARY
THRESH_BINARY_INV //取反
THRESH_TRUNC 超过阈值的,等于阈值
THRESH_TOZERO 小于阈值的,等于0
THRESH_TOZERO_INV
生成阈值方式
THRESH_OTSU
THRESH_TRIANGLE

代码

#include<iostream>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;

Mat src = imread("A:\\专用\\TestForTheCV\\tae.jpg");
int threshold_value = 127;
int threshold_max = 255;
const char* output = "dst image";
Mat dst;

void thresholdDemo(int ,void*);

int main() {
	imshow("原图", src);
	namedWindow(output, CV_WINDOW_AUTOSIZE);

	createTrackbar("Threshold Value is:", output, &threshold_value, threshold_max, thresholdDemo);

	waitKey(0);
	return 0;
}

void thresholdDemo(int, void*) {
	cvtColor(src, dst, CV_BGR2GRAY);
	//threshold(dst, dst, threshold_value, threshold_max, THRESH_TRUNC);

	threshold(dst, dst, 0, 255,THRESH_TRIANGLE);


	imshow(output, dst);
}

运行结果

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值