#include<opencv2/opencv.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgcodecs/imgcodecs.hpp>
#include<iostream>
using namespace cv;
using namespace std;
#define WINDOW_NAME"窗口"
int g_nThresholdValue = 100;
int g_nThresholdType = 3;
Mat g_srcImage, g_grayImage, g_dstImage;
void on_Threshold(int, void*);
int main()
{
g_srcImage = imread("1.jpg");
if (!g_srcImage.data)
{
cout << "读入错误" << endl;
return -1;
}
cvtColor(g_srcImage, g_grayImage, COLOR_RGB2GRAY);
namedWindow("原图");
imshow("原图", g_grayImage);
namedWindow("WINDOW_NAME");
createTrackbar("模式", "WINDOW_NAME", &g_nThresholdType, 4,on_Threshold);
createTrackbar("参数值", "WINDOW_NAME", &g_nThresholdValue, 255, on_Threshold);
on_Threshold(0, 0);
waitKey(0);
return 0;
}
void on_Threshold(int, void*)
{
threshold(g_grayImage, g_dstImage, g_nThresholdValue, 255, g_nThresholdType);
imshow("WINDOW_NAME", g_dstImage);
}
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgcodecs/imgcodecs.hpp>
#include<iostream>
using namespace cv;
using namespace std;
#define WINDOW_NAME"窗口"
int g_nThresholdValue = 100;
int g_nThresholdType = 3;
Mat g_srcImage, g_grayImage, g_dstImage;
void on_Threshold(int, void*);
int main()
{
g_srcImage = imread("1.jpg");
if (!g_srcImage.data)
{
cout << "读入错误" << endl;
return -1;
}
cvtColor(g_srcImage, g_grayImage, COLOR_RGB2GRAY);
namedWindow("原图");
imshow("原图", g_grayImage);
namedWindow("WINDOW_NAME");
createTrackbar("模式", "WINDOW_NAME", &g_nThresholdType, 4,on_Threshold);
createTrackbar("参数值", "WINDOW_NAME", &g_nThresholdValue, 255, on_Threshold);
on_Threshold(0, 0);
waitKey(0);
return 0;
}
void on_Threshold(int, void*)
{
threshold(g_grayImage, g_dstImage, g_nThresholdValue, 255, g_nThresholdType);
imshow("WINDOW_NAME", g_dstImage);
}