Python Image Rotation and Resizing using OpenCV and Matplotlib
This code appears to be using OpenCV and Matplotlib libraries to perform image rotation and resizing. Here's a breakdown of what it does:
-
img = plt.imread(self.path): Reads an image file specified byself.pathusingplt.imreadfunction from Matplotlib and assigns it to the variableimg. -
width, height = img.shape[1], img.shape[0]: Retrieves the width and height of the image using theshapeattribute of theimgarray. -
rotate_center = (width // 2, height // 2): Calculates the center point of the image by dividing the width and height by 2. -
rot_mat_30 = cv2.getRotationMatrix2D(rotate_center, angle=60, scale=1): Generates a 2D rotation matrixrot_mat_30using thecv2.getRotationMatrix2Dfunction from OpenCV. This matrix represents a rotation of 60 degrees around the center point. -
img_rot_mat_30 = cv2.warpAffine(img, rot_mat_30, (width, height)): Applies the rotation matrixrot_mat_30to the image using thecv2.warpAffinefunction. This results in a rotated image stored in the variableimg_rot_mat_30. -
size3 = (int(1.0 * img.shape[1]), int(1.0 * img.shape[0])): Calculates the new size of the image by multiplying the width and height by 1.0 and converting the result to integers. -
img_05 = cv2.resize(img, size3): Resizes the image to the new size using thecv2.resizefunction from OpenCV. The resized image is stored in the variableimg_05. -
plt.subplot(1, 1, 1), plt.imshow(img_rot_mat_30), plt.title('60ᄚ'): Sets up a subplot with a single plot. Displays the rotated imageimg_rot_mat_30usingplt.imshowfunction from Matplotlib. Adds a title to the plot indicating the rotation angle. -
plt.show(): Displays the plot with the rotated image. -
self.root.mainloop(): Executes the main event loop of the tkinter application. This assumes thatself.rootis an instance of the tkinterTkclass.
原文地址: https://www.cveoy.top/t/topic/pFVG 著作权归作者所有。请勿转载和采集!