使用rotate函数 旋转图片
rotate(src,dst, ROTATE_90_CLOCKWISE);
使用rotate 旋转图片,src是源图片的mat,dts是目标图片的mat,第3个参数是旋转的角度,有以下4个选项:
ROTATE_90_CLOCKWISE = 0, //!<Rotate 90 degrees clockwise
/ROTATE_180 = 1, //!<Rotate 180 degrees clockwise
ROTATE_90_COUNTERCLOCKWISE = 2, //Rotate 270 degrees clockwise
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/videodev2.h>
#include <string.h>
#include <sys/mman.h>
#include <assert.h>
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
using namespace std;
using namespace cv;
// ROTATE_90_CLOCKWISE = 0, //!<Rotate 90 degrees clockwise
// ROTATE_180 = 1, //!<Rotate 180 degrees clockwise
// ROTATE_90_COUNTERCLOCKWISE = 2, /
int main() {
Mat img = imread("in.jpg", IMREAD_UNCHANGED);
rotate(img,img2, ROTATE_90_CLOCKWISE);
imwrite("out.jpg", img2);
return 0;
}