In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the "OpenCV image rotation Rotate method" related knowledge, editor through the actual case to show you the operation process, the operation method is simple and fast, practical, I hope that this "OpenCV image rotation Rotate method" article can help you solve the problem.
Function / / Image rotation void Rotate (const cv::Mat & srcImage, cv::Mat & dstImage, double angle, cv::Point2f center, double scale) {cv::Mat M = cv::getRotationMatrix2D (center, angle, scale); / / calculate the rotation affine transformation matrix cv::warpAffine (srcImage, dstImage, M, cv::Size (srcImage.cols, srcImage.rows)); / / Affine transformation} getRotationMatrix2D function prototype
GetRotationMatrix2D is used to obtain the affine transformation matrix of rotation.
Mat getRotationMatrix2D (Point2f center, double angle, double scale); getRotationMatrix2D parameter description
Center of type Point2f, center of rotation.
Double type angle, the angle of rotation counterclockwise.
Scale of type double, the size scale of the image after rotation.
WarpAffine function prototype
WarpAffine is used for affine transformations.
Void warpAffine (InputArray src, OutputArray dst, InputArray M, Size dsize, int flags = INTER_LINEAR, int borderMode = BORDER_CONSTANT, const Scalar& borderValue = Scalar ()); warpAffine parameter description
Src of type InputArray, enter the image.
Dst of type OutputArray to output the image.
M of InputArray type, affine transformation matrix.
Dsize of type Size, the size of the output image.
Flags of int type, interpolation method.
BorderMode of type int, boundary filling method.
BorderValue of type const Scalar&, boundary filled with numeric values.
C++ test code # include # include using namespace std;using namespace cv;// image rotation void Rotate (const cv::Mat & srcImage, cv::Mat & dstImage, double angle, cv::Point2f center, double scale) {cv::Mat M = cv::getRotationMatrix2D (center, angle, scale); / / calculate the rotation affine transformation matrix cv::warpAffine (srcImage, dstImage, M, cv::Size (srcImage.cols, srcImage.rows)) / / Affine transformation} int main () {/ / load image cv::Mat src = imread ("0.jpg"); cv::Mat dst; / / definition parameter int row = src.rows; int col = src.cols; double angle = 30; cv::Point2f center (col / 2, row / 2); double scale = 0.5 / Image rotation Rotate (src, dst, angle, center, scale); / display image imshow ("src", src); imshow ("result", dst); waitKey (0); system ("pause"); return 0;} Test effect
Original picture
Fig. 2 rotated 30 °
Fig. 3 the original image size is rotated 45
It is not difficult to see that the size of the original image after rotation can no longer meet the requirements of the image. At this time, the scale can be reduced, or the size of the whole picture can be expanded to make it completely covered.
This is the end of the introduction about "the method of rotating OpenCV image Rotate". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.