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);
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章