#Numpy数组操作,www.numpy.org,目标:1.遍历数组中的每个像素点2.修改数组中像素点的值3.data\dtype\size\shape\len
import cv2 as cv
import numpy as np
#图片像素反转
def access_pixel(image):
print(image.shape)
height=image.shape[0]
width=image.shape[1]
channels=image.shape[2]
print("height=%s, width=%s, channels=%s"%(height,width,channels))
for row in range( height):
for col in range(width):
for c in range(channels):
#遍历像素点
pv=image[row,col,c]
#修改像素点
image[row,col,c]=255-pv
cv.imshow("pixels_demo",image)
#调用API
def inverse(image):
dst=cv.bitwise_not(image)
cv.imshow("inverse image",dst)
def create_image():
#3通道
#img=np.zeros([400,400,3],np.uint8)
#1通道
#img[:,:,0]=np.ones([400,400])*255
#cv.imshow("new image",img)
#单通道
img=np.zeros([400,400,1],np.uint8)
img[:,:,0]=np.ones([400,400])*255
#读取图片
src=cv.imread("C:\\Users\Administrator\Pictures\grev.jpg")
cv.namedWindow("输出图片",cv.WINDOW_AUTOSIZE)
#显示图片
cv.imshow("输出图片",src)
t1=cv.getTickCount()
#access_pixel(src)
#create_image()
inverse(src)
t2=cv.getTickCount()
time=(t2-t1)/cv.getTickFrequency()
print("time:%s"%(time*1000))
cv.waitKey(0)
cv.destroyAllWindows()
#注:本学习内容来自Python3 Opencv3图像处理教程———贾志刚