opencv处理图像的多种方法
#include<opencv2/opencv.hpp>#include<iostream>
#include<math.h>
using namespace cv;
using namespace std;
int main(int argc, char* argv) {
Mat src, dst;
src = imread("D://opencv//picture//space.jfif");
if (!src.data) {
printf("could not load image...\n");
return -1;
}
namedWindow("original image", CV_WINDOW_AUTOSIZE);
imshow("original image", src);
Mat dst_warp, dst_warpRotateScale, dst_warpTransformation, dst_warpFlip;
Point2f srcPoints;
Point2f dstPoints;
srcPoints = Point2f(0, 0);
srcPoints = Point2f(0, src.rows);
srcPoints = Point2f(src.cols, 0);
dstPoints = Point2f(0, src.rows*0.3);
dstPoints = Point2f(src.cols*0.25, src.rows*0.75);
dstPoints = Point2f(src.cols*0.75, src.rows*0.25);
Mat M1 = getAffineTransform(srcPoints, dstPoints);
warpAffine(src, dst_warp, M1, src.size());
Point2f center(src.cols / 2, src.rows / 2);
double angle = 45;
double scale = 0.5;
Mat M2 = getRotationMatrix2D(center, angle, scale);
warpAffine(src, dst_warpRotateScale, M2, Size(src.cols, src.rows), INTER_LINEAR);
//仿射变换—平移
Point2f srcPoints1;
Point2f dstPoints1;
srcPoints1 = Point2i(0, 0);
srcPoints1 = Point2i(0, src.rows);
srcPoints1 = Point2i(src.cols, 0);
dstPoints1 = Point2i(src.cols / 3, 0);
dstPoints1 = Point2i(src.cols / 3, src.rows);
dstPoints1 = Point2i(src.cols + src.cols / 3, 0);
Mat M3 = getAffineTransform(srcPoints1, dstPoints1);
warpAffine(src, dst_warpTransformation, M3, Size(src.cols + src.cols / 3, src.rows));
Point2f srcPoints2;
Point2f dstPoints2;
srcPoints2 = Point2i(0, 0);
srcPoints2 = Point2i(0, src.rows);
srcPoints2 = Point2i(src.cols, 0);
dstPoints2 = Point2i(src.cols, 0);
dstPoints2 = Point2i(src.cols, src.rows);
dstPoints2 = Point2i(0, 0);
Mat M4 = getAffineTransform(srcPoints2, dstPoints2);
warpAffine(src, dst_warpFlip, M4, Size(src.cols, src.rows));
//flip(src, dst_warpFlip, 1);//flipCode:= 0 图像向下翻转
//> 0 图像向右翻转
//< 0 图像同时向下向右翻转
imshow("affine transformation1(三点法)", dst_warp);
imshow("affine transfoemation2(指定比例和角度)", dst_warpRotateScale);
imshow("affine transfoemation3(仿射变换平移)", dst_warpTransformation);
imshow("affine transformation4(仿射变换镜像)", dst_warpFlip);
waitKey(0);
return 0;
}
页:
[1]