From 2647902feed03bfffd30d7289048a0ba5acc14b3 Mon Sep 17 00:00:00 2001 From: Suleyman TURKMEN Date: Sat, 22 Jan 2022 11:27:01 +0300 Subject: [PATCH] Update python samples --- .../python/camera_calibration_show_extrinsics.py | 15 ++++++++++++++- samples/python/common.py | 2 +- samples/python/digits.py | 1 + samples/python/digits_video.py | 2 +- samples/python/facedetect.py | 6 +++--- samples/python/qrcode.py | 2 ++ samples/python/text_skewness_correction.py | 10 ++++++---- 7 files changed, 28 insertions(+), 10 deletions(-) diff --git a/samples/python/camera_calibration_show_extrinsics.py b/samples/python/camera_calibration_show_extrinsics.py index d676691f15..0ee2a19b68 100755 --- a/samples/python/camera_calibration_show_extrinsics.py +++ b/samples/python/camera_calibration_show_extrinsics.py @@ -1,5 +1,18 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- + +''' +Plot camera calibration extrinsics. + +usage: + camera_calibration_show_extrinsics.py [--calibration ] [--cam_width] [--cam_height] [--scale_focal] [--patternCentric ] + +default values: + --calibration : left_intrinsics.yml + --cam_width : 0.064/2 + --cam_height : 0.048/2 + --scale_focal : 40 + --patternCentric : True +''' # Python 2/3 compatibility from __future__ import print_function diff --git a/samples/python/common.py b/samples/python/common.py index 85cda62cd4..e7ad478b88 100755 --- a/samples/python/common.py +++ b/samples/python/common.py @@ -222,7 +222,7 @@ def mosaic(w, imgs): pad = np.zeros_like(img0) imgs = it.chain([img0], imgs) rows = grouper(w, imgs, pad) - return np.vstack(map(np.hstack, rows)) + return np.vstack(list(map(np.hstack, rows))) def getsize(img): h, w = img.shape[:2] diff --git a/samples/python/digits.py b/samples/python/digits.py index e5d8ceb59a..25db411f94 100755 --- a/samples/python/digits.py +++ b/samples/python/digits.py @@ -191,3 +191,4 @@ if __name__ == '__main__': model.save('digits_svm.dat') cv.waitKey(0) + cv.destroyAllWindows() diff --git a/samples/python/digits_video.py b/samples/python/digits_video.py index 7b07831643..237e40a9b2 100755 --- a/samples/python/digits_video.py +++ b/samples/python/digits_video.py @@ -29,7 +29,7 @@ def main(): src = sys.argv[1] except: src = 0 - cap = video.create_capture(src) + cap = video.create_capture(src, fallback='synth:bg={}:noise=0.05'.format(cv.samples.findFile('sudoku.png'))) classifier_fn = 'digits_svm.dat' if not os.path.exists(classifier_fn): diff --git a/samples/python/facedetect.py b/samples/python/facedetect.py index 488c92d5e5..248206a7cd 100755 --- a/samples/python/facedetect.py +++ b/samples/python/facedetect.py @@ -39,13 +39,13 @@ def main(): except: video_src = 0 args = dict(args) - cascade_fn = args.get('--cascade', "data/haarcascades/haarcascade_frontalface_alt.xml") - nested_fn = args.get('--nested-cascade', "data/haarcascades/haarcascade_eye.xml") + cascade_fn = args.get('--cascade', "haarcascades/haarcascade_frontalface_alt.xml") + nested_fn = args.get('--nested-cascade', "haarcascades/haarcascade_eye.xml") cascade = cv.CascadeClassifier(cv.samples.findFile(cascade_fn)) nested = cv.CascadeClassifier(cv.samples.findFile(nested_fn)) - cam = create_capture(video_src, fallback='synth:bg={}:noise=0.05'.format(cv.samples.findFile('samples/data/lena.jpg'))) + cam = create_capture(video_src, fallback='synth:bg={}:noise=0.05'.format(cv.samples.findFile('lena.jpg'))) while True: _ret, img = cam.read() diff --git a/samples/python/qrcode.py b/samples/python/qrcode.py index b3253f96c6..21b1a59073 100644 --- a/samples/python/qrcode.py +++ b/samples/python/qrcode.py @@ -245,4 +245,6 @@ def main(): if __name__ == '__main__': + print(__doc__) main() + cv.destroyAllWindows() diff --git a/samples/python/text_skewness_correction.py b/samples/python/text_skewness_correction.py index c8ee33b39d..c3e97a333b 100644 --- a/samples/python/text_skewness_correction.py +++ b/samples/python/text_skewness_correction.py @@ -15,7 +15,7 @@ import argparse def main(): parser = argparse.ArgumentParser() - parser.add_argument("-i", "--image", required=True, help="path to input image file") + parser.add_argument("-i", "--image", default="imageTextR.png", help="path to input image file") args = vars(parser.parse_args()) # load the image from disk @@ -37,9 +37,9 @@ def main(): coords = cv.findNonZero(thresh) angle = cv.minAreaRect(coords)[-1] # the `cv.minAreaRect` function returns values in the - # range [-90, 0) if the angle is less than -45 we need to add 90 to it - if angle < -45: - angle = (90 + angle) + # range [0, 90) if the angle is more than 45 we need to subtract 90 from it + if angle > 45: + angle = (angle - 90) (h, w) = image.shape[:2] center = (w // 2, h // 2) @@ -55,4 +55,6 @@ def main(): if __name__ == "__main__": + print(__doc__) main() + cv.destroyAllWindows()