opencv学习笔记—8,阈值操作
一、图像阈值(threshold)
1、阈值二值化 THRESH_BINARY
2、阈值反二值化 THRESH_BINARY_INV
3、截断 THRESH_
4、阈值取0 TH_HRESTOZERO
5、阈值反取0 TH_HRESTOZERO_INV
二、
#include<opencv2/opencv.hpp>
#include<highgui.h>
#include<iostream>
using namespace cv;
Mat img,gray_img,output_img;
int threshold_vlaue=127;
int threshold_max=255;
int type_vlaue=0;
int type_max=4;
void Threshold_Demo(int,void*);
int main(int argc,char**argv)
{
Mat img=imread("1.jpg");
namedWindow("my picture",CV_WINDOW_AUTOSIZE);
namedWindow("threshold_img",CV_WINDOW_AUTOSIZE);
imshow("my picture",img);
cvtColor(img,gray_img,CV_BGR2GRAY);
createTrackbar("threshold","threshold_img",&threshold_vlaue,threshold_max,Threshold_Demo); //学会createTrackbar的使用
createTrackbar("type vlaue","threshold_img",&type_vlaue,type_max,Threshold_Demo);
Threshold_Demo(0,0);
waitKey(0);
return(0);
}
void Threshold_Demo(int,void*){
threshold(gray_img,output_img,threshold_vlaue,threshold_max,type_vlaue );
imshow("threshold_img",output_img);
}