π λ³Έ μμ λ Window10μ VSCode, Python3.11.0λ‘ μμ±λμμ΅λλ€.
μ»¬λ¬ μμμ κΈ°λ³Έμ μΌλ‘ RGB μ¦, λΉ¨κ°μ(Red), λ Ήμ(Green), νλμ(Blue) μμ μ±λΆμ μ‘°ν©μΌλ‘ ν½μ κ°μ νν νλ€.
κ·Έλ¬λ OpenCVμμλ RGB λμ BGR μμ μμλ‘ ν½μ κ°μ νννλ€.
κ° μμ μ±λΆμ 0 ~ 255 μ¬μ΄μ κ°μ κ°μ§ μ μλ€.
OpenCVλ‘ μμμ μ½μΌλ©΄ Numpy λ°°μ΄λ‘ μ½μ΄μ§κΈ° λλ¬Έμ, κ° ν½μ μ κ°μ μ°Έμ‘°ν μ μλ€.
μ΄λ₯Ό ν΅ν΄ μμμ μμμ λ³κ²½ν μλ μλ€.
import cv2
if __name__ == "__main__":
img = cv2.imread("test.png",cv2.IMREAD_COLOR)
img = cv2.resize(img,(512,600),interpolation=cv2.INTER_LANCZOS4)
cv2.imshow("Origin",img)
cv2.imshow("Reversed",~img) # λ°μ
cv2.waitKey(0)
cv2.destroyAllWindows()
μμ 곡κ°μλ RGBλ₯Ό μ μΈνλλΌλ μ¬λ¬κ°μ§ μμ 곡κ°μ΄ μλ€.
OpenCVλ cvtColor ν¨μλ₯Ό ν΅ν΄ μμ 곡κ°μ λ³κ²½ν μ μλ€.
import cv2
if __name__ == "__main__":
img = cv2.imread("test.png",cv2.IMREAD_COLOR)
img = cv2.resize(img,(512,600),interpolation=cv2.INTER_LANCZOS4)
cv2.imshow("Origin",img)
cv2.imshow("RGB",cv2.cvtColor(img,cv2.COLOR_BGR2RGB))
cv2.imshow("Gray",cv2.cvtColor(img,cv2.COLOR_BGR2GRAY))
cv2.waitKey(0)
cv2.destroyAllWindows()
κ° μ±λμ λΆλ¦¬νλ λ°©λ²μ΄ μλ€,.
Split ν¨μλ₯Ό μ°λ©΄ κ° μ±λμ Numpy λ°°μ΄μ μ»μ μ μλ€.
import cv2
if __name__ == "__main__":
img = cv2.imread("test.png",cv2.IMREAD_COLOR)
img = cv2.resize(img,(512,600),interpolation=cv2.INTER_LANCZOS4)
cv2.imshow("Origin",img)
b,g,r = cv2.split(img)
cv2.imshow("Blue",b)
cv2.imshow("Green",g)
cv2.imshow("Red",r)
me = cv2.merge([b,g,r])
cv2.imshow("Merged",me)
cv2.waitKey(0)
cv2.destroyAllWindows()
νμ€ν κ·Έλ¨ νννλ₯Ό ν΅ν΄ μμμ μλ³Έ μκ°μ μ μ§νλ©΄μ λͺ μλΉλ₯Ό λν μ μλ€.
import cv2
if __name__ == "__main__":
img = cv2.imread("test.png",cv2.IMREAD_COLOR)
img = cv2.resize(img,(512,600),interpolation=cv2.INTER_LANCZOS4)
cv2.imshow("Origin",img)
b,g,r = cv2.split(img)
b_h = cv2.equalizeHist(b)
g_h = cv2.equalizeHist(g)
r_h = cv2.equalizeHist(r)
eh_img = cv2.merge([b_h,g_h,r_h])
cv2.imshow("Histogram Equalized Image",eh_img)
cv2.waitKey(0)
cv2.destroyAllWindows()
μμ λ²μ μ§μ μ μν μμ λΆν λ ν μ μλ€.
inRangeλ₯Ό μ¬μ©νλ©΄ νΉμ μμ μμμ μΆμΆν μ μλ€.
import cv2
import numpy as np
if __name__ == "__main__":
img = cv2.imread("test.png",cv2.IMREAD_COLOR)
img = cv2.resize(img,(512,600),interpolation=cv2.INTER_LANCZOS4)
img_hsv = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
cv2.imshow("Origin",img)
# λΉ¨κ°μ λ²μ μ€μ (HSV)
lower_red = np.array([0, 100, 100]) # ννκ°
upper_red = np.array([10, 255, 255]) # μνκ°
mask = cv2.inRange(img_hsv, lower_red, upper_red)
cv2.imshow("Red Masking",cv2.bitwise_and(img,img,mask=mask))
cv2.waitKey(0)
cv2.destroyAllWindows()
'AI > Computer Vision' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[Computer Vision] λ μ΄λΈλ§κ³Ό μΈκ°μ κ²μΆ (0) | 2024.09.04 |
---|---|
[Computer Vision] μμμ μ΄μ§νμ λͺ¨ν΄λ‘μ§ (0) | 2024.09.03 |
[Computer Vision] μμ§(Edge) κ²μΆ (0) | 2024.09.02 |
[Computer Vision] μμμ κΈ°ννμ λ³ν (0) | 2024.08.30 |
[Computer Vision] Filtering (0) | 2024.08.30 |