slides_sobel_gapi.cpp 686 B

12345678910111213141516171819202122232425262728
  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. (void) argc;
  9. (void) argv;
  10. using namespace cv;
  11. Mat in_mat = imread("lena.png");
  12. Mat out_mat;
  13. GMat in;
  14. GMat gx = gapi::Sobel(in, CV_32F, 1, 0);
  15. GMat gy = gapi::Sobel(in, CV_32F, 0, 1);
  16. GMat mag = gapi::sqrt( gapi::mul(gx, gx)
  17. + gapi::mul(gy, gy));
  18. GMat out = gapi::convertTo(mag, CV_8U);
  19. GComputation sobel(GIn(in), GOut(out));
  20. sobel.apply(in_mat, out_mat);
  21. imwrite("lena-out.png", out_mat);
  22. return 0;
  23. }