In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to keep the rotation of image content in opencv". In daily operation, I believe many people have doubts about how to keep the rotation of image content in opencv. The editor consulted all kinds of data and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the question of "how to keep the rotation of image content in opencv". Next, please follow the editor to study!
In opencv, to rotate an image, simply call the following code:
M = cv2.getRotationMatrix2D ((width//2, height//2), 45,1) image_new = cv2.warpAffine (image, M, (width, height))
But this call will lose the image content, as follows: cdn.nlark.com/yuque/0/2020/png/1445121/1599750201721-e1633576-dcb6-45a7-8550-da35510ff367.png ">
But many times we want the image to remain intact after rotation:
Here is a solution:
Def rotate_keep (degree, width, height): "" rotation of lossless images @ param degree: @ param width: @ param height: @ return: rotation matrix New width and height "" height_new = int (width * fabs (sin (radians (degree) + height * fabs (cos (radians (degree) width_new = int (height * fabs (sin (radians (degree) + width * fabs (cos (radians (degree) mat_rotation = cv2.getRotationMatrix2D ((width / 2, height / 2), degree, 1) mat_rotation [0,2] + = (width_new-width) / 2 mat_rotation [1 2] + = (height_new-height) / 2 return mat_rotation, width_new, height_newangle = 45height, width = image.shape [0:2] M, width_new, height_new = rotate_keep (45, width, height) image_new = cv2.warpAffine (image, M, (width_new, height_new))
The code divides the whole process into three steps
Rotate the picture first
Calculate the theoretical image size after rotation
Translate the image so that the coordinates are negative and the coordinates are positive
At this point, the study on "how to keep the rotation of image content in opencv" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.