1 __author__ = "WSX" 2 import cv2 as cv 3 import numpy as np 4 5 image = cv.imread("1.JPG") #获取图 6 7 image_height = image.shape[0] 8 image_width = image.shape[1] 9 image_channel = image.shape[2] 10 11 # for i in range(image_height): #访问 每一个像素 12 # for j in range(image_width): 13 # for k in range(image_channel): 14 # temp = image[i , j , k] 15 # image[i , j , k] = 255 - temp 16 17 New_image = cv.bitwise_not(image) #像素取反,速度很快(依靠c代码) 18 19 20 cv.namedWindow("New_image" , cv.WINDOW_AUTOSIZE) 21 cv.imshow("New_image" , New_image) 22 cv.waitKey(0)