import cv2 as cv
def get_image_info():
image = cv.imread("./images/butterfly.jpg",0)
print(image.shape)
if __name__ == "__main__":
get_image_info()
import cv2 as cv
def get_image_info():
image = cv.imread("./images/butterfly.jpg")
print(image.shape)
if __name__ == "__main__":
get_image_info()
import cv2 as cv
def get_image_info():
image = cv.imread("./images/butterfly.jpg",0)
print(image[100,100])
if __name__ == "__main__":
get_image_info()
import cv2 as cv
def get_image_info():
image = cv.imread("./images/butterfly.jpg")
print(image[100,100])
if __name__ == "__main__":
get_image_info()
import cv2 as cv
def get_image_info():
image = cv.imread("./images/butterfly.jpg",0)
image[0:100,0:100] = 255
cv.imshow('change 0 - 100:', image)
cv.waitKey(0)
cv.destroyAllWindows()
if __name__ == "__main__":
get_image_info()
import cv2 as cv
def get_image_info():
image = cv.imread("./images/butterfly.jpg")
image[0:100,0:100] = (255,0,0)
cv.imshow('change 0 - 100:', image)
cv.waitKey(0)
cv.destroyAllWindows()
if __name__ == "__main__":
get_image_info()
OpenCV 像素遍历的本质就是numpy数组访问!!!
import cv2 as cv
def visit_pixel_demo():
image = cv.imread("./images/butterfly.jpg")
cv.imshow('original:', image)
h,w,c = image.shape
for row in range(h):
for col in range(w):
b,g,r = image[row,col]
image[row,col] = (255-b,255-g,255-r)
cv.imshow('visited:', image)
cv.waitKey(0)
cv.destroyAllWindows()
if __name__ == "__main__":
visit_pixel_demo()
import cv2 as cv
def visit_pixel_demo():
image = cv.imread("./images/butterfly.jpg",0)
cv.imshow('original', image)
h,w = image.shape
for row in range(h):
for col in range(w):
p_value = image[row,col]
image[row,col] = 255 - p_value
cv.imshow('visited', image)
cv.waitKey(0)
cv.destroyAllWindows()
if __name__ == "__main__":
visit_pixel_demo()