[참고]
- [10편] 이미지 Thresholding (옥수별님 블로그) : https://blog.naver.com/PostView.nhn?blogId=samsjang&logNo=220504782549&proxyReferer=https%3A%2F%2Fwww.google.com%2F
- 영상분할 Otsu Thresholding (건깡님 티스토리) : https://j07051.tistory.com/364
1. USB 카메라 영상(컬러)
#UBS 카메라 실시간 영상 스트리밍
#Windows10, PC 사용
import numpy as np
import cv2
img = cv2.VideoCapture(0)
while True:
ret, frame = img.read()
k = cv2.waitKey(3) & 0xFF
if k == 27:
break
cv2.imshow('frame', frame)
img.release()
cv2.destroyAllWindows()
2. USB 카메라 영상(흑백)
import numpy as np
import cv2
img = cv2.VideoCapture(0)
while True:
ret, frame = img.read()
gray_img = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
k = cv2.waitKey(3) & 0xFF
if k == 27:
break
# cv2.imshow('frame', frame)
cv2.imshow('gray_img', gray_img)
img.release()
cv2.destroyAllWindows()
3. THRESHOLD
import numpy as np
import cv2
img = cv2.VideoCapture(0)
while True:
ret, frame = img.read()
gray_img = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
ret, thr1 = cv2.threshold(gray_img, 127, 255, cv2.THRESH_BINARY)
ret, thr2 = cv2.threshold(gray_img, 127, 255, cv2.THRESH_BINARY_INV)
ret, thr3 = cv2.threshold(gray_img, 127, 255, cv2.THRESH_TRUNC)
ret, thr4 = cv2.threshold(gray_img, 127, 255, cv2.THRESH_TOZERO)
ret, thr5 = cv2.threshold(gray_img, 127, 255, cv2.THRESH_TOZERO_INV)
k = cv2.waitKey(3) & 0xFF
if k == 27:
break
# cv2.imshow('frame', frame)
cv2.imshow('gray_img', gray_img)
cv2.imshow('BINARY', thr1)
cv2.imshow('BINARY_INV', thr2)
cv2.imshow('TRUNC', thr3)
cv2.imshow('TOZERO', thr4)
cv2.imshow('TOZERO_INV', thr5)
img.release()
cv2.destroyAllWindows()
[결과]
'#openCV # 파이썬' 카테고리의 다른 글
#OpenCV4 관련 서적 #파이썬3 (0) | 2021.02.14 |
---|---|
#Otsu 알고리즘을 사용 #python (0) | 2019.05.03 |
#dlib 설치 #python3.6 (0) | 2019.05.02 |
#openCV #python #카메라 autofocus 기능 끄기 (0) | 2019.04.29 |
#openCV #원검출 #cv2.HoughCircles() (0) | 2019.04.04 |