api_example.cpp 998 B

12345678910111213141516171819202122232425262728293031323334
  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. int main(int argc, char *argv[])
  7. {
  8. cv::VideoCapture cap;
  9. if (argc > 1) cap.open(argv[1]);
  10. else cap.open(0);
  11. CV_Assert(cap.isOpened());
  12. cv::GMat in;
  13. cv::GMat vga = cv::gapi::resize(in, cv::Size(), 0.5, 0.5);
  14. cv::GMat gray = cv::gapi::BGR2Gray(vga);
  15. cv::GMat blurred = cv::gapi::blur(gray, cv::Size(5,5));
  16. cv::GMat edges = cv::gapi::Canny(blurred, 32, 128, 3);
  17. cv::GMat b,g,r;
  18. std::tie(b,g,r) = cv::gapi::split3(vga);
  19. cv::GMat out = cv::gapi::merge3(b, g | edges, r);
  20. cv::GComputation ac(in, out);
  21. cv::Mat input_frame;
  22. cv::Mat output_frame;
  23. CV_Assert(cap.read(input_frame));
  24. do
  25. {
  26. ac.apply(input_frame, output_frame);
  27. cv::imshow("output", output_frame);
  28. } while (cap.read(input_frame) && cv::waitKey(30) < 0);
  29. return 0;
  30. }