OPENCV学习笔记之基本阈值操作

包含头文件,现在有很大的疑惑,什么时候要包含什么样的头文件

#include
//#include
//#include
//#include
//#include
#include
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);
}

你可能感兴趣的:(OPENCV学习笔记之基本阈值操作)