OpenCV 4.12.0
開源計算機視覺
載入中...
搜尋中...
無匹配項
影像幾何變換

詳細描述

本節中的函式對二維影像執行各種幾何變換。它們不改變影像內容,而是使畫素網格變形,並將這個變形的網格對映到目標影像。事實上,為了避免取樣偽影,對映以反向順序進行,即從目標到源。也就是說,對於目標影像的每個畫素 \((x, y)\),函式計算源影像中相應“捐贈”畫素的座標,並複製畫素值

\[\texttt{dst} (x,y)= \texttt{src} (f_x(x,y), f_y(x,y))\]

如果您指定了正向對映 \(\left<g_x, g_y\right>: \texttt{src} \rightarrow \texttt{dst}\),OpenCV函式會首先計算相應的逆對映 \(\left<f_x, f_y\right>: \texttt{dst} \rightarrow \texttt{src}\),然後使用上述公式。

幾何變換的實際實現,從最通用的 remap 到最簡單、最快的 resize,需要解決上述公式中的兩個主要問題

注意
幾何變換不適用於 CV_8SCV_32S 影像。

列舉

列舉  cv::InterpolationFlags {
  cv::INTER_NEAREST = 0 ,
  cv::INTER_LINEAR = 1 ,
  cv::INTER_CUBIC = 2 ,
  cv::INTER_AREA = 3 ,
  cv::INTER_LANCZOS4 = 4 ,
  cv::INTER_LINEAR_EXACT = 5 ,
  cv::INTER_NEAREST_EXACT = 6 ,
  cv::INTER_MAX = 7 ,
  cv::WARP_FILL_OUTLIERS = 8 ,
  cv::WARP_INVERSE_MAP = 16 ,
  cv::WARP_RELATIVE_MAP = 32
}
 插值演算法 更多...
 
列舉  cv::InterpolationMasks {
  cv::INTER_BITS = 5 ,
  cv::INTER_BITS2 = INTER_BITS * 2 ,
  cv::INTER_TAB_SIZE = 1 << INTER_BITS ,
  cv::INTER_TAB_SIZE2 = INTER_TAB_SIZE * INTER_TAB_SIZE
}
 
列舉  cv::WarpPolarMode {
  cv::WARP_POLAR_LINEAR = 0 ,
  cv::WARP_POLAR_LOG = 256
}
 指定極座標對映模式。 更多...
 

函式

void cv::convertMaps (InputArray map1, InputArray map2, OutputArray dstmap1, OutputArray dstmap2, int dstmap1type, bool nninterpolation=false)
 將影像變換對映從一種表示形式轉換為另一種。
 
Mat cv::getAffineTransform (const Point2f src[], const Point2f dst[])
 從三對對應點計算仿射變換。
 
Mat cv::getAffineTransform (InputArray src, InputArray dst)
 
Mat cv::getPerspectiveTransform (const Point2f src[], const Point2f dst[], int solveMethod=DECOMP_LU)
 
Mat cv::getPerspectiveTransform (InputArray src, InputArray dst, int solveMethod=DECOMP_LU)
 從四對對應點計算透視變換。
 
void cv::getRectSubPix (InputArray image, Size patchSize, Point2f center, OutputArray patch, int patchType=-1)
 從影像中以亞畫素精度檢索畫素矩形。
 
Mat cv::getRotationMatrix2D (Point2f center, double angle, double scale)
 計算 2D 旋轉的仿射矩陣。
 
Matx23d cv::getRotationMatrix2D_ (Point2f center, double angle, double scale)
 
void cv::invertAffineTransform (InputArray M, OutputArray iM)
 反轉仿射變換。
 
void cv::linearPolar (InputArray src, OutputArray dst, Point2f center, double maxRadius, int flags)
 將影像重對映到極座標空間。
 
void cv::logPolar (InputArray src, OutputArray dst, Point2f center, double M, int flags)
 將影像重對映到半對數極座標空間。
 
void cv::remap (InputArray src, OutputArray dst, InputArray map1, InputArray map2, int interpolation, int borderMode=BORDER_CONSTANT, const Scalar &borderValue=Scalar())
 對影像應用通用幾何變換。
 
void cv::resize (InputArray src, OutputArray dst, Size dsize, double fx=0, double fy=0, int interpolation=INTER_LINEAR)
 調整影像大小。
 
void cv::warpAffine (InputArray src, OutputArray dst, InputArray M, Size dsize, int flags=INTER_LINEAR, int borderMode=BORDER_CONSTANT, const Scalar &borderValue=Scalar())
 對影像應用仿射變換。
 
void cv::warpPerspective (InputArray src, OutputArray dst, InputArray M, Size dsize, int flags=INTER_LINEAR, int borderMode=BORDER_CONSTANT, const Scalar &borderValue=Scalar())
 對影像應用透視變換。
 
void cv::warpPolar (InputArray src, OutputArray dst, Size dsize, Point2f center, double maxRadius, int flags)
 將影像重對映到極座標或半對數極座標空間。
 

列舉型別文件

◆ InterpolationFlags

#include <opencv2/imgproc.hpp>

插值演算法

列舉器
INTER_NEAREST 
Python: cv.INTER_NEAREST

最近鄰插值

INTER_LINEAR 
Python: cv.INTER_LINEAR

雙線性插值

INTER_CUBIC 
Python: cv.INTER_CUBIC

雙三次插值

INTER_AREA 
Python: cv.INTER_AREA

使用畫素區域關係進行重取樣。對於影像抽取,它可能是首選方法,因為它能產生無莫爾條紋的結果。但當影像放大時,它類似於 INTER_NEAREST 方法。

INTER_LANCZOS4 
Python: cv.INTER_LANCZOS4

8x8 鄰域上的 Lanczos 插值

INTER_LINEAR_EXACT 
Python: cv.INTER_LINEAR_EXACT

位精確雙線性插值

INTER_NEAREST_EXACT 
Python: cv.INTER_NEAREST_EXACT

位精確最近鄰插值。這將產生與 PIL、scikit-image 或 Matlab 中最近鄰方法相同的結果。

INTER_MAX 
Python: cv.INTER_MAX

插值程式碼掩碼

WARP_FILL_OUTLIERS 
Python: cv.WARP_FILL_OUTLIERS

標誌,填充所有目標影像畫素。如果其中一些對應於源影像中的異常值,則將其設定為零

WARP_INVERSE_MAP 
Python: cv.WARP_INVERSE_MAP

標誌,逆變換

例如,linearPolarlogPolar 變換

  • 標誌設定:\(dst( \rho , \phi ) = src(x,y)\)
  • 標誌已設定:\(dst(x,y) = src( \rho , \phi )\)
WARP_RELATIVE_MAP 
Python: cv.WARP_RELATIVE_MAP

◆ InterpolationMasks

#include <opencv2/imgproc.hpp>

列舉器
INTER_BITS 
Python: cv.INTER_BITS
INTER_BITS2 
Python: cv.INTER_BITS2
INTER_TAB_SIZE 
Python: cv.INTER_TAB_SIZE
INTER_TAB_SIZE2 
Python: cv.INTER_TAB_SIZE2

◆ WarpPolarMode

#include <opencv2/imgproc.hpp>

指定極座標對映模式。

另請參見
warpPolar
列舉器
WARP_POLAR_LINEAR 
Python: cv.WARP_POLAR_LINEAR

將影像對映到/從極座標空間。

WARP_POLAR_LOG 
Python: cv.WARP_POLAR_LOG

將影像對映到/從半對數極座標空間。

函式文件

◆ convertMaps()

void cv::convertMaps ( InputArray map1,
InputArray map2,
OutputArray dstmap1,
OutputArray dstmap2,
int dstmap1type,
bool nninterpolation = false )
Python
cv.convertMaps(map1, map2, dstmap1type[, dstmap1[, dstmap2[, nninterpolation]]]) -> dstmap1, dstmap2

#include <opencv2/imgproc.hpp>

將影像變換對映從一種表示形式轉換為另一種。

該函式將 remap 的一對對映從一種表示形式轉換為另一種。支援以下選項 ( (map1.type(), map2.type()) \(\rightarrow\) (dstmap1.type(), dstmap2.type()) )

  • \(\texttt{(CV_32FC1, CV_32FC1)} \rightarrow \texttt{(CV_16SC2, CV_16UC1)}\)。這是最常用的轉換操作,其中原始浮點對映(參見 remap)被轉換為更緊湊、更快的定點表示。第一個輸出陣列包含四捨五入後的座標,第二個陣列(僅在 nninterpolation=false 時建立)包含插值表中的索引。
  • \(\texttt{(CV_32FC2)} \rightarrow \texttt{(CV_16SC2, CV_16UC1)}\)。與上述相同,但原始對映儲存在一個2通道矩陣中。
  • 反向轉換。顯然,重建的浮點對映不會與原始對映完全相同。
引數
map1型別為 CV_16SC2、CV_32FC1 或 CV_32FC2 的第一個輸入對映。
map2型別分別為 CV_16UC1、CV_32FC1 或無(空矩陣)的第二個輸入對映。
dstmap1具有 dstmap1type 型別且與 src 大小相同的第一個輸出對映。
dstmap2第二個輸出對映。
dstmap1type第一個輸出對映的型別,應為 CV_16SC2、CV_32FC1 或 CV_32FC2。
nninterpolation指示定點對映是用於最近鄰插值還是更復雜的插值的標誌。
另請參見
remap, undistort, initUndistortRectifyMap

◆ getAffineTransform() [1/2]

Mat cv::getAffineTransform ( const Point2f src[],
const Point2f dst[] )
Python
cv.getAffineTransform(src, dst) -> retval

#include <opencv2/imgproc.hpp>

從三對對應點計算仿射變換。

該函式計算仿射變換的 \(2 \times 3\) 矩陣,使得

\[\begin{bmatrix} x'_i \\ y'_i \end{bmatrix} = \texttt{map_matrix} \cdot \begin{bmatrix} x_i \\ y_i \\ 1 \end{bmatrix}\]

其中

\[dst(i)=(x'_i,y'_i), src(i)=(x_i, y_i), i=0,1,2\]

引數
src源影像中三角形頂點的座標。
dst目標影像中相應三角形頂點的座標。
另請參見
warpAffine, transform

◆ getAffineTransform() [2/2]

Mat cv::getAffineTransform ( InputArray src,
InputArray dst )
Python
cv.getAffineTransform(src, dst) -> retval

#include <opencv2/imgproc.hpp>

◆ getPerspectiveTransform() [1/2]

Mat cv::getPerspectiveTransform ( const Point2f src[],
const Point2f dst[],
int solveMethod = DECOMP_LU )
Python
cv.getPerspectiveTransform(src, dst[, solveMethod]) -> retval

#include <opencv2/imgproc.hpp>

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

◆ getPerspectiveTransform() [2/2]

Mat cv::getPerspectiveTransform ( InputArray src,
InputArray dst,
int solveMethod = DECOMP_LU )
Python
cv.getPerspectiveTransform(src, dst[, solveMethod]) -> retval

#include <opencv2/imgproc.hpp>

從四對對應點計算透視變換。

該函式計算透視變換的 \(3 \times 3\) 矩陣,使得

\[\begin{bmatrix} t_i x'_i \\ t_i y'_i \\ t_i \end{bmatrix} = \texttt{map_matrix} \cdot \begin{bmatrix} x_i \\ y_i \\ 1 \end{bmatrix}\]

其中

\[dst(i)=(x'_i,y'_i), src(i)=(x_i, y_i), i=0,1,2,3\]

引數
src源影像中四邊形頂點的座標。
dst目標影像中相應四邊形頂點的座標。
solveMethod傳遞給 cv::solve (DecompTypes) 的方法
另請參見
findHomography, warpPerspective, perspectiveTransform

◆ getRectSubPix()

void cv::getRectSubPix ( InputArray image,
Size patchSize,
Point2f center,
OutputArray patch,
int patchType = -1 )
Python
cv.getRectSubPix(image, patchSize, center[, patch[, patchType]]) -> patch

#include <opencv2/imgproc.hpp>

從影像中以亞畫素精度檢索畫素矩形。

函式 getRectSubPix 從 src 提取畫素

\[patch(x, y) = src(x + \texttt{center.x} - ( \texttt{dst.cols} -1)*0.5, y + \texttt{center.y} - ( \texttt{dst.rows} -1)*0.5)\]

其中非整數座標處的畫素值使用雙線性插值檢索。多通道影像的每個通道都獨立處理。影像也應該是單通道或三通道影像。雖然矩形的中心必須在影像內部,但矩形的部分可能在外部。

引數
image源影像。
patchSize提取的塊的大小。
center源影像中提取矩形中心的浮點座標。中心必須在影像內部。
patch提取的塊,其大小為 patchSize,通道數與 src 相同。
patchType提取畫素的深度。預設情況下,它們與 src 具有相同的深度。
另請參見
warpAffine, warpPerspective

◆ getRotationMatrix2D()

Mat cv::getRotationMatrix2D ( Point2f center,
double angle,
double #include <opencv2/surface_matching/ppf_helpers.hpp>
inline
Python
cv.getRotationMatrix2D(center, angle, scale) -> retval

#include <opencv2/imgproc.hpp>

計算 2D 旋轉的仿射矩陣。

該函式計算以下矩陣

\[\begin{bmatrix} \alpha & \beta & (1- \alpha ) \cdot \texttt{center.x} - \beta \cdot \texttt{center.y} \\ - \beta & \alpha & \beta \cdot \texttt{center.x} + (1- \alpha ) \cdot \texttt{center.y} \end{bmatrix}\]

其中

\[\begin{array}{l} \alpha = \texttt{scale} \cdot \cos \texttt{angle} , \\ \beta = \texttt{scale} \cdot \sin \texttt{angle} \end{array}\]

該變換將旋轉中心對映到自身。如果這不是目標,請調整偏移。

引數
center源影像中的旋轉中心。
angle旋轉角度(度)。正值表示逆時針旋轉(假定座標原點為左上角)。
scale各向同性比例因子。
另請參見
getAffineTransform, warpAffine, transform
此函式的呼叫圖如下

◆ getRotationMatrix2D_()

Matx23d cv::getRotationMatrix2D_ ( Point2f center,
double angle,
double #include <opencv2/surface_matching/ppf_helpers.hpp>

#include <opencv2/imgproc.hpp>

另請參見
getRotationMatrix2D

◆ invertAffineTransform()

void cv::invertAffineTransform ( InputArray M,
OutputArray iM )
Python
cv.invertAffineTransform(M[, iM]) -> iM

#include <opencv2/imgproc.hpp>

反轉仿射變換。

該函式計算由 \(2 \times 3\) 矩陣 M 表示的逆仿射變換

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

結果也是一個與 M 型別相同的 \(2 \times 3\) 矩陣。

引數
M原始仿射變換。
iM輸出逆仿射變換。

◆ linearPolar()

void cv::linearPolar ( InputArray src,
OutputArray dst,
Point2f center,
double maxRadius,
int flags )
Python
cv.linearPolar(src, center, maxRadius, flags[, dst]) -> dst

#include <opencv2/imgproc.hpp>

將影像重對映到極座標空間。

已棄用
該函式產生與 cv::warpPolar(src, dst, src.size(), center, maxRadius, flags) 相同的結果

◆ logPolar()

void cv::logPolar ( InputArray src,
OutputArray dst,
Point2f center,
double M,
int flags )
Python
cv.logPolar(src, center, M, flags[, dst]) -> dst

#include <opencv2/imgproc.hpp>

將影像重對映到半對數極座標空間。

已棄用
該函式產生與 cv::warpPolar(src, dst, src.size(), center, maxRadius, flags+WARP_POLAR_LOG) 相同的結果;

◆ remap()

void cv::remap ( InputArray src,
OutputArray dst,
InputArray map1,
InputArray map2,
int interpolation,
int borderMode = BORDER_CONSTANT,
const Scalar & borderValue = Scalar() )
Python
cv.remap(src, map1, map2, interpolation[, dst[, borderMode[, borderValue]]]) -> dst

#include <opencv2/imgproc.hpp>

對影像應用通用幾何變換。

函式 remap 使用指定對映變換源影像

\[\texttt{dst} (x,y) = \texttt{src} (map_x(x,y),map_y(x,y))\]

帶有 WARP_RELATIVE_MAP 標誌時

\[\texttt{dst} (x,y) = \texttt{src} (x+map_x(x,y),y+map_y(x,y))\]

其中非整數座標處的畫素值使用可用插值方法之一計算。\ (map_x\) 和 \(map_y\) 可以分別編碼為 \(map_1\) 和 \(map_2\) 中的單獨浮點對映,或者 \(map_1\) 中的交錯浮點 \((x,y)\) 對映,或者使用 convertMaps 建立的定點對映。您可能希望將對映從浮點表示轉換為定點表示的原因是它們可以使重對映操作快得多(2倍)。在轉換的情況下,\(map_1\) 包含對 (cvFloor(x), cvFloor(y)),而 \(map_2\) 包含插值係數表中的索引。

此函式不能原地操作。

引數
src源影像。
dst目標影像。它與 map1 具有相同的大小,並且與 src 具有相同的型別。
map1包含 (x,y) 點或僅 x 值的第一個對映,型別為 CV_16SC2、CV_32FC1 或 CV_32FC2。有關將浮點表示轉換為定點以提高速度的詳細資訊,請參閱 convertMaps
map2包含 y 值的第二個對映,型別分別為 CV_16UC1、CV_32FC1 或無(如果 map1 是 (x,y) 點則為空對映)。
interpolation插值方法(參見 InterpolationFlags)。此函式不支援 INTER_AREAINTER_LINEAR_EXACTINTER_NEAREST_EXACT 方法。額外標誌 WARP_RELATIVE_MAP 可以與插值方法進行位或運算(例如 INTER_LINEAR | WARP_RELATIVE_MAP)
borderMode畫素外推方法(參見 BorderTypes)。當 borderMode=BORDER_TRANSPARENT 時,這意味著目標影像中對應於源影像中“異常值”的畫素不會被函式修改。
borderValue常量邊界情況下使用的值。預設值為 0。
注意
由於當前的實現限制,輸入和輸出影像的大小應小於 32767x32767。

◆ resize()

void cv::resize ( InputArray src,
OutputArray dst,
Size dsize,
double fx = 0,
double fy = 0,
int interpolation = INTER_LINEAR )
Python
cv.resize(src, dsize[, dst[, fx[, fy[, interpolation]]]]) -> dst

#include <opencv2/imgproc.hpp>

調整影像大小。

函式 resize 將影像 src 放大或縮小到指定大小。請注意,不考慮初始 dst 型別或大小。相反,大小和型別是從 srcdsizefxfy 推匯出來的。如果您想調整 src 的大小以適應預建立的 dst,可以按如下方式呼叫該函式

// explicitly specify dsize=dst.size(); fx and fy will be computed from that.
resize(src, dst, dst.size(), 0, 0, interpolation);
void resize(InputArray src, OutputArray dst, Size dsize, double fx=0, double fy=0, int interpolation=INTER_LINEAR)
調整影像大小。

如果您想在每個方向上將影像抽取2倍,可以這樣呼叫函式

// specify fx and fy and let the function compute the destination image size.
resize(src, dst, Size(), 0.5, 0.5, interpolation);
Size2i Size
定義 types.hpp:370

縮小影像時,通常使用 INTER_AREA 插值效果最佳,而放大影像時,通常使用 INTER_CUBIC(慢)或 INTER_LINEAR(更快但效果仍可接受)效果最佳。

引數
src輸入影像。
dst輸出影像;其大小為 dsize(非零時)或由 src.size()、fx 和 fy 計算得出;dst 的型別與 src 相同。
dsize輸出影像大小;如果為零(Python 中為 None),則計算為

\[\texttt{dsize = Size(round(fx*src.cols), round(fy*src.rows))}\]

dsize 或 fx 和 fy 必須都非零。
fx沿水平軸的比例因子;當其為 0 時,計算為

\[\texttt{(double)dsize.width/src.cols}\]

fy沿垂直軸的比例因子;當其為 0 時,計算為

\[\texttt{(double)dsize.height/src.rows}\]

interpolation插值方法,參見 InterpolationFlags
另請參見
warpAffine, warpPerspective, remap

◆ warpAffine()

void cv::warpAffine ( InputArray src,
OutputArray dst,
InputArray M,
Size dsize,
int flags = INTER_LINEAR,
int borderMode = BORDER_CONSTANT,
const Scalar & borderValue = Scalar() )
Python
cv.warpAffine(src, M, dsize[, dst[, flags[, borderMode[, borderValue]]]]) -> dst

#include <opencv2/imgproc.hpp>

對影像應用仿射變換。

函式 warpAffine 使用指定矩陣變換源影像

\[\texttt{dst} (x,y) = \texttt{src} ( \texttt{M} _{11} x + \texttt{M} _{12} y + \texttt{M} _{13}, \texttt{M} _{21} x + \texttt{M} _{22} y + \texttt{M} _{23})\]

當設定了標誌 WARP_INVERSE_MAP 時。否則,變換首先透過 invertAffineTransform 反轉,然後將其放入上述公式中代替 M。此函式不能原地操作。

引數
src輸入影像。
dst目標影像,其大小為 dsize,型別與 src 相同。
M\(2\times 3\) 變換矩陣。
dsize輸出影像的尺寸。
flags插值方法的組合(參見 InterpolationFlags)以及可選標誌 WARP_INVERSE_MAP,表示 M 是逆變換( \(\texttt{dst}\rightarrow\texttt{src}\) )。
borderMode畫素外推方法(參見 BorderTypes);當 borderMode=BORDER_TRANSPARENT 時,這意味著目標影像中對應於源影像中“異常值”的畫素不會被函式修改。
borderValue在常數邊界情況下使用的值;預設情況下,它是 0。
另請參見
warpPerspective, resize, remap, getRectSubPix, transform

◆ warpPerspective()

void cv::warpPerspective ( InputArray src,
OutputArray dst,
InputArray M,
Size dsize,
int flags = INTER_LINEAR,
int borderMode = BORDER_CONSTANT,
const Scalar & borderValue = Scalar() )
Python
cv.warpPerspective(src, M, dsize[, dst[, flags[, borderMode[, borderValue]]]]) -> dst

#include <opencv2/imgproc.hpp>

對影像應用透視變換。

函式 warpPerspective 使用指定矩陣變換源影像

\[\texttt{dst} (x,y) = \texttt{src} \left ( \frac{M_{11} x + M_{12} y + M_{13}}{M_{31} x + M_{32} y + M_{33}} , \frac{M_{21} x + M_{22} y + M_{23}}{M_{31} x + M_{32} y + M_{33}} \right )\]

當設定了標誌 WARP_INVERSE_MAP 時。否則,變換首先透過 invert 反轉,然後將其放入上述公式中代替 M。此函式不能原地操作。

引數
src輸入影像。
dst目標影像,其大小為 dsize,型別與 src 相同。
M\(3\times 3\) 變換矩陣。
dsize輸出影像的尺寸。
flags插值方法的組合(INTER_LINEARINTER_NEAREST)以及可選標誌 WARP_INVERSE_MAP,它將 M 設定為逆變換( \(\texttt{dst}\rightarrow\texttt{src}\) )。
borderMode畫素外推方法(BORDER_CONSTANTBORDER_REPLICATE)。
borderValue在常量邊界情況下使用的值;預設為 0。
另請參見
warpAffine, resize, remap, getRectSubPix, perspectiveTransform

◆ warpPolar()

void cv::warpPolar ( InputArray src,
OutputArray dst,
Size dsize,
Point2f center,
double maxRadius,
int flags )
Python
cv.warpPolar(src, dsize, center, maxRadius, flags[, dst]) -> dst

#include <opencv2/imgproc.hpp>

將影像重對映到極座標或半對數極座標空間。

使用以下變換轉換源影像

\[ dst(\rho , \phi ) = src(x,y) \]

其中

\[ \begin{array}{l} \vec{I} = (x - center.x, \;y - center.y) \\ \phi = Kangle \cdot \texttt{angle} (\vec{I}) \\ \rho = \left\{\begin{matrix} Klin \cdot \texttt{magnitude} (\vec{I}) & default \\ Klog \cdot log_e(\texttt{magnitude} (\vec{I})) & if \; semilog \\ \end{matrix}\right. \end{array} \]

\[ \begin{array}{l} Kangle = dsize.height / 2\Pi \\ Klin = dsize.width / maxRadius \\ Klog = dsize.width / log_e(maxRadius) \\ \end{array} \]

線性與半對數對映

極座標對映可以是線性的或半對數的。將 WarpPolarMode 之一新增到 flags 以指定極座標對映模式。

線性是預設模式。

半對數對映模仿了人類的“中央凹”視覺,它允許在視線(中央視覺)上具有非常高的敏銳度,而與敏銳度較低的周邊視覺形成對比。

關於 dsize 的選項
  • 如果 dsize 中的兩個值都 <=0(預設),則目標影像將具有(幾乎)與源邊界圓相同的面積

    \[\begin{array}{l} dsize.area \leftarrow (maxRadius^2 \cdot \Pi) \\ dsize.width = \texttt{cvRound}(maxRadius) \\ dsize.height = \texttt{cvRound}(maxRadius \cdot \Pi) \\ \end{array}\]

  • 如果只有 dsize.height <= 0,則目標影像面積將與邊界圓面積成比例,但按 Kx * Kx 縮放

    \[\begin{array}{l} dsize.height = \texttt{cvRound}(dsize.width \cdot \Pi) \\ \end{array} \]

  • 如果 dsize 中的兩個值都 > 0,則目標影像將具有給定大小,因此邊界圓的面積將縮放到 dsize
反向對映

可以透過將 WARP_INVERSE_MAP 新增到 flags 來獲得反向對映

// 直接變換
warpPolar(src, lin_polar_img, Size(),center, maxRadius, flags); // linear Polar
warpPolar(src, log_polar_img, Size(),center, maxRadius, flags + WARP_POLAR_LOG); // semilog Polar
// 逆變換
warpPolar(lin_polar_img, recovered_lin_polar_img, src.size(), center, maxRadius, flags + WARP_INVERSE_MAP);
warpPolar(log_polar_img, recovered_log_polar, src.size(), center, maxRadius, flags + WARP_POLAR_LOG + WARP_INVERSE_MAP);

此外,要從極座標對映座標 \((rho, phi)->(x, y)\) 計算原始座標

double angleRad, magnitude;
double Kangle = dst.rows / CV_2PI;
angleRad = phi / Kangle;
if (flags & WARP_POLAR_LOG)
{
double Klog = dst.cols / std::log(maxRadius);
magnitude = std::exp(rho / Klog);
}
else
{
double Klin = dst.cols / maxRadius;
magnitude = rho / Klin;
}
int x = cvRound(center.x + magnitude * cos(angleRad));
int y = cvRound(center.y + magnitude * sin(angleRad));
引數
src源影像。
dst目標影像。它將與 src 具有相同的型別。
dsize目標影像大小(有效選項請參見描述)。
center變換中心。
maxRadius要變換的邊界圓的半徑。它也決定了逆幅值比例引數。
flags插值方法的組合,InterpolationFlags + WarpPolarMode
注意
  • 此函式不能原地操作。
  • 為了計算幅度和角度(以度為單位),內部使用了 cartToPolar,因此角度測量範圍為 0 到 360 度,精度約為 0.3 度。
  • 此函式使用 remap。由於當前的實現限制,輸入和輸出影像的大小應小於 32767x32767。
另請參見
cv::remap