Add code examples of thresholding images
This commit is contained in:
parent
cf5e5fbd33
commit
c6aedc5cec
2 changed files with 32 additions and 0 deletions
18
examples/adaptive-threshold.py
Normal file
18
examples/adaptive-threshold.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
import cv2
|
||||
import numpy
|
||||
|
||||
cap = cv2.VideoCapture(2)
|
||||
|
||||
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
|
||||
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
|
||||
|
||||
while True:
|
||||
_, frame = cap.read()
|
||||
grey = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
||||
t1 = cv2.adaptiveThreshold(grey, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY_INV, 3, 7)
|
||||
t2 = cv2.adaptiveThreshold(grey, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY_INV, 13, 7)
|
||||
t3 = cv2.adaptiveThreshold(grey, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY_INV, 23, 7)
|
||||
|
||||
threshed = numpy.concatenate((t1, t2, t3), axis=1)
|
||||
cv2.imshow('threshed', threshed)
|
||||
cv2.waitKey(1)
|
14
examples/threshold.py
Normal file
14
examples/threshold.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
import cv2
|
||||
|
||||
cap = cv2.VideoCapture(2)
|
||||
|
||||
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
|
||||
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
|
||||
|
||||
while True:
|
||||
_, frame = cap.read()
|
||||
grey = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
||||
_, thresh = cv2.threshold(grey, 127, 255, cv2.THRESH_BINARY)
|
||||
cv2.imshow('original', frame)
|
||||
cv2.imshow('thresh', thresh)
|
||||
cv2.waitKey(1)
|
Loading…
Reference in a new issue