Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/gapi/samples/api_example.cpp
16337 views
1
#include <opencv2/videoio.hpp>
2
#include <opencv2/highgui.hpp>
3
#include <opencv2/gapi.hpp>
4
#include <opencv2/gapi/core.hpp>
5
#include <opencv2/gapi/imgproc.hpp>
6
7
int main(int argc, char *argv[])
8
{
9
cv::VideoCapture cap;
10
if (argc > 1) cap.open(argv[1]);
11
else cap.open(0);
12
CV_Assert(cap.isOpened());
13
14
cv::GMat in;
15
cv::GMat vga = cv::gapi::resize(in, cv::Size(), 0.5, 0.5);
16
cv::GMat gray = cv::gapi::BGR2Gray(vga);
17
cv::GMat blurred = cv::gapi::blur(gray, cv::Size(5,5));
18
cv::GMat edges = cv::gapi::Canny(blurred, 32, 128, 3);
19
cv::GMat b,g,r;
20
std::tie(b,g,r) = cv::gapi::split3(vga);
21
cv::GMat out = cv::gapi::merge3(b, g | edges, r);
22
cv::GComputation ac(in, out);
23
24
cv::Mat input_frame;
25
cv::Mat output_frame;
26
CV_Assert(cap.read(input_frame));
27
do
28
{
29
ac.apply(input_frame, output_frame);
30
cv::imshow("output", output_frame);
31
} while (cap.read(input_frame) && cv::waitKey(30) < 0);
32
33
return 0;
34
}
35
36