Five types of binarization threshold value
Code:
#include <opencv2/opencv.hpp> #include <iostream> #include <math.h> using namespace cv; Mat src, gray_src, dst; int threshold_value = 127; int threshold_max = 255; int type_value = 2; int type_max = 4; const char* output_title = "binary image"; void Threshold_Demo(int, void*); int main(int argc, char** argv) { src = imread("L:/4.jpg"); if (!src.data) { printf("could not load image...\n"); return -1; } namedWindow("input image", CV_WINDOW_AUTOSIZE); namedWindow(output_title, CV_WINDOW_AUTOSIZE); imshow("input image", src); createTrackbar("Threshold Value:", output_title, &threshold_value, threshold_max, Threshold_Demo); createTrackbar ( " the Type the Value: " , output_title, & type_value, type_max, Threshold_Demo); // Parameter: 1 2 slidably attached to the sliding space name of the name of the image window 4. 3. Initialize threshold slide control the scale range scale callback hreshold_Demo Threshold_Demo ( 0 , 0 ); waitKey ( 0 ); return 0 ; } void Threshold_Demo ( int , void * ) { cvtColor (the src, gray_src, CV_BGR2GRAY); threshold (gray_src, DST, threshold_value , threshold_max, type_value); //Type_value displayed by selecting five methods // threshold (gray_src, DST, threshold_value, threshold_max, THRESH_BINARY); the first method of THRESH_ imshow (output_title, DST); }
Original:
result: