-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy path04_Threshold.cpp
45 lines (31 loc) · 878 Bytes
/
04_Threshold.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
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std;
int main( int argc, char** argv ) {
// Create matrix from image
Mat imageSrc = imread("lena1.png", CV_LOAD_IMAGE_COLOR);
// Create windows
namedWindow("Source", WINDOW_AUTOSIZE);
namedWindow("Destination", WINDOW_AUTOSIZE);
int val1 = 0;
int val2 = 0;
createTrackbar("Val1", "Destination", &val1, 255);
createTrackbar("Val2", "Destination", &val2, 255);
// Keep updating
while(true) {
// Destination matrix
Mat imageDest;
// Convert to grayscale
cvtColor(imageSrc, imageDest, CV_BGR2GRAY);
// Apply threshold
threshold(imageDest, imageDest, 150, 255, CV_THRESH_BINARY);
// Show images
imshow("Source", imageSrc);
imshow("Destination", imageDest);
// Wait forever
waitKey(50);
}
return 0;
}