#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-08-04 20:52:03 发布
本文展示了一个使用OpenCV进行图像阈值处理的C++示例程序,通过创建滑动条来动态调整阈值,实现了对灰度图像的二值化处理,并展示了处理后的效果。
844

被折叠的 条评论
为什么被折叠?



