import cv2     # h, w, c
import numpy
import matplotlib.pyplot as plt

img = cv2.imread("D:/.....jpeg" , 1)
print("图像的形状,返回一个图像的(行数,列数,通道数):", img.shape)
print("图像的像素数目:", img.size)
print("图像的数据类型:", img.dtype)
#img = cv2.resize(img,(280,280))    可以改变图片的大小

fname = open("./xiangsu.txt",'w')
fname.write("图像的形状,返回一个图像的(行数,列数,通道数):"+str(img.shape)+'\n')
fname.write("图像的像素数目:"+str(img.size)+'\n')
fname.write("图像的数据类型:"+str(img.dtype)+'\n')
Xlenth = img.shape[1]          # 图片列数454
Ylenth = img.shape[0]          # 图片行数439

a = 1
for i in range(Ylenth):
    fname.write(str(a) + ':'+'\n')
    for j in range(Xlenth):
        fname.write(str(img[i][j])+' ')
    a += 1
    fname.write('\n')
fname.close()


cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐