#include<iostream>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
int threshold_value = 0;
int threshold_type = 3;
int const max_value = 255;
int const max_type = 4;
int const max_BINARY_value = 255;
Mat src, src_gray, dst;
char* window_name = "Threshold Demo";
char* trackbar_type = "Type:0-Binary\n1-BinaryInverted\n2-Truncate\n3-ToZero\n4-ToZeroInverted";
char* trackbar_value = "Value";
void Threshold_Demo(int, void*);
int main()
{
src = imread("哆啦A梦.jpg");
cvtColor(src, src_gray, CV_BGR2GRAY);
namedWindow(window_name);
createTrackbar(trackbar_type, window_name, &threshold_type, max_type, Threshold_Demo);
createTrackbar(trackbar_value, window_name, &threshold_value, max_value, Threshold_Demo);
Threshold_Demo(0, 0);
while (true)
{
int c = waitKey(20);
if ((char)c == 27)
{
break;
}
}
}
void Threshold_Demo(int, void*)
{
/*
0: Binary
1: Binary Inverted
2: Threshold Truncated
3: Threshold to Zero
4: Threshold to Zero Inverted
*/
threshold(src_gray, dst, threshold_value, max_BINARY_value, threshold_type);
imshow(window_name, dst);
}