github.com/kaydxh/golang@v0.0.131/pkg/gocv/cgo/third_path/opencv4/include/opencv2/gapi/own/convert.hpp (about) 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 7 8 #ifndef OPENCV_GAPI_OWN_CONVERT_HPP 9 #define OPENCV_GAPI_OWN_CONVERT_HPP 10 11 #if !defined(GAPI_STANDALONE) 12 13 #include <opencv2/gapi/opencv_includes.hpp> 14 #include <opencv2/gapi/own/mat.hpp> 15 16 namespace cv 17 { 18 template<typename T> 19 std::vector<T> to_own(const cv::MatSize &sz) { 20 std::vector<T> result(sz.dims()); 21 for (int i = 0; i < sz.dims(); i++) { 22 // Note: cv::MatSize is not iterable 23 result[i] = static_cast<T>(sz[i]); 24 } 25 return result; 26 } 27 28 cv::gapi::own::Mat to_own(Mat&&) = delete; 29 30 inline cv::gapi::own::Mat to_own(Mat const& m) { 31 return (m.dims == 2) 32 ? cv::gapi::own::Mat{m.rows, m.cols, m.type(), m.data, m.step} 33 : cv::gapi::own::Mat{to_own<int>(m.size), m.type(), m.data}; 34 }; 35 36 namespace gapi 37 { 38 namespace own 39 { 40 41 inline cv::Mat to_ocv(Mat const& m) { 42 return m.dims.empty() 43 ? cv::Mat{m.rows, m.cols, m.type(), m.data, m.step} 44 : cv::Mat{m.dims, m.type(), m.data}; 45 } 46 47 cv::Mat to_ocv(Mat&&) = delete; 48 49 } // namespace own 50 } // namespace gapi 51 } // namespace cv 52 53 #endif // !defined(GAPI_STANDALONE) 54 55 #endif // OPENCV_GAPI_OWN_CONVERT_HPP