-
Notifications
You must be signed in to change notification settings - Fork 0
/
2-5_Thresholding.cpp
53 lines (37 loc) · 1 KB
/
2-5_Thresholding.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
//img = imread("C:\\OpenCV331\\00_images\\lena.jpg");
Mat imgSrc;
Mat imgGray;
Mat imgBW;
int thrdSlider;
const int thrdSliderMax = 255;
void OnTrackBar(int value1, void* value2);
int main()
{
imgSrc = imread("catNoise01.jpg");
if (imgSrc.empty())
{
cout << "影像載入失敗" << endl;
return -1;
}
cvtColor(imgSrc, imgGray, COLOR_BGR2GRAY);
namedWindow("winImg", WINDOW_AUTOSIZE);
namedWindow("winGray", WINDOW_AUTOSIZE);
namedWindow("winThrd", WINDOW_AUTOSIZE);
imshow("winImg", imgSrc);
imshow("winGray", imgGray);
thrdSlider = 50;
char trackbarName[15];
sprintf_s(trackbarName, "Thrd %d", thrdSliderMax);
createTrackbar(trackbarName, "winThrd", &thrdSlider,
thrdSliderMax, OnTrackBar);
waitKey(0);
return 0;
}
void OnTrackBar(int value1, void* value2)
{
threshold(imgGray, imgBW, thrdSlider, thrdSliderMax, CV_THRESH_BINARY);
imshow("winThrd", imgBW);
}