-
Notifications
You must be signed in to change notification settings - Fork 10
/
filter_demo_webcam.cpp
70 lines (57 loc) · 1.41 KB
/
filter_demo_webcam.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*------------------------------------------------------/
* Image Proccessing with Deep Learning
* OpenCV : Filter Demo - Video
* Created: 2021-Spring
------------------------------------------------------*/
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
/* open the video camera no.0 */
VideoCapture cap(0);
if (!cap.isOpened()) // if not success, exit the programm
{
cout << "Cannot open the video cam\n";
return -1;
}
namedWindow("MyVideo", CV_WINDOW_AUTOSIZE);
int key = 0;
int kernel_size = 11;
int filter_type = 0;
while (1)
{
Mat src, dst;
/* read a new frame from video */
bool bSuccess = cap.read(src);
if (!bSuccess) // if not success, break loop
{
cout << "Cannot find a frame from video stream\n";
break;
}
key = waitKey(30);
if (key == 27) // wait for 'ESC' press for 30ms. If 'ESC' is pressed, break loop
{
cout << "ESC key is pressed by user\n";
break;
}
else if (key == 'b' || key == 'B')
{
filter_type = 1; // blur
}
/* Keyboard input for other filters*/
// ADD YOUR CODE HERE
// ADD YOUR CODE HERE
// ADD YOUR CODE HERE
if (filter_type == 1)
blur(src, dst, cv::Size(kernel_size, kernel_size), cv::Point(-1, -1));
/* Apply filter accroding to filter type */
// ADD YOUR CODE HERE
// ADD YOUR CODE HERE
else
src.copyTo(dst);
imshow("MyVideo", dst);
}
return 0;
}