본문 바로가기
수업(국비지원)/Python

[Python] 2022-12-28 복습

by byeolsub 2023. 4. 27.

 📌

# bitwise 함수 : 2개의 이미지 호출하기 
import numpy as np, cv2
image1 = np.zeros((300, 300), np.uint8) # 300행, 300열 검은색 영상 생성
image2 = image1.copy()
image1.shape
cv2.imshow("image1", image1)
cv2.imshow("image2", image2)

h, w = image1.shape[:2] # 300, 300
print(h, w)
cx, cy = w//2, h//2
print(cx, cy)
# 원을 표시.
# (cx, cy) : 원의 중심 좌표
# 100 : 반지름
# 255 : 색상값
cv2.circle(image1, (cx, cy), 100, 255, -1) # 중심에 원 그리기
# 사각형 표시
# (0, 0, cx, h) : (시작 x좌표, 시작 y좌표, w, h)
# 255 : 색상값
cv2.rectangle(image2, (0, 0, cx, h), 255, -1)
# 두개의 이미지 합하기
image3 = cv2.bitwise_or(image1, image2) # 원소 간 논리합
image4 = cv2.bitwise_and(image1, image2) # 원소 간 논리곱
image5 = cv2.bitwise_xor(image1, image2) # 원소 간 배타적 논리합
image6 = cv2.bitwise_not(image1) # 행렬 반전

cv2.imshow("bitwise_or", image3)
cv2.imshow("bitwise_and", image4)
cv2.imshow("bitwise_xor", image5)
cv2.imshow("bitwise_not", image6)
cv2.waitKey(0)