OPENCV學習筆記之基本閾值操作

包含頭文件,現在有很大的疑惑,什麼時候要包含什麼樣的頭文件

#include<opencv2/opencv.hpp>
//#include<opencv2/core/core.hpp>
//#include<opencv2/highgui/highgui.hpp>
//#include<opencv2/imgproc/imgproc.hpp>
//#include<iostream>
#include<math.h>
using namespace cv;
using namespace std;

定義變量及聲明函數

Mat src, gray, dst;
int threshold_value =127;
int type_value=2;
int type_max = 4;
int threshold_max = 255;
const char*output_title = "binary image";
void Threshold_Demo(int, void*);

主函數:

int main(int angc, char** argv)
{
	src = imread("1.jpg");
	cvtColor(src, gray, COLOR_RGB2GRAY);//轉爲灰度圖。
    imshow("載入灰度圖", gray);
//另一想法是直接 src=imread("1.jpg",0);//載入灰度圖
			 //imshow("載入灰度圖", src);
	namedWindow(output_title, WINDOW_AUTOSIZE);


	createTrackbar("閾值", output_title, &threshold_value, threshold_max, Threshold_Demo);//滑塊名稱,窗口名稱,改變的量,量的最大值,
	createTrackbar("模式", output_title, &type_value, type_max, Threshold_Demo);
	Threshold_Demo(0, 0);

	waitKey(0);
	return(0);
	
}

Threshold_Demo()函數

void Threshold_Demo(int, void*)
{
	printf("%d", THRESH_BINARY);
	threshold(gray, dst, threshold_value, threshold_max, type_value);
	imshow(output_title, dst);
}

效果如下

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