OpenCV 4.12.0
開源計算機視覺
載入中...
搜尋中...
無匹配項
cv::GComputation 類參考

GComputation 類表示一個捕獲的計算圖。GComputation 物件為使用者使用 G-API 編寫的表示式程式碼形成邊界,允許對其進行編譯和執行。更多...

#include <opencv2/gapi/gcomputation.hpp>

cv::GComputation 的協作圖

公共型別

typedef std::function< GComputation()> Generator
 

公共成員函式

 GComputation (const Generator &gen)
 使用生成器函式定義計算。
 
 GComputation (const std::vector< GMat > &ins, const std::vector< GMat > &outs)
 定義具有任意輸入/輸出數量的計算。
 
GAPI_WRAP GComputation (GMat in, GMat out)
 定義一元(一個輸入 - 一個輸出)計算。
 
GAPI_WRAP GComputation (GMat in, GScalar out)
 定義一元(一個輸入 - 一個輸出)計算。
 
GAPI_WRAP GComputation (GMat in1, GMat in2, GMat out)
 定義二元(兩個輸入 - 一個輸出)計算。
 
 GComputation (GMat in1, GMat in2, GScalar out)
 定義二元(兩個輸入 - 一個輸出)計算。
 
GAPI_WRAP GComputation (GProtoInputArgs &&ins, GProtoOutputArgs &&outs)
 通用 GComputation 建構函式。
 
void apply (const std::vector< cv::Mat > &ins, std::vector< cv::Mat > &outs, GCompileArgs &&args={})
 執行具有任意數量輸入/輸出的計算(即時編譯)。
 
void apply (cv::Mat in, cv::Mat &out, GCompileArgs &&args={})
 執行一元計算(即時編譯)
 
void apply (cv::Mat in, cv::Scalar &out, GCompileArgs &&args={})
 執行一元計算(即時編譯)
 
void apply (cv::Mat in1, cv::Mat in2, cv::Mat &out, GCompileArgs &&args={})
 執行二元計算(即時編譯)
 
void apply (cv::Mat in1, cv::Mat in2, cv::Scalar &out, GCompileArgs &&args={})
 執行二元計算(即時編譯)
 
void apply (GRunArgs &&ins, GRunArgsP &&outs, GCompileArgs &&args={})
 即時編譯圖並立即在輸入資料向量上執行。
 
template<typename... Ts>
auto compile (const Ts &... meta_and_compile_args) -> typename std::enable_if< detail::are_meta_descrs_but_last< Ts... >::value &&std::is_same< GCompileArgs, detail::last_type_t< Ts... > >::value, GCompiled >::type
 
template<typename... Ts>
auto compile (const Ts &... metas) -> typename std::enable_if< detail::are_meta_descrs< Ts... >::value, GCompiled >::type
 
GCompiled compile (GMetaArgs &&in_metas, GCompileArgs &&args={})
 為特定輸入格式編譯計算。
 
template<typename... Ts>
auto compileStreaming (const Ts &... meta_and_compile_args) -> typename std::enable_if< detail::are_meta_descrs_but_last< Ts... >::value &&std::is_same< GCompileArgs, detail::last_type_t< Ts... > >::value, GStreamingCompiled >::type
 
template<typename... Ts>
auto compileStreaming (const Ts &... metas) -> typename std::enable_if< detail::are_meta_descrs< Ts... >::value, GStreamingCompiled >::type
 
GAPI_WRAP GStreamingCompiled compileStreaming (GCompileArgs &&args={})
 編譯流模式的計算。
 
GAPI_WRAP GStreamingCompiled compileStreaming (GMetaArgs &&in_metas, GCompileArgs &&args={})
 編譯流模式的計算。
 

保護成員函式

template<typename... Ts, int... IIs>
GStreamingCompiled compileStreaming (const std::tuple< Ts... > &meta_and_compile_args, detail::Seq< IIs... >)
 
void recompile (GMetaArgs &&in_metas, GCompileArgs &&args)
 

詳細描述

GComputation 類表示一個捕獲的計算圖。GComputation 物件為使用者使用 G-API 編寫的表示式程式碼形成邊界,允許對其進行編譯和執行。

G-API 計算是使用輸入/輸出資料物件定義的。G-API 將自動跟蹤哪些操作將指定的輸出連線到輸入,從而形成要執行的呼叫圖。下面的示例表示 Sobel 運算元的邊緣檢測計算(\(G = \sqrt{G_x^2 + G_y^2}\))。

現在可以使用此物件宣告捕獲完整的管道

cv::GComputation sobelEdge(cv::GIn(in), cv::GOut(out));

應重建呼叫圖的輸入/輸出資料物件使用特殊包裝器 cv::GIncv::GOut 傳遞。G-API 將自動跟蹤哪些操作形成從輸入到輸出的路徑,並適當地構建執行圖。

請注意,cv::GComputation 不會獲取其定義的資料物件的所有權。此外,多個 GComputation 物件可以在相同的表示式上定義,例如,一個較小的管道,它期望影像梯度已預先計算,可以這樣定義:

cv::GComputation sobelEdgeSub(cv::GIn(gx, gy), cv::GOut(out));

結果圖將期望兩個輸入併產生一個輸出。在這種情況下,gx/gy 資料物件是否是 cv::gapi::Sobel 運算元的結果並不重要——G-API 在達到這些資料物件時將停止展開表示式並構建底層圖。

定義 GComputation 的方式很重要,因為其定義指定了圖的協議——即圖應如何使用。協議由輸入數量、輸出數量以及輸入和輸出的形狀定義。

在上面的示例中,sobelEdge 期望一個 Mat 作為輸入併產生一個 Mat;而 sobelEdgeSub 期望兩個 Mats 作為輸入併產生一個 MatGComputation 的協議定義了其他計算方法應如何使用——cv::GComputation::compile()cv::GComputation::apply()。例如,如果一個圖定義在兩個 GMat 輸入上,則必須將兩個 cv::Mat 物件傳遞給 apply() 以進行執行。GComputation 在執行時檢查協議的正確性,因此在 apply() 中傳遞不同數量的物件或傳遞 cv::Scalar 而不是 cv::Mat 將會在 C++ 源中編譯透過,但在執行時引發異常。G-API 還提供了型別化的包裝器 cv::GComputationT<>,它在編譯時引入了這種型別檢查。

cv::GComputation 本身是一個精簡物件,只捕獲圖的內容。編譯後的圖(實際處理資料)由 GCompiled 類表示。使用 compile() 方法生成具有給定編譯選項的編譯圖。cv::GComputation 也可以用於透過隱式即時圖編譯來處理資料,詳情請參閱 apply()

GComputation 是一個引用計數物件——一旦定義,所有副本都將引用同一個例項。

另請參見
GCompiled

成員 Typedef 文件

◆ Generator

建構函式 & 解構函式文件

◆ GComputation() [1/7]

cv::GComputation::GComputation ( const Generator & gen)
Python
cv.GComputation(ins, outs) -> <GComputation 物件>
cv.GComputation(in_, out) -> <GComputation 物件>
cv.GComputation(in1, in2, out) -> <GComputation 物件>

使用生成器函式定義計算。

圖可以在構造時直接透過 lambda 進行原地定義

cv::GComputation sobelEdgeGen([](){
cv::GMat gx = cv::gapi::Sobel(in, CV_32F, 1, 0);
cv::GMat gy = cv::gapi::Sobel(in, CV_32F, 0, 1);
return cv::GComputation(in, out);
});

這可能很有用,因為所有臨時物件(cv::GMats)和名稱空間都可以區域性化到 lambda 的作用域,而不會用可能不必要的物件和資訊汙染父作用域。

引數
gen返回 cv::GComputation 的生成器函式,參見 Generator。

◆ GComputation() [2/7]

GAPI_WRAP cv::GComputation::GComputation ( GProtoInputArgs && ins,
GProtoOutputArgs && outs )
Python
cv.GComputation(ins, outs) -> <GComputation 物件>
cv.GComputation(in_, out) -> <GComputation 物件>
cv.GComputation(in1, in2, out) -> <GComputation 物件>

通用 GComputation 建構函式。

構造一個新圖,其協議由連線輸入/輸出操作的流指定。如果傳遞的邊界無效(例如,給定輸出和輸入之間沒有功能依賴(路徑)),則丟擲異常。

引數
ins輸入資料向量。
outs輸出資料向量。
注意
不要直接構造 GProtoInputArgs/GProtoOutputArgs 物件,而是使用 cv::GIn()/cvGOut() 包裝函式。
另請參見
G-API 資料型別

◆ GComputation() [3/7]

GAPI_WRAP cv::GComputation::GComputation ( GMat in,
GMat out )
Python
cv.GComputation(ins, outs) -> <GComputation 物件>
cv.GComputation(in_, out) -> <GComputation 物件>
cv.GComputation(in1, in2, out) -> <GComputation 物件>

定義一元(一個輸入 - 一個輸出)計算。

這是一個過載成員函式,為方便起見而提供。它與上述函式的區別僅在於它接受的引數。

引數
in定義的一元計算的輸入 GMat
輸出3D仿射變換矩陣,尺寸為\(3 \times 4\),形式如下定義的一元計算的輸出 GMat

◆ GComputation() [4/7]

GAPI_WRAP cv::GComputation::GComputation ( GMat in,
GScalar out )
Python
cv.GComputation(ins, outs) -> <GComputation 物件>
cv.GComputation(in_, out) -> <GComputation 物件>
cv.GComputation(in1, in2, out) -> <GComputation 物件>

定義一元(一個輸入 - 一個輸出)計算。

這是一個過載成員函式,為方便起見而提供。它與上述函式的區別僅在於它接受的引數。

引數
in定義的一元計算的輸入 GMat
輸出3D仿射變換矩陣,尺寸為\(3 \times 4\),形式如下定義的一元計算的輸出 GScalar

◆ GComputation() [5/7]

GAPI_WRAP cv::GComputation::GComputation ( GMat in1,
GMat in2,
GMat out )
Python
cv.GComputation(ins, outs) -> <GComputation 物件>
cv.GComputation(in_, out) -> <GComputation 物件>
cv.GComputation(in1, in2, out) -> <GComputation 物件>

定義二元(兩個輸入 - 一個輸出)計算。

這是一個過載成員函式,為方便起見而提供。它與上述函式的區別僅在於它接受的引數。

引數
in1定義的二元計算的第一個輸入 GMat
in2定義的二元計算的第二個輸入 GMat
輸出3D仿射變換矩陣,尺寸為\(3 \times 4\),形式如下定義的二元計算的輸出 GMat

◆ GComputation() [6/7]

cv::GComputation::GComputation ( GMat in1,
GMat in2,
GScalar out )
Python
cv.GComputation(ins, outs) -> <GComputation 物件>
cv.GComputation(in_, out) -> <GComputation 物件>
cv.GComputation(in1, in2, out) -> <GComputation 物件>

定義二元(兩個輸入 - 一個輸出)計算。

這是一個過載成員函式,為方便起見而提供。它與上述函式的區別僅在於它接受的引數。

引數
in1定義的二元計算的第一個輸入 GMat
in2定義的二元計算的第二個輸入 GMat
輸出3D仿射變換矩陣,尺寸為\(3 \times 4\),形式如下定義的二元計算的輸出 GScalar

◆ GComputation() [7/7]

cv::GComputation::GComputation ( const std::vector< GMat > & ins,
const std::vector< GMat > & outs )
Python
cv.GComputation(ins, outs) -> <GComputation 物件>
cv.GComputation(in_, out) -> <GComputation 物件>
cv.GComputation(in1, in2, out) -> <GComputation 物件>

定義具有任意輸入/輸出數量的計算。

這是一個過載成員函式,為方便起見而提供。它與上述函式的區別僅在於它接受的引數。

引數
ins此計算的輸入 GMats 向量
outs此計算的輸出 GMats 向量

當計算輸入/輸出的數量在編譯時未知時(例如,當透過程式生成圖以構建具有給定級別數量的影像金字塔時)使用此過載。

成員函式文件

◆ apply() [1/6]

void cv::GComputation::apply ( const std::vector< cv::Mat > & ins,
std::vector< cv::Mat > & outs,
GCompileArgs && args = {} )
Python
cv.GComputation.apply(callback[, args]) -> retval

執行具有任意數量輸入/輸出的計算(即時編譯)。

這是一個過載成員函式,為方便起見而提供。它與上述函式的區別僅在於它接受的引數。

引數
ins要由計算處理的輸入 cv::Mat 物件向量。
outs要由計算生成的輸出 cv::Mat 物件向量。
args底層編譯過程的編譯引數。

ins/outs 向量中的元素數量必須與用於定義此 GComputation 的輸入/輸出數量匹配。

◆ apply() [2/6]

void cv::GComputation::apply ( cv::Mat in,
cv::Mat & 輸出3D仿射變換矩陣,尺寸為\(3 \times 4\),形式如下,
GCompileArgs && args = {} )
Python
cv.GComputation.apply(callback[, args]) -> retval

執行一元計算(即時編譯)

這是一個過載成員函式,為方便起見而提供。它與上述函式的區別僅在於它接受的引數。

引數
in用於一元計算的輸入 cv::Mat
輸出3D仿射變換矩陣,尺寸為\(3 \times 4\),形式如下用於一元計算的輸出 cv::Mat
args底層編譯過程的編譯引數。

◆ apply() [3/6]

void cv::GComputation::apply ( cv::Mat in,
cv::Scalar & 輸出3D仿射變換矩陣,尺寸為\(3 \times 4\),形式如下,
GCompileArgs && args = {} )
Python
cv.GComputation.apply(callback[, args]) -> retval

執行一元計算(即時編譯)

這是一個過載成員函式,為方便起見而提供。它與上述函式的區別僅在於它接受的引數。

引數
in用於一元計算的輸入 cv::Mat
輸出3D仿射變換矩陣,尺寸為\(3 \times 4\),形式如下用於一元計算的輸出 cv::Scalar
args底層編譯過程的編譯引數。

◆ apply() [4/6]

void cv::GComputation::apply ( cv::Mat in1,
cv::Mat in2,
cv::Mat & 輸出3D仿射變換矩陣,尺寸為\(3 \times 4\),形式如下,
GCompileArgs && args = {} )
Python
cv.GComputation.apply(callback[, args]) -> retval

執行二元計算(即時編譯)

這是一個過載成員函式,為方便起見而提供。它與上述函式的區別僅在於它接受的引數。

引數
in1用於二元計算的第一個輸入 cv::Mat
in2用於二元計算的第二個輸入 cv::Mat
輸出3D仿射變換矩陣,尺寸為\(3 \times 4\),形式如下用於二元計算的輸出 cv::Mat
args底層編譯過程的編譯引數。

◆ apply() [5/6]

void cv::GComputation::apply ( cv::Mat in1,
cv::Mat in2,
cv::Scalar & 輸出3D仿射變換矩陣,尺寸為\(3 \times 4\),形式如下,
GCompileArgs && args = {} )
Python
cv.GComputation.apply(callback[, args]) -> retval

執行二元計算(即時編譯)

這是一個過載成員函式,為方便起見而提供。它與上述函式的區別僅在於它接受的引數。

引數
in1用於二元計算的第一個輸入 cv::Mat
in2用於二元計算的第二個輸入 cv::Mat
輸出3D仿射變換矩陣,尺寸為\(3 \times 4\),形式如下用於二元計算的輸出 cv::Scalar
args底層編譯過程的編譯引數。

◆ apply() [6/6]

void cv::GComputation::apply ( GRunArgs && ins,
GRunArgsP && outs,
GCompileArgs && args = {} )
Python
cv.GComputation.apply(callback[, args]) -> retval

即時編譯圖並立即在輸入資料向量上執行。

輸入/輸出資料物件的數量必須與 GComputation 的協議匹配,主機資料物件(cv::Matcv::Scalar)的型別也必須與協議中資料物件(cv::GMatcv::GScalar)的形狀匹配。如果存在不匹配,將生成執行時異常。

在內部,為給定的輸入格式配置建立了一個 cv::GCompiled 物件,然後立即在輸入資料上執行它。cv::GComputation 快取透過 apply() 生成的已編譯物件——如果下次使用相同的輸入引數(影像格式、影像解析度等)呼叫此方法,則底層已編譯圖將重複使用而無需重新編譯。如果新元資料與快取的不匹配,則會重新生成底層已編譯圖。

注意
compile() 始終觸發編譯過程並生成新的 GCompiled 物件,無論是否已透過 apply() 快取了類似的物件。
引數
ins要處理的輸入資料向量。不要手動建立 GRunArgs 物件,請使用 cv::gin() 包裝器。
outs要填充結果的輸出資料向量。cv::Mat 物件在此向量中可以為空,G-API 將自動使用所需格式和維度對其進行初始化。不要手動建立 GRunArgsP 物件,請使用 cv::gout() 包裝器。
args要傳遞給底層編譯過程的編譯引數列表。不要手動建立 GCompileArgs 物件,請使用 cv::compile_args() 包裝器。
另請參見
G-API 資料型別, G-API 圖編譯引數

◆ compile() [1/3]

template<typename... Ts>
auto cv::GComputation::compile ( const Ts &... meta_and_compile_args) -> typename std::enable_if<detail::are_meta_descrs_but_last<Ts...>::value && std::is_same<GCompileArgs, detail::last_type_t<Ts...> >::value, GCompiled>::type
inline

這是一個過載成員函式,為方便起見而提供。它與上述函式的區別僅在於它接受的引數。

接受一個可變引數包,其中包含需要生成編譯物件的元資料描述符,後跟表示此過程的編譯引數的 GCompileArgs 物件。

返回
GCompiled,一個專門為給定輸入引數編譯的可執行計算。

◆ compile() [2/3]

template<typename... Ts>
auto cv::GComputation::compile ( const Ts &... metas) -> typename std::enable_if<detail::are_meta_descrs<Ts...>::value, GCompiled>::type
inline

這是一個過載成員函式,為方便起見而提供。它與上述函式的區別僅在於它接受的引數。

接受一個可變引數包,其中包含需要生成編譯物件的元資料描述符。

返回
GCompiled,一個專門為給定輸入引數編譯的可執行計算。

◆ compile() [3/3]

GCompiled cv::GComputation::compile ( GMetaArgs && in_metas,
GCompileArgs && args = {} )

為特定輸入格式編譯計算。

此方法觸發編譯過程並生成一個新的 GCompiled 物件,然後該物件可以處理給定格式的資料。將不同格式的資料傳遞給已編譯的計算將生成執行時異常。

引數
in_metas輸入元資料配置向量。從實際資料物件(如 cv::Matcv::Scalar)使用 cv::descr_of() 獲取元資料,或自行建立。
args此編譯過程的編譯引數。編譯引數直接影響將生成何種可執行物件,例如將使用哪些核心(以及因此,裝置)來執行計算。
返回
GCompiled,一個專門為給定輸入引數編譯的可執行計算。
另請參見
G-API 圖編譯引數

◆ compileStreaming() [1/5]

template<typename... Ts, int... IIs>
GStreamingCompiled cv::GComputation::compileStreaming ( const std::tuple< Ts... > & meta_and_compile_args,
detail::Seq< IIs... >  )
inlineprotected
Python
cv.GComputation.compileStreaming(in_metas[, args]) -> retval
cv.GComputation.compileStreaming([, args]) -> retval
cv.GComputation.compileStreaming(callback[, args]) -> retval

◆ compileStreaming() [2/5]

template<typename... Ts>
auto cv::GComputation::compileStreaming ( const Ts &... meta_and_compile_args) -> typename std::enable_if<detail::are_meta_descrs_but_last<Ts...>::value && std::is_same<GCompileArgs, detail::last_type_t<Ts...> >::value, GStreamingCompiled>::type
inline
Python
cv.GComputation.compileStreaming(in_metas[, args]) -> retval
cv.GComputation.compileStreaming([, args]) -> retval
cv.GComputation.compileStreaming(callback[, args]) -> retval

這是一個過載成員函式,為方便起見而提供。它與上述函式的區別僅在於它接受的引數。

接受一個可變引數包,其中包含需要生成編譯物件的元資料描述符,後跟表示此過程的編譯引數的 GCompileArgs 物件。

返回
GStreamingCompiled,一個專門為給定輸入引數編譯的面向流的可執行計算。

◆ compileStreaming() [3/5]

template<typename... Ts>
auto cv::GComputation::compileStreaming ( const Ts &... metas) -> typename std::enable_if<detail::are_meta_descrs<Ts...>::value, GStreamingCompiled>::type
inline
Python
cv.GComputation.compileStreaming(in_metas[, args]) -> retval
cv.GComputation.compileStreaming([, args]) -> retval
cv.GComputation.compileStreaming(callback[, args]) -> retval

這是一個過載成員函式,為方便起見而提供。它與上述函式的區別僅在於它接受的引數。

接受一個可變引數包,其中包含需要生成編譯物件的元資料描述符。

返回
GStreamingCompiled,一個專門為給定輸入引數編譯的面向流的可執行計算。

◆ compileStreaming() [4/5]

GAPI_WRAP GStreamingCompiled cv::GComputation::compileStreaming ( GCompileArgs && args = {})
Python
cv.GComputation.compileStreaming(in_metas[, args]) -> retval
cv.GComputation.compileStreaming([, args]) -> retval
cv.GComputation.compileStreaming(callback[, args]) -> retval

編譯流模式的計算。

此方法觸發編譯過程並生成一個新的 GStreamingCompiled 物件,然後該物件可以處理任何格式的影片流資料。底層機制將自動調整到每個新的輸入影片流,但請注意,並非所有現有後端都支援此功能(請參閱 reshape())。

引數
args此編譯過程的編譯引數。編譯引數直接影響將生成何種可執行物件,例如將使用哪些核心(以及因此,裝置)來執行計算。
返回
GStreamingCompiled,一個為任何輸入影像格式編譯的面向流的可執行計算。
另請參見
G-API 圖編譯引數

◆ compileStreaming() [5/5]

GAPI_WRAP GStreamingCompiled cv::GComputation::compileStreaming ( GMetaArgs && in_metas,
GCompileArgs && args = {} )
Python
cv.GComputation.compileStreaming(in_metas[, args]) -> retval
cv.GComputation.compileStreaming([, args]) -> retval
cv.GComputation.compileStreaming(callback[, args]) -> retval

編譯流模式的計算。

此方法觸發編譯過程並生成一個新的 GStreamingCompiled 物件,然後該物件可以處理給定格式的影片流資料。將不同格式的流傳遞給已編譯的計算將生成執行時異常。

引數
in_metas輸入元資料配置向量。從實際資料物件(如 cv::Matcv::Scalar)使用 cv::descr_of() 獲取元資料,或自行建立。
args此編譯過程的編譯引數。編譯引數直接影響將生成何種可執行物件,例如將使用哪些核心(以及因此,裝置)來執行計算。
返回
GStreamingCompiled,一個專門為給定輸入引數編譯的面向流的可執行計算。
另請參見
G-API 圖編譯引數

◆ recompile()

void cv::GComputation::recompile ( GMetaArgs && in_metas,
GCompileArgs && args )
保護

此類的文件是從以下檔案生成的