Opencv自适应阀值操作-adaptiveThreshold函数

#include
#include

using namespace std;
using namespace cv;

int g_nCurrC = 0, g_nMode = 0, g_nMath = 0, g_nSize = 1;

int main()
{
	Mat srcImage = imread("牛吃草.jpg");
	imshow("【原图】", srcImage);

	Mat grayImage;
	cvtColor(srcImage, grayImage, CV_BGR2GRAY);

	Mat dstImage;
	dstImage.create(grayImage.size(), grayImage.type());

	namedWindow("【阀值化】");
	createTrackbar("Mode", "【阀值化】", &g_nMode, 1, 0);
	createTrackbar("C", "【阀值化】", &g_nCurrC, 100, 0);
	createTrackbar("Math", "【阀值化】", &g_nMath, 1, 0);
	createTrackbar("Size", "【阀值化】", &g_nSize, 100, 0);

	char key;
	while (1)
	{
		adaptiveThreshold(grayImage, dstImage, 255, g_nMath, g_nMode, 2 * g_nSize + 1, g_nCurrC);
		imshow("【阀值化后的图】", dstImage);

		key = waitKey(10);

		if (key == 27)
			break;
	}

	return 0;
}

Opencv自适应阀值操作-adaptiveThreshold函数_第1张图片

你可能感兴趣的:(opencv学习之路)