第一个OpenCV程序

创建日期:2024-06-21
更新日期:2025-01-01
import numpy as np
import cv2
import imutils

rgb_img = cv2.imread('./img/creative_commons_elephant.jpg', cv2.IMREAD_COLOR)
gray_img = cv2.cvtColor(rgb_img, cv2.COLOR_RGB2GRAY)
reverse_img = 255 - gray_img
random_img = np.zeros((gray_img.shape[0], gray_img.shape[1]), dtype=np.uint8)

for i in range(gray_img.shape[0]):
    for j in range(gray_img.shape[1]):
        random_img[i, j] = gray_img[i, j]*1.2

cv2.imshow('reverse_img', imutils.resize(reverse_img, 800))
cv2.imshow('random_img', imutils.resize(random_img, 800))

if cv2.waitKey(0) == 27:
    cv2.destroyAllWindows()