2023-10-10 python-opencv-读取png图片像素数据-记录

摘要:

2023-10-10 python-opencv-读取png图片像素数据-记录

安装opencv

python3 -m pip install opencv-python

读取像素点:

import cv2
 
imagess = cv2.imread(r'example-0.png',-1)
 
# print(imagess.shape)
 
# print(imagess)
print(len(imagess))
print(len(imagess[0]))
 
# print(imagess[0][0])
 
high=len(imagess)
length=len(imagess[0])
 
print (high)
print (length)
 
num_line=0
for line in imagess:
    num_column=0
    for px in line:
        # px[0]=px[0]-1
        print(px[0], px[1], px[2], end=' | ')
        num_column=num_column+1
 
        if num_column > 5:
            break
 
    print("\n")
    num_line=num_line+1
    if num_line > 2:
        break   

结果:

201 196 198 | 168 163 165 | 155 150 152 | 1

你可能感兴趣的:(python,python,opencv,开发语言)