OpenCV仿射變換——平移
OpenCV仿射變換——平移
- OpenCV仿射變換——平移
- 公式及原理
- OpenCV函式
- 實作代碼
- 代碼執行效果
公式及原理
定義原坐標為(x,y),平移后(xoffect,yoffset)后的坐標為(x*,y* ):

也就是說,原來在(x,y)位置的像素值,被平移到(x’,y’ )位置處,為方便計算機運算,可以寫成矩陣樣式:

在OpenCV中的防射變換矩陣M就是:

OpenCV函式
通過cv::getAffineTransform函式得到變換矩陣
cv::Mat getAffineTransform(cv::InputArray src, cv::InputArray dst)
輸入
InputArray src:表示輸入的三個點
InputArray dstL:表示輸出的三個點
回傳
cv::Mat物件
通過cv::warpAffine得到平移或旋轉的cv::Mat物件
void warpAffine(InputArray src, OutputArray dst, InputArray M, Size dsize, int flags=INTER_LINEAR, int borderMode=BORDER_CONSTANT, const Scalar& borderValue=Scalar());
src : Source image.
**dst **: Destination image that has the size dsize and the same type as src .
M –:2\times 3 transformation matrix.
dsize : Size of the destination image.
flags : Combination of interpolation methods (see resize() ) and the optional flag WARP_INVERSE_MAP that means that M is the inverse transformation ( \texttt{dst}\rightarrow\texttt{src} ).
borderMode : Pixel extrapolation method (see borderInterpolate() ). When borderMode=BORDER_TRANSPARENT , it means that the pixels in the destination image corresponding to the “outliers” in the source image are not modified by the function.
borderValue – Value used in case of a constant border. By default, it is 0.
無回傳值
實作代碼
#include<iostream>
#include<opencv2/core.hpp>
#include<opencv2/imgproc.hpp>
#include<opencv2/highgui.hpp>
int main() {
cv::Mat src = cv::imread("D:\\Windows\\WorkSpace\\imageTest\\OIP.jpg"/>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/197366.html
標籤:其他
下一篇:技術大牛教你自學編程如何避坑
