CodeLibrary/03_pycharm_python_coursework_20240427/opencv_03.py
JRNitre 2092240e04 计算机专业前沿作业 Python
Date: 20240427
Design by JRNitre
2024-04-27 20:40:24 +08:00

22 lines
577 B
Python

import cv2
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
img_1 = cv2.imread('source/data_03.jpg')
cv2.imshow("img1", img_1)
img_2 = np.zeros(img_1.shape, dtype=np.uint8)
img_2[200:400, 200:400] = 255
cv2.imshow("img2", img_2)
result_or = cv2.bitwise_or(img_1, img_2)
result_and = cv2.bitwise_and(img_1, img_2)
result_not = cv2.bitwise_not(img_1, img_2)
result_xor = cv2.bitwise_xor(img_1, img_2)
cv2.imshow("or", result_or)
cv2.imshow("and", result_and)
cv2.imshow("not", result_not)
cv2.imshow("xor", result_xor)
cv2.waitKey()
cv2.destroyWindow()