forked from techwithtim/OpenCV-Tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tutorial5.cpp
36 lines (27 loc) · 848 Bytes
/
tutorial5.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
#include <iostream>
#include <opencv2/opencv.hpp>
int main() {
cv::VideoCapture cap(0);
while (true) {
cv::Mat frame;
cap.read(frame);
int width = static_cast<int>(cap.get(cv::CAP_PROP_FRAME_WIDTH));
int height = static_cast<int>(cap.get(cv::CAP_PROP_FRAME_HEIGHT));
cv::Mat hsv;
cv::cvtColor(frame, hsv, cv::COLOR_BGR2HSV);
cv::Scalar lower_blue(90, 50, 50);
cv::Scalar upper_blue(130, 255, 255);
cv::Mat mask;
cv::inRange(hsv, lower_blue, upper_blue, mask);
cv::Mat result;
cv::bitwise_and(frame, frame, result, mask = mask);
cv::imshow("frame", result);
cv::imshow("mask", mask);
if (cv::waitKey(1) == 'q') {
break;
}
}
cap.release();
cv::destroyAllWindows();
return 0;
}