日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

OpenCV图像旋转,指定填充背景颜色边界颜色

發布時間:2024/4/15 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 OpenCV图像旋转,指定填充背景颜色边界颜色 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

OpenCV圖像旋轉,指定填充背景顏色邊界顏色

OpenCV與圖像旋轉有關的函數: (1)warpAffine函數
void cv::warpAffine(InputArray?src,
??OutputArray?dst,
??InputArray?M,
??Size?dsize,
??int?flags?=?INTER_LINEAR,
??int?borderMode?=?BORDER_CONSTANT,
??const?Scalar?&?borderValue?=?Scalar()?
?)??

Applies an affine transformation to an image.

The function warpAffine transforms the source image using the specified matrix:

dst(x,y)=src(M11x+M12y+M13,M21x+M22y+M23)

when the flag WARP_INVERSE_MAP is set. Otherwise, the transformation is first inverted with?cv::invertAffineTransform?and then put in the formula above instead of M. The function cannot operate in-place.

Parameters
srcinput image.
dstoutput image that has the size dsize and the same type as src .
M2×3?transformation matrix.
dsizesize of the output image.
flagscombination of interpolation methods (see?cv::InterpolationFlags) and the optional flag WARP_INVERSE_MAP that means that M is the inverse transformation (?dstsrc?).
borderModepixel extrapolation method (see?cv::BorderTypes); 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.
borderValuevalue used in case of a constant border; by default, it is 0.
中文解釋: ? ? C++: void warpAffine(InputArray src, OutputArray dst, InputArray M, Size dsize, int flags=INTER_LINEAR, intborderMode=BORDER_CONSTANT, const Scalar& borderValue=Scalar())
? InputArray src:輸入的圖像C++: void warpAffine(InputArray src, OutputArray dst, InputArray M, Size dsize, int flags=INTER_LINEAR, intborderMode=BORDER_CONSTANT, const Scalar& borderValue=Scalar())
? 第1個參數:OutputArray dst:輸出的圖像?
? 第2個參數:InputArray M:透視變換的矩陣
? 第3個參數:Size dsize:輸出圖像的大小
? 第4個參數:int flags=INTER_LINEAR:輸出圖像的插值方法,可以為
? ? ? ? ? ? INTER_LINEAR 線性插值;
? ? ? ? ? ? INTER_NEAREST 最近鄰插值;
? ? ? ? ? ? INTER_AREA 區域插值
? ? ? ? ? ? INTER_CUBIC 三次條樣插值
? ? ? ? ? ? CV_WARP_INVERSE_MAP:指定 matrix 是輸出圖像到輸入圖像的反變換,因此可以直接用來做象素插值。否則, 函數從 map_matrix 得到反變換。
? ? ? ? ? ? CV_WARP_FILL_OUTLIERS:填充所有縮小圖像的象素。如果部分象素落在輸入圖像的邊界外,那么它們的值設定為 fillval(fillval
用來填充邊界外面的值).

? 第5個參數:int borderMode:圖像邊界的處理方式,默認是BORDER_CONSTANT(即指定常數值填充) ,實質上,邊界處理類型,該枚舉型還有:

Enumerator
BORDER_CONSTANT?

iiiiii|abcdefgh|iiiiiii?with some specified?i(指定常數填充)

BORDER_REPLICATE?

aaaaaa|abcdefgh|hhhhhhh(復制邊緣像素填充)

BORDER_REFLECT?

fedcba|abcdefgh|hgfedcb(反射復制邊界像素)

BORDER_WRAP?

cdefgh|abcdefgh|abcdefg

BORDER_REFLECT_101?

gfedcb|abcdefgh|gfedcba(對稱填充,也就是以最邊緣像素為軸)

BORDER_TRANSPARENT?

uvwxyz|absdefgh|ijklmno

BORDER_REFLECT101?

same as BORDER_REFLECT_101

BORDER_DEFAULT?

same as BORDER_REFLECT_101

BORDER_ISOLATED?

do not look outside of ROI

? 第6個參數:const Scalar& borderValue=Scalar():邊界的顏色設置,一般默認是0。 (2)getRotationMatrix2D函數Mat getRotationMatrix2D(Point2f center, double angle, double scale) 參數詳解:Point2f center:表示旋轉的中心點double angle:表示旋轉的角度double scale:圖像縮放因子 例子: int main() {Mat src = imread("D:\\OpencvTest\\test1.jpg");cv::Mat dst;//float scale = 200.0/ src.rows;//縮放因子 //cv::resize(src, src, cv::Size(), scale, scale, cv::INTER_LINEAR); //旋轉角度-20度 double angle = -20;//輸出圖像的尺寸與原圖一樣 cv::Size dst_sz(src.cols, src.rows);//指定旋轉中心 cv::Point2f center(src.cols / 2., src.rows / 2.);//獲取旋轉矩陣(2x3矩陣) cv::Mat rot_mat = cv::getRotationMatrix2D(center, angle, 1.0);//設置選擇背景邊界顏色:綠色 cv::Scalar borderColor = Scalar(0, 238, 0);cv::warpAffine(src, dst, rot_mat, src.size(), INTER_LINEAR, BORDER_CONSTANT, borderColor); //cv::warpAffine(src, dst, rot_mat, dst_sz, INTER_LINEAR, BORDER_REPLICATE);//顯示旋轉效果 cv::imshow("src image ", src);cv::imshow("Rotation Image", dst);waitKey(0);return 0;return 0; } 運行效果: 改為BORDER_REPLICATE:復制邊緣填充,其效果如下:cv::warpAffine(src, dst, rot_mat, dst_sz, INTER_LINEAR, BORDER_REPLICATE);

【尊重原創,轉載請注明出處】 http://blog.csdn.net/guyuealian/article/details/77993410

總結

以上是生活随笔為你收集整理的OpenCV图像旋转,指定填充背景颜色边界颜色的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。