#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace std;
using namespace cv;
#define Window_name "程序窗口"
//全局变量声明
int g_nThresholdValue =100;//
int g_nThresholdType = 3;//
Mat g_srcImage, g_grayImage, g_dstImage;
//轨迹条回调函数
static void on_Threshold(int, void*);
int main(){
system("color 5E");
g_srcImage= imread("靶标原图.png", 1);
if (!g_srcImage.data){
printf("打开图片错误,请检查路径\n");
return false;
}
cvtColor(g_srcImage, g_grayImage, COLOR_RGB2GRAY);
namedWindow("原图窗口", 1);
imshow("原图窗口", g_srcImage);
//新建两个bar
namedWindow(Window_name, WINDOW_AUTOSIZE);
createTrackbar("模式", Window_name, &g_nThresholdType, 4, on_Threshold);
createTrackbar("参数值", Window_name, &g_nThresholdValue, 255, on_Threshold);
//初始化阈值回调函数
on_Threshold(0, 0);
while (1)
{
int key;
key = waitKey(20);
if ((char)key==27)
break;
}
return 0;
}
static void on_Threshold(int, void*){
threshold(g_srcImage,g_dstImage,g_nThresholdValue,255,g_nThresholdType);
imshow(Window_name, g_dstImage);
}