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