github.com/kaydxh/golang@v0.0.131/pkg/gocv/cgo/third_path/opencv4/include/opencv2/gapi/streaming/desync.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) 2020 Intel Corporation 6 7 8 #ifndef OPENCV_GAPI_GSTREAMING_DESYNC_HPP 9 #define OPENCV_GAPI_GSTREAMING_DESYNC_HPP 10 11 #include <tuple> 12 13 #include <opencv2/gapi/util/util.hpp> 14 #include <opencv2/gapi/gtype_traits.hpp> 15 #include <opencv2/gapi/garg.hpp> 16 #include <opencv2/gapi/gcall.hpp> 17 #include <opencv2/gapi/gkernel.hpp> 18 19 namespace cv { 20 namespace gapi { 21 namespace streaming { 22 23 namespace detail { 24 struct GDesync { 25 static const char *id() { 26 return "org.opencv.streaming.desync"; 27 } 28 29 // An universal yield for desync. 30 // Yields output objects according to the input Types... 31 // Reuses gkernel machinery. 32 // FIXME: This function can be generic and declared in gkernel.hpp 33 // (it is there already, but a part of GKernelType[M] 34 template<typename... R, int... IIs> 35 static std::tuple<R...> yield(cv::GCall &call, cv::detail::Seq<IIs...>) { 36 return std::make_tuple(cv::detail::Yield<R>::yield(call, IIs)...); 37 } 38 }; 39 40 template<typename G> 41 G desync(const G &g) { 42 cv::GKernel k{ 43 GDesync::id() // kernel id 44 , "" // kernel tag 45 , [](const GMetaArgs &a, const GArgs &) {return a;} // outMeta callback 46 , {cv::detail::GTypeTraits<G>::shape} // output Shape 47 , {cv::detail::GTypeTraits<G>::op_kind} // input data kinds 48 , {cv::detail::GObtainCtor<G>::get()} // output template ctors 49 }; 50 cv::GCall call(std::move(k)); 51 call.pass(g); 52 return std::get<0>(GDesync::yield<G>(call, cv::detail::MkSeq<1>::type())); 53 } 54 } // namespace detail 55 56 /** 57 * @brief Starts a desynchronized branch in the graph. 58 * 59 * This operation takes a single G-API data object and returns a 60 * graph-level "duplicate" of this object. 61 * 62 * Operations which use this data object can be desynchronized 63 * from the rest of the graph. 64 * 65 * This operation has no effect when a GComputation is compiled with 66 * regular cv::GComputation::compile(), since cv::GCompiled objects 67 * always produce their full output vectors. 68 * 69 * This operation only makes sense when a GComputation is compiled in 70 * straming mode with cv::GComputation::compileStreaming(). If this 71 * operation is used and there are desynchronized outputs, the user 72 * should use a special version of cv::GStreamingCompiled::pull() 73 * which produces an array of cv::util::optional<> objects. 74 * 75 * @note This feature is highly experimental now and is currently 76 * limited to a single GMat argument only. 77 */ 78 GAPI_EXPORTS GMat desync(const GMat &g); 79 80 } // namespace streaming 81 } // namespace gapi 82 } // namespace cv 83 84 #endif // OPENCV_GAPI_GSTREAMING_DESYNC_HPP