OpenCV:重映射remap vs仿射变换warpAffine( 三 )


       warpAffine(src, dst_warp, M1, src.size());//仿射变换 
       //第二种仿射变换的挪用体例:直接指定角度和比例                                         
【OpenCV:重映射remap vs仿射变换warpAffine】       //扭转加缩放 
       Point2f center(src.cols/2, src.rows/2);//扭转中间 
       double angle = 45;//逆时针扭转45度 
       double scale = 0.5;//缩放比例 
       Mat M2 = getRotationMatrix2D(center, angle, scale);//计较扭转加缩放的变换矩阵 
       warpAffine(dst_warp, dst_warpRotateScale, M2, src.size());//仿射变换 
       imshow("原始图", src);
       imshow("仿射变换1", dst_warp);
       imshow("仿射变换2", dst_warpRotateScale);
       waitKey(0);
       return 0;
}
【注】:
有没有发现图片进行仿射变换后的布景被填充为黑色了?
其实这个布景色是可以调的 , 像如许:
warpAffine(dst_warp, dst_warpRotateScale, M2, src.size(), 1, 0, Scalar(11,111, 211));
//操纵Scalar来填充分歧颜色布景

OpenCV:重映射remap vs仿射变换warpAffine

文章插图

6法式2
#include <opencv2\opencv.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\features2d\features2d.hpp>
#include <opencv2\core\core.hpp>
using namespace std; 
using namespace cv; 
//仿射变换尝试
#define PIC_BEGIN_NUM 100  //这里界说你的肇端图片编号
#define ANGLE_START -45  //扭转角度的起头
#define ANGLE_  0  //扭转角度的竣事
#define ANGLE_STEP 2 //扭转角度步长
int main(int argc, char **argv)
{
       const char* filename = "0.jpg";
       Mat srcImg = imread(filename, 1);
       imshow("source", srcImg);
       Point center(srcImg.cols / 2, srcImg.rows / 2); //图片中间为扭转点
       char file[20];
       int count = PIC_BEGIN_NUM;
       Mat tpimg;
       for (int tp = ANGLE_START; tp < ANGLE_; tp += ANGLE_STEP)
       {
              Mat rotMatS = getRotationMatrix2D(center, tp, 0.5); //图片缩小到本来的0.5倍
              warpAffine(srcImg, tpimg, rotMatS, srcImg.size(), 1, 0, Scalar(0, 0, 0));//填充黑色布景                                                                          

推荐阅读