import cv2
labels_path = "test/labels/"
labels2_path = "test/labels2/"
for image in os.listdir(labels_path):
#print(image)
index, _ = os.path.splitext(image)
print(index)
image_file = os.path.join(labels_path, image)
img = cv2.imread(image_file).astype(np.float32)
#img2 = np.array(img);
#print(img2)
save_img = np.zeros((256, 256), dtype=np.uint16)
for i in range(256):
for j in range(256):
#save_img[i][j] = int(img[i][j] / 100.0) #img2
print(img[i][j])
cv2.imwrite(os.path.join(labels_path, index+".png"), save_img)
cv2.imread()读取图片后已多维数组的形式保存图片信息,前两维表示图片的像素坐标,最后一维表示图片的通道索引,具体图像的通道数由图片的格式来决定:https://blog.csdn.net/lccrun/article/details/95594268
cv2.imwrite():https://www.cnblogs.com/shizhengwen/p/8719062.html
TypeError系列之:TypeError: only size-1 arrays can be converted to Python scalars
维数
三大用于数据科学的顶级Python库:https://www.sohu.com/a/254597312_100159565 NumPy、Pandas、MatPlot
cv2读取的mat如何转为numpy的数组呢?opencv和Numpy如何互相数据转换:数据结构上有何相同和不同之处 https://www.cnblogs.com/ansang/p/8137114.html
如何进行像素操作:读取和赋值 x,y=pixel
https://www.matools.com/blog/190496442
https://baijiahao.baidu.com/s?id=1645986288459279361&wfr=spider&for=pc