1. 图像属性
def access_pixels(img):
print(img.shape)
height = img.shape[0] #高度
width = img.shape[1] #宽度
channels= img.shape[2] #blue green red 几通道
print ("width: %s, height: %s, channels: %s"%(width, height, channels))
for row in range(height): # 图像反转
for col in range(width):
for c in range(channels):
pv = img[row, col, c] #save img
img[row, col, c] = 255 - pv # 修改好数值保存到原来图片中
cv.imshow("pixels_demo", img)
def inverse(img): # opencv API 图像发转
dst = cv.bitwise_not(img)
cv.imshow("inverse demo", dst)
2.查看用时
t1 = cv.getTickCount()
access_pixels(src)
t2 = cv.getTickCount()
time = ((t2-t1)/cv.getTickFrequency())
print ("time :%ms"%time*1000)
查看使用了多少时间 *1000之后是ms
3.通道分离 与 合并
三通道进行分离
b,g,r = cv.split(src)
cv.imshow("blue", b)
cv.imshow("green", g)
cv.imshow("red", r)
srv[:,:,2] = 0
最后一个通道赋值0
合并
srv = cv.merge([b,g,r])