OpenCV_图像旋转与缩放
下面这份代码用于实现对图像的缩放与旋转。
OpenCV版本:2.4.2
// 图像旋转与缩放
#include <iostream>
#include <vector>
#include <opencv2/opencv.hpp>
int main(int argc, char** argv)
{
cv::Mat image = cv::imread("../test.jpg");
if (image.empty())
{
std::cout<<"read image failure"<<std::endl;
return -1;
}
cv::Point2f center = cv::Point2f(image.cols / 2, image.rows / 2); // 旋转中心
double angle = 30; // 旋转角度
double scale = 0.5; // 缩放尺度
cv::Mat rotateMat;
rotateMat = cv::getRotationMatrix2D(center, angle, scale);
cv::Mat rotateImg;
cv::warpAffine(image, rotateImg, rotateMat, image.size());
cv::imwrite("../rotate.jpg", rotateImg);
return 0;
}
相关推荐
learningCV 2020-11-10
learningCV 2020-08-25
huang00 2020-08-21
wangdaren 2020-08-15
BeanJoy 2020-07-28
csdmeb 2020-06-25
wangdaren 2020-06-14
pythonxuexi 2020-06-13
woniulx0 2020-06-13
greent00 2020-06-10
liangzuojiayi 2020-06-09
greent00 2020-06-09
csdmeb 2020-06-08
BeanJoy 2020-06-06
lihuifei 2020-06-05
wangdaren 2020-06-03
wangdaren 2020-05-31
greent00 2020-05-30