OpenCV 4.12.0
開源計算機視覺
載入中...
搜尋中...
無匹配項
目標跟蹤

詳細描述

類  cv::DenseOpticalFlow
 
類  cv::DISOpticalFlow
 DIS 光流演算法。 更多...
 
類  cv::FarnebackOpticalFlow
 使用 Gunnar Farneback 演算法計算稠密光流的類。 更多...
 
類  cv::KalmanFilter
 卡爾曼濾波器類。 更多...
 
類  cv::SparseOpticalFlow
 稀疏光流演算法的基介面。 更多...
 
類  cv::SparsePyrLKOpticalFlow
 用於計算稀疏光流的類。 更多...
 
類  cv::Tracker
 長期跟蹤器的基抽象類。 更多...
 
類  cv::TrackerDaSiamRPN
 
類  cv::TrackerGOTURN
 GOTURN(使用迴歸網路的通用物件跟蹤)跟蹤器 更多...
 
類  cv::TrackerMIL
 MIL 演算法以線上方式訓練分類器,以將物件與背景分離。 更多...
 
類  cv::TrackerNano
 Nano 跟蹤器是一種超輕量級基於 DNN 的通用物件跟蹤器。 更多...
 
類  cv::TrackerVit
 VIT 跟蹤器是一種超輕量級基於 DNN 的通用物件跟蹤器。 更多...
 
類  cv::VariationalRefinement
 變分光流細化。 更多...
 

列舉

列舉  {
  cv::OPTFLOW_USE_INITIAL_FLOW = 4 ,
  cv::OPTFLOW_LK_GET_MIN_EIGENVALS = 8 ,
  cv::OPTFLOW_FARNEBACK_GAUSSIAN = 256
}
 
列舉  {
  cv::MOTION_TRANSLATION = 0 ,
  cv::MOTION_EUCLIDEAN = 1 ,
  cv::MOTION_AFFINE = 2 ,
  cv::MOTION_HOMOGRAPHY = 3
}
 

函式

int cv::buildOpticalFlowPyramid (InputArray img, OutputArrayOfArrays pyramid, Size winSize, int maxLevel, bool withDerivatives=true, int pyrBorder=BORDER_REFLECT_101, int derivBorder=BORDER_CONSTANT, bool tryReuseInputImage=true)
 構建可傳遞給 calcOpticalFlowPyrLK 的影像金字塔。
 
void cv::calcOpticalFlowFarneback (InputArray prev, InputArray next, InputOutputArray flow, double pyr_scale, int levels, int winsize, int iterations, int poly_n, double poly_sigma, int flags)
 使用 Gunnar Farneback 演算法計算稠密光流。
 
void cv::calcOpticalFlowPyrLK (InputArray prevImg, InputArray nextImg, InputArray prevPts, InputOutputArray nextPts, OutputArray status, OutputArray err, Size winSize=Size(21, 21), int maxLevel=3, TermCriteria criteria=TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 0.01), int flags=0, double minEigThreshold=1e-4)
 使用帶金字塔的迭代 Lucas-Kanade 方法計算稀疏特徵集的光流。
 
RotatedRect cv::CamShift (InputArray probImage, Rect &window, TermCriteria criteria)
 Finds an object center, size, and orientation.
 
double cv::computeECC (InputArray templateImage, InputArray inputImage, InputArray inputMask=noArray())
 計算兩幅影像之間的增強相關係數(ECC)值 [82]
 
Mat cv::estimateRigidTransform (InputArray src, InputArray dst, bool fullAffine)
 計算兩個二維點集之間的最佳仿射變換。
 
double cv::findTransformECC (InputArray templateImage, InputArray inputImage, InputOutputArray warpMatrix, int motionType, TermCriteria criteria, InputArray inputMask, int gaussFiltSize)
 根據 ECC 準則 [82] 尋找兩幅影像之間的幾何變換(扭曲)。
 
double cv::findTransformECC (InputArray templateImage, InputArray inputImage, InputOutputArray warpMatrix, int motionType=MOTION_AFFINE, TermCriteria criteria=TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 50, 0.001), InputArray inputMask=noArray())
 
int cv::meanShift (InputArray probImage, Rect &window, TermCriteria criteria)
 在反向投影影像上查詢物件。
 
Mat cv::readOpticalFlow (const String &path)
 讀取 .flo 檔案。
 
bool cv::writeOpticalFlow (const String &path, InputArray flow)
 將 .flo 寫入磁碟。
 

列舉型別文件

◆ 匿名列舉

匿名列舉

#include <opencv2/video/tracking.hpp>

列舉器
OPTFLOW_USE_INITIAL_FLOW 
Python: cv.OPTFLOW_USE_INITIAL_FLOW
OPTFLOW_LK_GET_MIN_EIGENVALS 
Python: cv.OPTFLOW_LK_GET_MIN_EIGENVALS
OPTFLOW_FARNEBACK_GAUSSIAN 
Python: cv.OPTFLOW_FARNEBACK_GAUSSIAN

◆ 匿名列舉

匿名列舉

#include <opencv2/video/tracking.hpp>

列舉器
MOTION_TRANSLATION 
Python: cv.MOTION_TRANSLATION
MOTION_EUCLIDEAN 
Python: cv.MOTION_EUCLIDEAN
MOTION_AFFINE 
Python: cv.MOTION_AFFINE
MOTION_HOMOGRAPHY 
Python: cv.MOTION_HOMOGRAPHY

函式文件

◆ buildOpticalFlowPyramid()

int cv::buildOpticalFlowPyramid ( InputArray img,
OutputArrayOfArrays pyramid,
Size winSize,
int maxLevel,
bool withDerivatives = true,
int pyrBorder = BORDER_REFLECT_101,
int derivBorder = BORDER_CONSTANT,
bool tryReuseInputImage = true )
Python
cv.buildOpticalFlowPyramid(img, winSize, maxLevel[, pyramid[, withDerivatives[, pyrBorder[, derivBorder[, tryReuseInputImage]]]]]) -> retval, pyramid

#include <opencv2/video/tracking.hpp>

構建可傳遞給 calcOpticalFlowPyrLK 的影像金字塔。

引數
img8 位輸入影像。
pyramid輸出金字塔。
winSize光流演算法的視窗大小。不得小於 calcOpticalFlowPyrLK 的 winSize 引數。需要它來計算金字塔層所需的填充。
maxLevel基於 0 的最大金字塔層數。
withDerivatives設定為預先計算每個金字塔層的梯度。如果金字塔構建時沒有梯度,則 calcOpticalFlowPyrLK 將在內部計算它們。
pyrBorder金字塔層的邊界模式。
derivBorder梯度的邊界模式。
tryReuseInputImage如果可能,將輸入影像的 ROI 放入金字塔。可以傳遞 false 以強制資料複製。
返回
構建的金字塔層數。可以小於 maxLevel。

◆ calcOpticalFlowFarneback()

void cv::calcOpticalFlowFarneback ( InputArray prev,
InputArray next (下一個),
InputOutputArray flow,
double pyr_scale,
int levels,
int winsize,
int iterations,
int poly_n,
double poly_sigma,
int flags )
Python
cv.calcOpticalFlowFarneback(prev, next, flow, pyr_scale, levels, winsize, iterations, poly_n, poly_sigma, flags) -> flow

#include <opencv2/video/tracking.hpp>

使用 Gunnar Farneback 演算法計算稠密光流。

引數
prev第一個 8 位單通道輸入影像。
next (下一個)與 prev 相同大小和型別的第二個輸入影像。
flow計算出的流影像,其大小與 prev 相同,型別為 CV_32FC2。
pyr_scale引數,指定用於為每個影像構建金字塔的影像比例(<1);pyr_scale=0.5 表示經典金字塔,其中每一層都比前一層小兩倍。
levels金字塔層數,包括初始影像;levels=1 表示不建立額外層,僅使用原始影像。
winsize平均視窗大小;更大的值會增加演算法對影像噪聲的魯棒性,並提供更多快速運動檢測的機會,但會產生更模糊的運動場。
iterations演算法在每個金字塔級別執行的迭代次數。
poly_n用於在每個畫素中尋找多項式展開的畫素鄰域大小;更大的值意味著影像將用更平滑的表面近似,從而產生更魯棒的演算法和更模糊的運動場,通常 poly_n =5 或 7。
poly_sigma高斯標準差,用於平滑作為多項式展開基礎的導數;對於 poly_n=5,可以將 poly_sigma 設定為 1.1;對於 poly_n=7,一個好的值將是 poly_sigma=1.5。
flags可以是以下組合的操作標誌
  • OPTFLOW_USE_INITIAL_FLOW 使用輸入流作為初始流近似。
  • OPTFLOW_FARNEBACK_GAUSSIAN 使用高斯 \(\texttt{winsize}\times\texttt{winsize}\) 濾波器而不是相同大小的方框濾波器進行光流估計;通常,此選項比方框濾波器提供更精確的流,但速度較慢;通常,高斯視窗的 winsize 應設定為更大的值以達到相同的魯棒性水平。

該函式使用 [84] 演算法為每個 prev 畫素找到光流,使得

\[\texttt{prev} (y,x) \sim \texttt{next} ( y + \texttt{flow} (y,x)[1], x + \texttt{flow} (y,x)[0])\]

注意
一些示例
  • 一個使用 Gunnar Farneback 描述的光流演算法的示例可以在 opencv_source_code/samples/cpp/fback.cpp 中找到。
  • (Python)一個使用 Gunnar Farneback 描述的光流演算法的示例可以在 opencv_source_code/samples/python/opt_flow.py 中找到。

◆ calcOpticalFlowPyrLK()

void cv::calcOpticalFlowPyrLK ( InputArray prevImg,
InputArray nextImg,
InputArray prevPts,
InputOutputArray nextPts,
OutputArray status,
OutputArray err,
Size winSize = Size(21, 21),
int maxLevel = 3,
TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 0.01),
int flags = 0,
double minEigThreshold = 1e-4 )
Python
cv.calcOpticalFlowPyrLK(prevImg, nextImg, prevPts, nextPts[, status[, err[, winSize[, maxLevel[, criteria[, flags[, minEigThreshold]]]]]]]) -> nextPts, status, err

#include <opencv2/video/tracking.hpp>

使用帶金字塔的迭代 Lucas-Kanade 方法計算稀疏特徵集的光流。

引數
prevImg第一個 8 位輸入影像或由 buildOpticalFlowPyramid 構建的金字塔。
nextImg第二個輸入影像或與 prevImg 大小和型別相同的金字塔。
prevPts需要尋找光流的二維點向量;點座標必須是單精度浮點數。
nextPts輸出的二維點向量(包含單精度浮點座標),其中包含第二幅影像中輸入特徵的計算新位置;當傳遞 OPTFLOW_USE_INITIAL_FLOW 標誌時,該向量必須與輸入的大小相同。
status輸出狀態向量(無符號字元);如果找到相應特徵的光流,向量的每個元素設定為 1,否則設定為 0。
err輸出誤差向量;向量的每個元素設定為相應特徵的誤差,誤差度量的型別可以在 flags 引數中設定;如果未找到光流,則誤差未定義(使用 status 引數查詢此類情況)。
winSize每個金字塔級別的搜尋視窗大小。
maxLevel基於 0 的最大金字塔層數;如果設定為 0,則不使用金字塔(單層),如果設定為 1,則使用兩層,依此類推;如果金字塔作為輸入傳遞,則演算法將使用金字塔擁有的層數,但不超過 maxLevel。
criteria引數,指定迭代搜尋演算法的終止標準(在達到指定的最大迭代次數 criteria.maxCount 後,或當搜尋視窗移動小於 criteria.epsilon 時)。
flags操作標誌
  • OPTFLOW_USE_INITIAL_FLOW 使用儲存在 nextPts 中的初始估計;如果未設定此標誌,則 prevPts 將複製到 nextPts 並被視為初始估計。
  • OPTFLOW_LK_GET_MIN_EIGENVALS 使用最小特徵值作為誤差度量(參見 minEigThreshold 描述);如果未設定此標誌,則使用原始點和移動點周圍補丁之間的 L1 距離,除以視窗中的畫素數,作為誤差度量。
minEigThreshold該演算法計算光流方程的 2x2 法線矩陣(該矩陣在 [37] 中稱為空間梯度矩陣)的最小特徵值,然後除以視窗中的畫素數;如果此值小於 minEigThreshold,則相應的特徵將被過濾掉且其光流不被處理,因此這允許移除壞點並獲得性能提升。

該函式實現了金字塔中 Lucas-Kanade 光流的稀疏迭代版本。參見 [37] 。該函式使用 TBB 庫進行並行化。

注意
一些示例
  • 一個使用 Lucas-Kanade 光流演算法的示例可以在 opencv_source_code/samples/cpp/lkdemo.cpp 中找到。
  • (Python)一個使用 Lucas-Kanade 光流演算法的示例可以在 opencv_source_code/samples/python/lk_track.py 中找到。
  • (Python)一個使用 Lucas-Kanade 跟蹤器進行單應性匹配的示例可以在 opencv_source_code/samples/python/lk_homography.py 中找到。

◆ CamShift()

RotatedRect cv::CamShift ( InputArray probImage,
Rect & window,
TermCriteria criteria )
Python
cv.CamShift(probImage, window, criteria) -> retval, window

#include <opencv2/video/tracking.hpp>

Finds an object center, size, and orientation.

引數
probImage物件直方圖的反向投影。參見 calcBackProject。
window初始搜尋視窗。
criteria底層 meanShift 的停止標準。返回(在舊介面中)CAMSHIFT 收斂所需的迭代次數。該函式實現了 CAMSHIFT 物件跟蹤演算法 [40] 。首先,它使用 meanShift 找到物件中心,然後調整視窗大小並找到最佳旋轉。該函式返回包含物件位置、大小和方向的旋轉矩形結構。搜尋視窗的下一個位置可以透過 RotatedRect::boundingRect() 獲取。

請參見 OpenCV 示例 camshiftdemo.c,該示例跟蹤彩色物件。

注意
  • (Python)一個解釋 camshift 跟蹤演算法的示例可以在 opencv_source_code/samples/python/camshift.py 中找到。

◆ computeECC()

double cv::computeECC ( InputArray templateImage,
InputArray inputImage,
InputArray inputMask = noArray() )
Python
cv.computeECC(templateImage, inputImage[, inputMask]) -> retval

#include <opencv2/video/tracking.hpp>

計算兩幅影像之間的增強相關係數(ECC)值 [82]

引數
templateImage單通道模板影像;CV_8U 或 CV_32F 陣列。
inputImage要扭曲的單通道輸入影像,以提供與 templateImage 相似的影像,型別與 templateImage 相同。
inputMask一個可選掩碼,用於指示 inputImage 的有效值。
另請參見
findTransformECC

◆ estimateRigidTransform()

Mat cv::estimateRigidTransform ( InputArray src,
InputArray dst,
bool fullAffine )

#include <opencv2/video/tracking.hpp>

計算兩個二維點集之間的最佳仿射變換。

引數
src第一個輸入二維點集,儲存在 std::vector 或 Mat 中,或者儲存在 Mat 中的影像。
dst第二個輸入二維點集,與 A 的大小和型別相同,或者是另一幅影像。
fullAffine如果為 true,該函式會找到沒有額外限制的最佳仿射變換(6 個自由度)。否則,可選擇的變換類別僅限於平移、旋轉和均勻縮放的組合(4 個自由度)。

該函式找到一個最佳仿射變換 [A|b](一個 2 x 3 浮點矩陣),它最能近似以下兩者之間的仿射變換

Two point sets
Two raster images. In this case, the function first finds some features in the src image and
finds the corresponding features in dst image. After that, the problem is reduced to the first
case.

在點集的情況下,問題表述如下:你需要找到一個 2x2 矩陣 A 和 2x1 向量 b,使得

\[[A^*|b^*] = arg \min _{[A|b]} \sum _i \| \texttt{dst}[i] - A { \texttt{src}[i]}^T - b \| ^2\]

其中 src[i] 和 dst[i] 分別是 src 和 dst 中的第 i 個點,\[A|b\] 可以是任意的(當 fullAffine=true 時)或具有以下形式

\[\begin{bmatrix} a_{11} & a_{12} & b_1 \\ -a_{12} & a_{11} & b_2 \end{bmatrix}\]

當 fullAffine=false 時。

已棄用
請改用 cv::estimateAffine2D, cv::estimateAffinePartial2D。如果將此函式用於影像,請使用 cv::calcOpticalFlowPyrLK 提取點,然後使用估計函式。
另請參見
estimateAffine2D, estimateAffinePartial2D, getAffineTransform, getPerspectiveTransform, findHomography

◆ findTransformECC() [1/2]

double cv::findTransformECC ( InputArray templateImage,
InputArray inputImage,
InputOutputArray warpMatrix,
int motionType,
TermCriteria criteria,
InputArray inputMask,
int gaussFiltSize )
Python
cv.findTransformECC(templateImage, inputImage, warpMatrix, motionType, criteria, inputMask, gaussFiltSize) -> retval, warpMatrix
cv.findTransformECC(templateImage, inputImage, warpMatrix[, motionType[, criteria[, inputMask]]]) -> retval, warpMatrix

#include <opencv2/video/tracking.hpp>

根據 ECC 準則 [82] 尋找兩幅影像之間的幾何變換(扭曲)。

引數
templateImage單通道模板影像;CV_8U 或 CV_32F 陣列。
inputImage單通道輸入影像,應使用最終的 warpMatrix 進行扭曲,以提供與 templateImage 相似的影像,型別與 templateImage 相同。
warpMatrix浮點 \(2\times 3\) 或 \(3\times 3\) 對映矩陣(扭曲)。
motionType引數,指定運動型別
  • MOTION_TRANSLATION 設定平移運動模型;warpMatrix 為 \(2\times 3\) 矩陣,其中前 \(2\times 2\) 部分是單位矩陣,其餘兩個引數被估計。
  • MOTION_EUCLIDEAN 設定歐幾里得(剛性)變換作為運動模型;估計三個引數;warpMatrix 為 \(2\times 3\)。
  • MOTION_AFFINE 設定仿射運動模型(預設);估計六個引數;warpMatrix 為 \(2\times 3\)。
  • MOTION_HOMOGRAPHY 設定單應性作為運動模型;估計八個引數;`warpMatrix` 為 \(3\times 3\)。
criteria引數,指定 ECC 演算法的終止標準;criteria.epsilon 定義兩次迭代之間相關係數增量的閾值(負的 criteria.epsilon 使 criteria.maxcount 成為唯一的終止標準)。預設值如上述宣告所示。
inputMask一個可選掩碼,用於指示 inputImage 的有效值。
gaussFiltSize一個可選值,指示高斯模糊濾波器的大小;(預設值:5)

該函式根據 ECC 準則 ([82]) 估計最佳變換 (warpMatrix),即

\[\texttt{warpMatrix} = \arg\max_{W} \texttt{ECC}(\texttt{templateImage}(x,y),\texttt{inputImage}(x',y'))\]

其中

\[\begin{bmatrix} x' \\ y' \end{bmatrix} = W \cdot \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}\]

(對於單應性,該方程在齊次座標下成立)。它返回最終的增強相關係數,即模板影像與最終扭曲輸入影像之間的相關係數。當給定一個 \(3\times 3\) 矩陣且 motionType =0、1 或 2 時,第三行將被忽略。

與 findHomography 和 estimateRigidTransform 不同,函式 findTransformECC 實現了一種基於區域的對齊,該對齊基於強度相似性。本質上,該函式更新大致對齊影像的初始變換。如果缺少此資訊,則使用單位扭曲(單位矩陣)作為初始化。請注意,如果影像發生強烈位移/旋轉,則需要一個大致對齊影像的初始變換(例如,一個簡單的歐幾里得/相似變換,允許影像大致顯示相同影像內容)。在第二幅影像中使用反向扭曲,使其接近第一幅影像,即在使用 warpAffine 或 warpPerspective 時使用 WARP_INVERSE_MAP 標誌。另請參閱 OpenCV 示例 image_alignment.cpp,該示例演示了該函式的使用。請注意,如果演算法不收斂,該函式將丟擲異常。

另請參見
computeECC, estimateAffine2D, estimateAffinePartial2D, findHomography

◆ findTransformECC() [2/2]

double cv::findTransformECC ( InputArray templateImage,
InputArray inputImage,
InputOutputArray warpMatrix,
int motionType = MOTION_AFFINE,
TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 50, 0.001),
InputArray inputMask = noArray() )
Python
cv.findTransformECC(templateImage, inputImage, warpMatrix, motionType, criteria, inputMask, gaussFiltSize) -> retval, warpMatrix
cv.findTransformECC(templateImage, inputImage, warpMatrix[, motionType[, criteria[, inputMask]]]) -> retval, warpMatrix

#include <opencv2/video/tracking.hpp>

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

◆ meanShift()

int cv::meanShift ( InputArray probImage,
Rect & window,
TermCriteria criteria )
Python
cv.meanShift(probImage, window, criteria) -> retval, window

#include <opencv2/video/tracking.hpp>

在反向投影影像上查詢物件。

引數
probImage物件直方圖的反向投影。詳情參見 calcBackProject。
window初始搜尋視窗。
criteria迭代搜尋演算法的停止標準。返回:CAMSHIFT 收斂所需的迭代次數。該函式實現了迭代物件搜尋演算法。它接受物件的輸入反向投影和初始位置。計算反向投影影像視窗中的質量中心,並將搜尋視窗中心移動到質量中心。該過程重複進行,直到達到指定的迭代次數 criteria.maxCount 或直到視窗中心移動小於 criteria.epsilon。該演算法在 CamShift 內部使用,與 CamShift 不同的是,在搜尋過程中搜索視窗的大小或方向不會改變。您可以直接將 calcBackProject 的輸出傳遞給此函式。但如果您預過濾反向投影並去除噪聲,可以獲得更好的結果。例如,您可以透過 findContours 檢索連通分量,丟棄小面積的輪廓 (contourArea),並使用 drawContours 渲染剩餘的輪廓來做到這一點。

◆ readOpticalFlow()

Mat cv::readOpticalFlow ( const String & 路徑)
Python
cv.readOpticalFlow(路徑) -> retval

#include <opencv2/video/tracking.hpp>

讀取 .flo 檔案。

引數
路徑要載入的檔案路徑

函式 readOpticalFlow 從檔案中載入流場並將其作為單個矩陣返回。結果 Mat 的型別為 CV_32FC2 - 浮點,2 通道。第一個通道對應水平方向的流 (u),第二個通道對應垂直方向的流 (v)。

◆ writeOpticalFlow()

bool cv::writeOpticalFlow ( const String & 路徑,
InputArray flow )
Python
cv.writeOpticalFlow(path, flow) -> retval

#include <opencv2/video/tracking.hpp>

將 .flo 寫入磁碟。

引數
路徑要寫入的檔案路徑
flow要儲存的流場

該函式將流場儲存到檔案中,成功返回 true,否則返回 false。流場必須是 2 通道浮點矩陣 (CV_32FC2)。第一個通道對應水平方向的流 (u),第二個通道對應垂直方向的流 (v)。