diff --git a/examples/adaptive-threshold.py b/examples/adaptive-threshold.py new file mode 100644 index 0000000..60adaef --- /dev/null +++ b/examples/adaptive-threshold.py @@ -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) diff --git a/examples/threshold.py b/examples/threshold.py new file mode 100644 index 0000000..f362628 --- /dev/null +++ b/examples/threshold.py @@ -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)