convert.hpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. //
  5. // Copyright (C) 2018 Intel Corporation
  6. #ifndef OPENCV_GAPI_OWN_CONVERT_HPP
  7. #define OPENCV_GAPI_OWN_CONVERT_HPP
  8. #if !defined(GAPI_STANDALONE)
  9. #include <opencv2/gapi/opencv_includes.hpp>
  10. #include <opencv2/gapi/own/mat.hpp>
  11. namespace cv
  12. {
  13. template<typename T>
  14. std::vector<T> to_own(const cv::MatSize &sz) {
  15. std::vector<T> result(sz.dims());
  16. for (int i = 0; i < sz.dims(); i++) {
  17. // Note: cv::MatSize is not iterable
  18. result[i] = static_cast<T>(sz[i]);
  19. }
  20. return result;
  21. }
  22. cv::gapi::own::Mat to_own(Mat&&) = delete;
  23. inline cv::gapi::own::Mat to_own(Mat const& m) {
  24. return (m.dims == 2)
  25. ? cv::gapi::own::Mat{m.rows, m.cols, m.type(), m.data, m.step}
  26. : cv::gapi::own::Mat{to_own<int>(m.size), m.type(), m.data};
  27. };
  28. namespace gapi
  29. {
  30. namespace own
  31. {
  32. inline cv::Mat to_ocv(Mat const& m) {
  33. return m.dims.empty()
  34. ? cv::Mat{m.rows, m.cols, m.type(), m.data, m.step}
  35. : cv::Mat{m.dims, m.type(), m.data};
  36. }
  37. cv::Mat to_ocv(Mat&&) = delete;
  38. } // namespace own
  39. } // namespace gapi
  40. } // namespace cv
  41. #endif // !defined(GAPI_STANDALONE)
  42. #endif // OPENCV_GAPI_OWN_CONVERT_HPP