用opencv旋转Python图像

2024-09-26 18:06:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在从事这个开放式cv python项目。我能够加载图像,绘制RGB,并将图像更改为灰度。但是,一旦我尝试旋转图像,终端中就不会弹出任何内容。你知道我做错了什么吗

import cv2 
import matplotlib.pyplot as plt

##### loading the image 

coffeeImage = cv2.imread("coffee.jpeg")
blue, green, red = cv2.split(coffeeImage)

img_matplotlib = cv2.merge([red, green, blue])

#####  plotting RGB image

plt.subplot(122)
plt.title("RGB")
plt.imshow(img_matplotlib)
plt.show()

#### Changing image to grey-scale

grayImage = cv2.cvtColor(coffeeImage,cv2.COLOR_BGR2GRAY)

cv2.imshow('grey-scale',grayImage)
cv2.waitKey(0)
cv2.destroyAllWindows()

#### rotate the image 



(h, w) = grayImage.shape[:2]
center = (w / 2, h / 2)
 
angle90 = 90
scale = 1.0

rotatedImage = cv2.getRotationMatrix2D(center, angle90, scale)
rotated90 = cv2.warpAffine(grayImage, rotatedImage, (h, w))

cv2.imshow('Rotated Image', rotated90)
cv2.waitKey(0)

谢谢


Tags: the图像imageimportmatplotlibpltgreenblue

热门问题