본문 바로가기
OpenCV

[OpenCV] bitwise.py: BITWISE Operations

by Lizardee 2024. 4. 11.

import cv2 as cv
import numpy as np

# Blank 
blank = np.zeros((400,400), dtype='uint8')

# Rectangle, Circle
rectangle = cv.rectangle(blank.copy(), (30,30), (370,370), 255, -1)
circle = cv.circle(blank.copy(), (200,200), 200, 255, -1)
cv.imshow('Rectangle', rectangle)
cv.imshow('Circle', circle)


# Bitwise Operations
# 1. Bitwise AND
bitwise_and = cv.bitwise_and(rectangle, circle)
cv.imshow('Bitwise AND', bitwise_and)

# 2. Bitwise OR
bitwise_or = cv.bitwise_or(rectangle, circle)
cv.imshow('Bitwise OR', bitwise_or)

# 3. Bitwise XOR
bitwise_xor = cv.bitwise_xor(rectangle, circle)
cv.imshow('Bitwise XOR', bitwise_xor)

# 4. Bitwise NOT
bitwise_not = cv.bitwise_not(rectangle)
cv.imshow('Bitwise NOT', bitwise_not)


cv.waitKey(0)

'OpenCV' 카테고리의 다른 글

[OpenCV] smoothing.py: Blurring Techniques  (0) 2024.04.11
[OpenCV] splitmerge.py: Color Channels  (0) 2024.04.10
[OpenCV] contours.py  (0) 2024.04.10
[OpenCV] transformations.py  (0) 2024.04.10
[OpenCV] basic.py  (0) 2024.04.10