From d9264d0c1fa79c1d470dad1fb626ceefd5915824 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Thu, 12 May 2016 18:45:50 +0200 Subject: [PATCH] add an option to display a live preview of what remains in the image after applying the mask --- bin/range-detector | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bin/range-detector b/bin/range-detector index ae38ec9..6e1b403 100755 --- a/bin/range-detector +++ b/bin/range-detector @@ -34,6 +34,9 @@ def get_arguments(): help='Path to the image') ap.add_argument('-w', '--webcam', required=False, help='Use webcam', action='store_true') + ap.add_argument('-p', '--preview', required=False, + help='Show a preview of the image after applying the mask', + action='store_true') args = vars(ap.parse_args()) if not xor(bool(args['image']), bool(args['webcam'])): @@ -89,8 +92,12 @@ def main(): thresh = cv2.inRange(frame_to_thresh, (v1_min, v2_min, v3_min), (v1_max, v2_max, v3_max)) - cv2.imshow("Original", image) - cv2.imshow("Thresh", thresh) + if args['preview']: + preview = cv2.bitwise_and(image, image, mask=thresh) + cv2.imshow("Preview", preview) + else: + cv2.imshow("Original", image) + cv2.imshow("Thresh", thresh) if cv2.waitKey(1) & 0xFF is ord('q'): break