#include <iostream> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/opencv.hpp> using namespace std; using namespace cv; Mat src1, src2, gray_src, dst; int main() { src1 = imread("/Users/apple/Desktop/test.jpg", IMREAD_COLOR); //src2 = imread("/Users/apple/Desktop/test2.jpg", IMREAD_COLOR); if (src1.empty()) { // if (!src.data()) cout << "could not load image..." << endl; return -1; } // imshow("input", src1); // waitKey(0); // zoom // the first method Mat s = (Mat_<float>(2, 3) << 0.5, 0, 0, 0, 0.5, 0); Mat dst1; warpAffine(src1, dst1, s, src1.size()); // The second method Mat dst2; resize(src1, dst2, Size(src1.cols / 2, src1.rows / 2), 0.5, 0.5); // Equivalent to the next two // resize(src1, dst2, Size(), 0.5, 0.5); // resize(src1, dst2, src.size(), 0.5, 0.5); // show imshow("src", src1); imshow("warpHffine", dst1); imshow("resize", dst2); waitKey(0); // pan s = (Mat_<float>(2, 3) << 1, 0, 100, 0, 1, 100); warpAffine(dst1, dst1, s, src1.size()); imshow("warpHffine", dst1); waitKey(0); //rotate // clockwise // [ cos(a) -sin(a) 0] // [ sin(a) cos(a) 0] // counterclockwise // [ cos(a) sin(a) 0] // [-sin(a) cos(a) 0] // This function only rotates 90 and 180 degrees // rotate(dst1, dst1, ROTATE_90_COUNTERCLOCKWISE); // imshow("warpHffine", dst1); // waitKey(0); // for any angle // Note that the angle parameter is the counterclockwise rotation angle Mat tem = getRotationMatrix2D(Point2f(dst1.cols / 2, dst1.rows / 2), 30, 1); warpAffine(dst1, dst1, tem, dst1.size()); imshow("warpHffine", dst1); waitKey(0); return 0; }
OpenCV geometric transformation (1)
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=325620023&siteId=291194637
Recommended
Ranking