oak_copy.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <opencv2/gapi.hpp>
  2. #include <opencv2/gapi/core.hpp>
  3. #include <opencv2/gapi/cpu/core.hpp>
  4. #include <opencv2/gapi/gframe.hpp>
  5. #include <opencv2/gapi/media.hpp>
  6. #include <opencv2/gapi/oak/oak.hpp>
  7. #include <opencv2/gapi/streaming/format.hpp> // BGR accessor
  8. #include <opencv2/highgui.hpp> // CommandLineParser
  9. const std::string keys =
  10. "{ h help | | Print this help message }"
  11. "{ output | output.png | Path to the output file }";
  12. int main(int argc, char *argv[]) {
  13. cv::CommandLineParser cmd(argc, argv, keys);
  14. if (cmd.has("help")) {
  15. cmd.printMessage();
  16. return 0;
  17. }
  18. const std::string output_name = cmd.get<std::string>("output");
  19. cv::GFrame in;
  20. // Actually transfers data to host
  21. cv::GFrame copy = cv::gapi::oak::copy(in);
  22. // Default camera works only with nv12 format
  23. cv::GMat out = cv::gapi::streaming::Y(copy);
  24. auto args = cv::compile_args(cv::gapi::oak::ColorCameraParams{},
  25. cv::gapi::oak::kernels());
  26. auto pipeline = cv::GComputation(cv::GIn(in), cv::GOut(out)).compileStreaming(std::move(args));
  27. // Graph execution /////////////////////////////////////////////////////////
  28. cv::Mat out_mat(1920, 1080, CV_8UC1);
  29. pipeline.setSource(cv::gapi::wip::make_src<cv::gapi::oak::ColorCamera>());
  30. pipeline.start();
  31. // pull 1 frame
  32. pipeline.pull(cv::gout(out_mat));
  33. cv::imwrite(output_name, out_mat);
  34. std::cout << "Pipeline finished: " << output_name << " file has been written." << std::endl;
  35. }