OpenCV图像旋转,指定填充背景颜色边界颜色
来源:互联网 发布:百度一下淘宝男裤 编辑:程序博客网 时间:2024/06/08 04:09
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 .M
2×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 (dst→src ).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(即指定常数值填充) ,实质上,边界处理类型,该枚举型还有:
iiiiii|abcdefgh|iiiiiii
with some specified i(指定常数填充)
aaaaaa|abcdefgh|hhhhhhh(复制边缘像素填充)
fedcba|abcdefgh|hgfedcb(反射复制边界像素)
cdefgh|abcdefgh|abcdefg
gfedcb|abcdefgh|gfedcba(对称填充,也就是以最边缘像素为轴)
uvwxyz|absdefgh|ijklmno
same as BORDER_REFLECT_101
BORDER_DEFAULTsame as BORDER_REFLECT_101
BORDER_ISOLATEDdo 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
阅读全文
0 0
- OpenCV图像旋转,指定填充背景颜色边界颜色
- OpenCV图像剪切,超出图像区域指定颜色填充
- 图像边界填充OpenCV
- opencv图像边界的填充
- Matlab图像剪切,超出图像区域指定颜色填充
- HTML图像、背景、颜色
- CSS:背景颜色/背景图像
- opencv-图像添加边界(填充)
- opencv图像处理之轮廓外背景颜色改变
- 【OPENCV】图像颜色转换
- OpenCV-009:识别摄像头图像中的指定颜色并显示
- 改变背景图像或颜色
- html 图像、背景和颜色
- 用指定颜色填充一个闭合区域
- 用指定颜色填充一个连接域
- 指定区域内图像颜色反转
- iOS开发:图像处理-颜色填充模式
- OpenCV提取图像颜色直方图
- Eclipse开发快捷键技巧
- linux进程通信之消息队列
- Zookeeper的基本概念和基础使用
- 【英语句式】写论文中值得参考的语法、句式
- socket can error write: No buffer space available
- OpenCV图像旋转,指定填充背景颜色边界颜色
- Unity广播快速学习
- impdp 报错 ora-31640
- 《jQuery技术内幕》
- echarts3改动
- Python网络爬虫与信息提取-Day12-Re(正则表达式)库入门
- jsp错误
- C语言怎样提取一个数的十位个位百位千位
- 安装、配置和测试Asterisk过程中遇到的问题及解决方法