我正在尝试裁剪图像并将其打印到matplotlib.pyplot中,但显示了一个错误
import matplotlib.pyplot as plt
import numpy as np
import cv2
image = cv2.imread("tt.jpg")
type(image)
print(image.shape)
W = 100
H = 100
def crop_center(img , cropx , cropy):
y,x,c = image.shape
startx = x//2-(cropx//2)
starty = y//2-(cropy//2)
return img[starty:starty+cropy , startx:startx+cropx]
croped = crop_center(image,W,H)
print(croped)
print(plt.imshow(croped, cmap='gray'))
plt.show() # with scaled size
**错误:**
Traceback (most recent call last):
File "openimage.py", line 96, in <module>
croped = crop_center(scaled,W,H)
File "openimage.py", line 92, in crop_center
y,x,c = image.shape
ValueError: not enough values to unpack (expected 3, got 2)
目前没有回答
相关问题 更多 >
编程相关推荐