import cv2
import numpy as np
def get_image_info(image):
print(type(image))
print(image.shape)
print(image.size)
print(image.dtype)
pixel_data = np.array(image)
print(pixel_data)
img = cv2.imread(r'test.png') #读取项目文件下的test.png图片到img
new_img = cv2.resize(img, (416, 416), interpolation=cv2.INTER_AREA) #把img读入的图片缩小到416*416并传给new_img
cv2.imshow("cat", new_img) #显示new_img图片,显示窗口为cat
get_image_info(img)
cv2.imwrite(r'testa.png', new_img) #把new_img图片写入项目文件目录下并命名为testa.png
flag = min(img.shape[0], img.shape[1])
new_img2 = img[((img.shape[0]-flag)//2):((img.shape[0]+flag)//2), ((img.shape[1]-flag)//2):((img.shape[1]+flag)//2)]
new_img2 = cv2.resize(new_img2, (416, 416), interpolation=cv2.INTER_AREA)
cv2.imwrite(r'cat.png', new_img)
gray = cv2.cvtColor(new_img2, cv2.COLOR_BGR2GRAY)
cv2.imwrite(r'testb.png', gray)
cv2.waitKey(0)
cv2.destroyAllWindows()