아이셩짱셩 2018. 8. 7. 21:31
728x90

#원과 박스를 서로 교차할 수 있다.

import numpy as np

import cv2


#박스와 원을 그린다.

rectangle = np.zeros((300, 300), dtype = "uint8")

cv2.rectangle(rectangle, (25, 25), (275, 275), 255, -1)

cv2.imshow("Rectangle", rectangle)


# Secondly, let's draw a circle

circle = np.zeros((300, 300), dtype = "uint8")

cv2.circle(circle, (150, 150), 150, 255, -1)

cv2.imshow("Circle", circle)


# AND로 하면 두 도형의 공통 부분만 나온다.

bitwiseAnd = cv2.bitwise_and(rectangle, circle)

cv2.imshow("AND", bitwiseAnd)

cv2.waitKey(0)


# OR로 하면 두 도형의 전체가 다 나온다.

bitwiseOr = cv2.bitwise_or(rectangle, circle)

cv2.imshow("OR", bitwiseOr)

cv2.waitKey(0)


# XOR은 공통 부분을 제외한 부분만 나온다.

bitwiseXor = cv2.bitwise_xor(rectangle, circle)   

cv2.imshow("XOR", bitwiseXor)

cv2.waitKey(0)


# NOT은 해당 부분에 속하지 않는 부분만 나온다.

bitwiseNot = cv2.bitwise_not(circle)

cv2.imshow("NOT", bitwiseNot)

cv2.waitKey(0)

728x90