python opencv的最基本逻辑 cv2
最基本逻辑就是读取图片,图片是mxn的数组:[
[ pixel11,pixel11.........pixel1m]
[ pixel21,..........
.........
[pixeln1.....................pixelnm]
]
m图片的宽度,n是图片高度,数组里的每个元素是个列表,列表里有三个元素分别是当前元素的RGB值:[R,G,B]
以下程序是一个处理每个像素的小例子
image_path = "08.png" #图片路径 img = cv2.imread(image_path) #cv2.imshow("ori", img) for row in range(len(img)): for colume in range(len(img[row])): if row>140: img[row][colume] = [0, 0, 0] elif img[row][colume][0]>185 and img[row][colume][1]>185 and img[row][colume][2]>185: img[row][colume]=[255,255,255] else: img[row][colume]=[0,0,0]
以上程序实现功能:
1.像素点在宽度140以内的点被置成黑色
2.像素点在宽度140以外的点如果RGB的值都大于185,则被置成白色(RGB值均为255)
3.除了1和2外其他像素点置成黑色(RGB均为0)

浙公网安备 33010602011771号