// CPP program to demonstrate segmentation // thresholding. #include #include #include #include using namespace cv; int main(int argc char** argv) { if (argc != 2) { cout << ' Usage: ' ' ' << endl; return -1; } int threshold_value = 0; // Valid Values: 0 1 2 3 4 int threshold_type = 2; // maxVal useful for threshold_type 1 and 2 int maxVal = 255; // Source image Mat src = imread(argv[1] 1); cvNamedWindow('Original' CV_WINDOW_NORMAL); imshow('Original' src); Mat src_gray dst; // Convert the image to GrayScale cvtColor(src src_gray CV_BGR2GRAY); // Create a window to display results cvNamedWindow('Result' CV_WINDOW_NORMAL); createTrackbar('Threshold' 'Result' &threshold_value 255); while (1) { threshold(src_gray dst threshold_value maxVal threshold_type); imshow('Result' dst); waitKey(1); } }