#include<opencv2\opencv.hpp>
#include<iostream>
#include<math.h>
using namespace cv;
Mat src, dst,gray_src;
int threshold_value = 127;
int threshold_max = 255;
const char* output_window = "output_window";
void Threshold_Demo(int, void*);
int main()
{
src = imread("C:/Users/asus/Desktop/tupian/1.jpg");
if (src.empty())
{
printf("could not load image...\n");
return -1;
}
namedWindow("input image", WINDOW_AUTOSIZE);
imshow("input image", src);
namedWindow(output_window, WINDOW_AUTOSIZE);
cvtColor(src, gray_src, COLOR_BGR2GRAY);
createTrackbar("Threshold_Demo", output_window, &threshold_value, threshold_max, Threshold_Demo);
Threshold_Demo(0, 0);
waitKey(0);
return 0;
}
void Threshold_Demo(int, void*)
{
cvtColor(src, gray_src, COLOR_BGR2GRAY);
//threshold(gray_src, dst,threshold_value, threshold_max, THRESH_BINARY);
threshold(gray_src, dst,threshold_value, threshold_max, THRESH_BINARY_INV);
imshow(output_window, dst);
}
opencv c++基本阈值操作
最新推荐文章于 2024-05-14 17:53:26 发布