diff --git a/samples/python/asift.py b/samples/python/asift.py index 042e9bda3f..8555ed7019 100755 --- a/samples/python/asift.py +++ b/samples/python/asift.py @@ -116,11 +116,11 @@ if __name__ == '__main__': try: fn1, fn2 = args except: - fn1 = '../data/aero1.jpg' - fn2 = '../data/aero3.jpg' + fn1 = 'aero1.jpg' + fn2 = 'aero3.jpg' - img1 = cv.imread(fn1, 0) - img2 = cv.imread(fn2, 0) + img1 = cv.imread(cv.samples.findFile(fn1), cv.IMREAD_GRAYSCALE) + img2 = cv.imread(cv.samples.findFile(fn2), cv.IMREAD_GRAYSCALE) detector, matcher = init_feature(feature_name) if img1 is None: diff --git a/samples/python/browse.py b/samples/python/browse.py index 261d154253..35d1c27280 100755 --- a/samples/python/browse.py +++ b/samples/python/browse.py @@ -32,7 +32,7 @@ if __name__ == '__main__': print() if len(sys.argv) > 1: - fn = sys.argv[1] + fn = cv.samples.findFile(sys.argv[1]) print('loading %s ...' % fn) img = cv.imread(fn) if img is None: diff --git a/samples/python/calibrate.py b/samples/python/calibrate.py index a2970a95e7..e0896ea7ef 100755 --- a/samples/python/calibrate.py +++ b/samples/python/calibrate.py @@ -53,7 +53,7 @@ if __name__ == '__main__': obj_points = [] img_points = [] - h, w = cv.imread(img_names[0], 0).shape[:2] # TODO: use imquery call to retrieve results + h, w = cv.imread(img_names[0], cv.IMREAD_GRAYSCALE).shape[:2] # TODO: use imquery call to retrieve results def processImage(fn): print('processing %s... ' % fn) diff --git a/samples/python/camera_calibration_show_extrinsics.py b/samples/python/camera_calibration_show_extrinsics.py index 75274aea9e..6304aa7931 100755 --- a/samples/python/camera_calibration_show_extrinsics.py +++ b/samples/python/camera_calibration_show_extrinsics.py @@ -160,7 +160,7 @@ def draw_camera_boards(ax, camera_matrix, cam_width, cam_height, scale_focal, def main(): parser = argparse.ArgumentParser(description='Plot camera calibration extrinsics.', formatter_class=argparse.ArgumentDefaultsHelpFormatter) - parser.add_argument('--calibration', type=str, default="../data/left_intrinsics.yml", + parser.add_argument('--calibration', type=str, default='left_intrinsics.yml', help='YAML camera calibration file.') parser.add_argument('--cam_width', type=float, default=0.064/2, help='Width/2 of the displayed camera.') @@ -172,7 +172,7 @@ def main(): help='The calibration board is static and the camera is moving.') args = parser.parse_args() - fs = cv.FileStorage(args.calibration, cv.FILE_STORAGE_READ) + fs = cv.FileStorage(cv.samples.findFile(args.calibration), cv.FILE_STORAGE_READ) board_width = int(fs.getNode('board_width').real()) board_height = int(fs.getNode('board_height').real()) square_size = fs.getNode('square_size').real() diff --git a/samples/python/coherence.py b/samples/python/coherence.py index 225fc13f38..59db351d8d 100755 --- a/samples/python/coherence.py +++ b/samples/python/coherence.py @@ -51,9 +51,9 @@ if __name__ == '__main__': try: fn = sys.argv[1] except: - fn = '../data/baboon.jpg' + fn = 'baboon.jpg' - src = cv.imread(fn) + src = cv.imread(cv.samples.findFile(fn)) def nothing(*argv): pass diff --git a/samples/python/color_histogram.py b/samples/python/color_histogram.py index d997241f50..3a2e532c7e 100755 --- a/samples/python/color_histogram.py +++ b/samples/python/color_histogram.py @@ -39,7 +39,7 @@ if __name__ == '__main__': fn = sys.argv[1] except: fn = 0 - cam = video.create_capture(fn, fallback='synth:bg=../data/baboon.jpg:class=chess:noise=0.05') + cam = video.create_capture(fn, fallback='synth:bg=baboon.jpg:class=chess:noise=0.05') while True: flag, frame = cam.read() diff --git a/samples/python/deconvolution.py b/samples/python/deconvolution.py index 91d10243bb..109f46cddb 100755 --- a/samples/python/deconvolution.py +++ b/samples/python/deconvolution.py @@ -19,11 +19,11 @@ Usage: ESC - exit Examples: - deconvolution.py --angle 135 --d 22 ../data/licenseplate_motion.jpg + deconvolution.py --angle 135 --d 22 licenseplate_motion.jpg (image source: http://www.topazlabs.com/infocus/_images/licenseplate_compare.jpg) - deconvolution.py --angle 86 --d 31 ../data/text_motion.jpg - deconvolution.py --circle --d 19 ../data/text_defocus.jpg + deconvolution.py --angle 86 --d 31 text_motion.jpg + deconvolution.py --circle --d 19 text_defocus.jpg (image source: compact digital photo camera, no artificial distortion) @@ -73,11 +73,11 @@ if __name__ == '__main__': try: fn = args[0] except: - fn = '../data/licenseplate_motion.jpg' + fn = 'licenseplate_motion.jpg' win = 'deconvolution' - img = cv.imread(fn, 0) + img = cv.imread(cv.samples.findFile(fn), cv.IMREAD_GRAYSCALE) if img is None: print('Failed to load file:', fn) sys.exit(1) diff --git a/samples/python/dft.py b/samples/python/dft.py index 51206cf7ab..d5a0f03e06 100755 --- a/samples/python/dft.py +++ b/samples/python/dft.py @@ -38,8 +38,8 @@ def shift_dft(src, dst=None): h, w = src.shape[:2] - cx1 = cx2 = w/2 - cy1 = cy2 = h/2 + cx1 = cx2 = w // 2 + cy1 = cy2 = h // 2 # if the size is odd, then adjust the bottom/right quadrants if w % 2 != 0: @@ -65,11 +65,13 @@ def shift_dft(src, dst=None): if __name__ == "__main__": if len(sys.argv) > 1: - im = cv.imread(sys.argv[1]) + fname = sys.argv[1] else: - im = cv.imread('../data/baboon.jpg') + fname = 'baboon.jpg' print("usage : python dft.py ") + im = cv.imread(cv.samples.findFile(fname)) + # convert to grayscale im = cv.cvtColor(im, cv.COLOR_BGR2GRAY) h, w = im.shape[:2] diff --git a/samples/python/digits.py b/samples/python/digits.py index f9f1e0be39..ea9844e312 100755 --- a/samples/python/digits.py +++ b/samples/python/digits.py @@ -3,7 +3,7 @@ ''' SVM and KNearest digit recognition. -Sample loads a dataset of handwritten digits from '../data/digits.png'. +Sample loads a dataset of handwritten digits from 'digits.png'. Then it trains a SVM and KNearest classifiers on it and evaluates their accuracy. @@ -42,7 +42,7 @@ from common import clock, mosaic SZ = 20 # size of each digit is SZ x SZ CLASS_N = 10 -DIGITS_FN = '../data/digits.png' +DIGITS_FN = 'digits.png' def split2d(img, cell_size, flatten=True): h, w = img.shape[:2] @@ -54,8 +54,9 @@ def split2d(img, cell_size, flatten=True): return cells def load_digits(fn): + fn = cv.samples.findFile(fn) print('loading "%s" ...' % fn) - digits_img = cv.imread(fn, 0) + digits_img = cv.imread(fn, cv.IMREAD_GRAYSCALE) digits = split2d(digits_img, (SZ, SZ)) labels = np.repeat(np.arange(CLASS_N), len(digits)/CLASS_N) return digits, labels diff --git a/samples/python/distrans.py b/samples/python/distrans.py index 02a51d500d..939ecfdc82 100755 --- a/samples/python/distrans.py +++ b/samples/python/distrans.py @@ -24,10 +24,11 @@ if __name__ == '__main__': try: fn = sys.argv[1] except: - fn = '../data/fruits.jpg' + fn = 'fruits.jpg' print(__doc__) - img = cv.imread(fn, 0) + fn = cv.samples.findFile(fn) + img = cv.imread(fn, cv.IMREAD_GRAYSCALE) if img is None: print('Failed to load fn:', fn) sys.exit(1) diff --git a/samples/python/facedetect.py b/samples/python/facedetect.py index eb020d2b6b..73d9341273 100755 --- a/samples/python/facedetect.py +++ b/samples/python/facedetect.py @@ -40,8 +40,8 @@ if __name__ == '__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', "data/haarcascades/haarcascade_frontalface_alt.xml") + nested_fn = args.get('--nested-cascade', "data/haarcascades/haarcascade_eye.xml") cascade = cv.CascadeClassifier(cv.samples.findFile(cascade_fn)) nested = cv.CascadeClassifier(cv.samples.findFile(nested_fn)) diff --git a/samples/python/find_obj.py b/samples/python/find_obj.py index c5cd7c66a9..d0c67b085c 100755 --- a/samples/python/find_obj.py +++ b/samples/python/find_obj.py @@ -147,11 +147,11 @@ if __name__ == '__main__': try: fn1, fn2 = args except: - fn1 = '../data/box.png' - fn2 = '../data/box_in_scene.png' + fn1 = 'box.png' + fn2 = 'box_in_scene.png' - img1 = cv.imread(fn1, 0) - img2 = cv.imread(fn2, 0) + img1 = cv.imread(cv.samples.findFile(fn1), cv.IMREAD_GRAYSCALE) + img2 = cv.imread(cv.samples.findFile(fn2), cv.IMREAD_GRAYSCALE) detector, matcher = init_feature(feature_name) if img1 is None: diff --git a/samples/python/floodfill.py b/samples/python/floodfill.py index f03beef928..29986c5d84 100755 --- a/samples/python/floodfill.py +++ b/samples/python/floodfill.py @@ -25,10 +25,10 @@ if __name__ == '__main__': try: fn = sys.argv[1] except: - fn = '../data/fruits.jpg' + fn = 'fruits.jpg' print(__doc__) - img = cv.imread(fn, True) + img = cv.imread(cv.samples.findFile(fn)) if img is None: print('Failed to load image file:', fn) sys.exit(1) diff --git a/samples/python/gabor_threads.py b/samples/python/gabor_threads.py index 5c1cf11e1e..377fa9ad0b 100755 --- a/samples/python/gabor_threads.py +++ b/samples/python/gabor_threads.py @@ -55,9 +55,9 @@ if __name__ == '__main__': try: img_fn = sys.argv[1] except: - img_fn = '../data/baboon.jpg' + img_fn = 'baboon.jpg' - img = cv.imread(img_fn) + img = cv.imread(cv.samples.findFile(img_fn)) if img is None: print('Failed to load image file:', img_fn) sys.exit(1) diff --git a/samples/python/grabcut.py b/samples/python/grabcut.py index 37bc2e0f17..318e23453f 100644 --- a/samples/python/grabcut.py +++ b/samples/python/grabcut.py @@ -107,11 +107,11 @@ if __name__ == '__main__': if len(sys.argv) == 2: filename = sys.argv[1] # for drawing purposes else: - print("No input image given, so loading default image, ../data/lena.jpg \n") + print("No input image given, so loading default image, lena.jpg \n") print("Correct Usage: python grabcut.py \n") - filename = '../data/lena.jpg' + filename = 'lena.jpg' - img = cv.imread(filename) + img = cv.imread(cv.samples.findFile(filename)) img2 = img.copy() # a copy of original image mask = np.zeros(img.shape[:2],dtype = np.uint8) # mask initialized to PR_BG output = np.zeros(img.shape,np.uint8) # output image to be shown diff --git a/samples/python/hist.py b/samples/python/hist.py index 266fa12e0d..e085fdc55e 100755 --- a/samples/python/hist.py +++ b/samples/python/hist.py @@ -60,10 +60,10 @@ if __name__ == '__main__': if len(sys.argv)>1: fname = sys.argv[1] else : - fname = '../data/lena.jpg' + fname = 'lena.jpg' print("usage : python hist.py ") - im = cv.imread(fname) + im = cv.imread(cv.samples.findFile(fname)) if im is None: print('Failed to load image file:', fname) diff --git a/samples/python/houghcircles.py b/samples/python/houghcircles.py index 2c24c002c6..bf0aa43de3 100755 --- a/samples/python/houghcircles.py +++ b/samples/python/houghcircles.py @@ -5,7 +5,7 @@ This example illustrates how to use cv.HoughCircles() function. Usage: houghcircles.py [] - image argument defaults to ../data/board.jpg + image argument defaults to board.jpg ''' # Python 2/3 compatibility @@ -21,9 +21,9 @@ if __name__ == '__main__': try: fn = sys.argv[1] except IndexError: - fn = "../data/board.jpg" + fn = 'board.jpg' - src = cv.imread(fn, 1) + src = cv.imread(cv.samples.findFile(fn)) img = cv.cvtColor(src, cv.COLOR_BGR2GRAY) img = cv.medianBlur(img, 5) cimg = src.copy() # numpy function diff --git a/samples/python/houghlines.py b/samples/python/houghlines.py index 84351072dd..e662854693 100755 --- a/samples/python/houghlines.py +++ b/samples/python/houghlines.py @@ -5,7 +5,7 @@ This example illustrates how to use Hough Transform to find lines Usage: houghlines.py [] - image argument defaults to ../data/pic1.png + image argument defaults to pic1.png ''' # Python 2/3 compatibility @@ -22,9 +22,9 @@ if __name__ == '__main__': try: fn = sys.argv[1] except IndexError: - fn = "../data/pic1.png" + fn = 'pic1.png' - src = cv.imread(fn) + src = cv.imread(cv.samples.findFile(fn)) dst = cv.Canny(src, 50, 200) cdst = cv.cvtColor(dst, cv.COLOR_GRAY2BGR) diff --git a/samples/python/inpaint.py b/samples/python/inpaint.py index fb0140cc77..3e2fd5635e 100755 --- a/samples/python/inpaint.py +++ b/samples/python/inpaint.py @@ -27,11 +27,11 @@ if __name__ == '__main__': try: fn = sys.argv[1] except: - fn = '../data/fruits.jpg' + fn = 'fruits.jpg' print(__doc__) - img = cv.imread(fn) + img = cv.imread(cv.samples.findFile(fn)) if img is None: print('Failed to load image file:', fn) sys.exit(1) diff --git a/samples/python/letter_recog.py b/samples/python/letter_recog.py index b519379a8f..67e4266f28 100755 --- a/samples/python/letter_recog.py +++ b/samples/python/letter_recog.py @@ -158,10 +158,12 @@ if __name__ == '__main__': args, dummy = getopt.getopt(sys.argv[1:], '', ['model=', 'data=', 'load=', 'save=']) args = dict(args) args.setdefault('--model', 'svm') - args.setdefault('--data', '../data/letter-recognition.data') + args.setdefault('--data', 'letter-recognition.data') - print('loading data %s ...' % args['--data']) - samples, responses = load_base(args['--data']) + datafile = cv.samples.findFile(args['--data']) + + print('loading data %s ...' % datafile) + samples, responses = load_base(datafile) Model = models[args['--model']] model = Model() diff --git a/samples/python/logpolar.py b/samples/python/logpolar.py index 1af0f11753..09b2cbc99f 100644 --- a/samples/python/logpolar.py +++ b/samples/python/logpolar.py @@ -22,9 +22,9 @@ if __name__ == '__main__': try: fn = sys.argv[1] except IndexError: - fn = '../data/fruits.jpg' + fn = 'fruits.jpg' - img = cv.imread(fn) + img = cv.imread(cv.samples.findFile(fn)) if img is None: print('Failed to load image file:', fn) sys.exit(1) diff --git a/samples/python/morphology.py b/samples/python/morphology.py index 1d95fa9b6d..e368c28576 100755 --- a/samples/python/morphology.py +++ b/samples/python/morphology.py @@ -31,9 +31,9 @@ if __name__ == '__main__': try: fn = sys.argv[1] except: - fn = '../data/baboon.jpg' + fn = 'baboon.jpg' - img = cv.imread(fn) + img = cv.imread(cv.samples.findFile(fn)) if img is None: print('Failed to load image file:', fn) diff --git a/samples/python/peopledetect.py b/samples/python/peopledetect.py index d0ddc1b7b2..a6f0538daf 100755 --- a/samples/python/peopledetect.py +++ b/samples/python/peopledetect.py @@ -40,7 +40,7 @@ if __name__ == '__main__': hog = cv.HOGDescriptor() hog.setSVMDetector( cv.HOGDescriptor_getDefaultPeopleDetector() ) - default = ['../data/basketball2.png '] if len(sys.argv[1:]) == 0 else [] + default = [cv.samples.findFile('basketball2.png')] if len(sys.argv[1:]) == 0 else [] for fn in it.chain(*map(glob, default + sys.argv[1:])): print(fn, ' - ',) diff --git a/samples/python/stereo_match.py b/samples/python/stereo_match.py index 5b0867003a..2d539318f5 100755 --- a/samples/python/stereo_match.py +++ b/samples/python/stereo_match.py @@ -35,8 +35,8 @@ def write_ply(fn, verts, colors): if __name__ == '__main__': print('loading images...') - imgL = cv.pyrDown( cv.imread('../data/aloeL.jpg') ) # downscale images for faster processing - imgR = cv.pyrDown( cv.imread('../data/aloeR.jpg') ) + imgL = cv.pyrDown(cv.imread(cv.samples.findFile('aloeL.jpg'))) # downscale images for faster processing + imgR = cv.pyrDown(cv.imread(cv.samples.findFile('aloeR.jpg'))) # disparity range is tuned for 'aloe' image pair window_size = 3 diff --git a/samples/python/texture_flow.py b/samples/python/texture_flow.py index c3220805b3..70259a8129 100755 --- a/samples/python/texture_flow.py +++ b/samples/python/texture_flow.py @@ -21,9 +21,9 @@ if __name__ == '__main__': try: fn = sys.argv[1] except: - fn = '../data/starry_night.jpg' + fn = 'starry_night.jpg' - img = cv.imread(fn) + img = cv.imread(cv.samples.findFile(fn)) if img is None: print('Failed to load image file:', fn) sys.exit(1) diff --git a/samples/python/tst_scene_render.py b/samples/python/tst_scene_render.py index 6955d16012..33cbd0dc1c 100644 --- a/samples/python/tst_scene_render.py +++ b/samples/python/tst_scene_render.py @@ -98,8 +98,8 @@ class TestSceneRender(): if __name__ == '__main__': - backGr = cv.imread('../data/graf1.png') - fgr = cv.imread('../data/box.png') + backGr = cv.imread(cv.samples.findFile('graf1.png')) + fgr = cv.imread(cv.samples.findFile('box.png')) render = TestSceneRender(backGr, fgr) diff --git a/samples/python/tutorial_code/Histograms_Matching/histogram_calculation/calcHist_Demo.py b/samples/python/tutorial_code/Histograms_Matching/histogram_calculation/calcHist_Demo.py index 63302abbbe..992ca90141 100644 --- a/samples/python/tutorial_code/Histograms_Matching/histogram_calculation/calcHist_Demo.py +++ b/samples/python/tutorial_code/Histograms_Matching/histogram_calculation/calcHist_Demo.py @@ -6,10 +6,10 @@ import argparse ## [Load image] parser = argparse.ArgumentParser(description='Code for Histogram Calculation tutorial.') -parser.add_argument('--input', help='Path to input image.', default='../data/lena.jpg') +parser.add_argument('--input', help='Path to input image.', default='lena.jpg') args = parser.parse_args() -src = cv.imread(args.input) +src = cv.imread(cv.samples.findFile(args.input)) if src is None: print('Could not open or find the image:', args.input) exit(0) diff --git a/samples/python/tutorial_code/Histograms_Matching/histogram_equalization/EqualizeHist_Demo.py b/samples/python/tutorial_code/Histograms_Matching/histogram_equalization/EqualizeHist_Demo.py index fb87cce75a..9bb82cee40 100644 --- a/samples/python/tutorial_code/Histograms_Matching/histogram_equalization/EqualizeHist_Demo.py +++ b/samples/python/tutorial_code/Histograms_Matching/histogram_equalization/EqualizeHist_Demo.py @@ -4,10 +4,10 @@ import argparse ## [Load image] parser = argparse.ArgumentParser(description='Code for Histogram Equalization tutorial.') -parser.add_argument('--input', help='Path to input image.', default='../data/lena.jpg') +parser.add_argument('--input', help='Path to input image.', default='lena.jpg') args = parser.parse_args() -src = cv.imread(args.input) +src = cv.imread(cv.samples.findFile(args.input)) if src is None: print('Could not open or find the image:', args.input) exit(0) diff --git a/samples/python/tutorial_code/ImgTrans/Filter2D/filter2D.py b/samples/python/tutorial_code/ImgTrans/Filter2D/filter2D.py index 407cd8b2fc..658e4636a7 100644 --- a/samples/python/tutorial_code/ImgTrans/Filter2D/filter2D.py +++ b/samples/python/tutorial_code/ImgTrans/Filter2D/filter2D.py @@ -11,15 +11,15 @@ def main(argv): window_name = 'filter2D Demo' ## [load] - imageName = argv[0] if len(argv) > 0 else "../data/lena.jpg" + imageName = argv[0] if len(argv) > 0 else 'lena.jpg' # Loads an image - src = cv.imread(imageName, cv.IMREAD_COLOR) + src = cv.imread(cv.samples.findFile(imageName), cv.IMREAD_COLOR) # Check if image is loaded fine if src is None: print ('Error opening image!') - print ('Usage: filter2D.py [image_name -- default ../data/lena.jpg] \n') + print ('Usage: filter2D.py [image_name -- default lena.jpg] \n') return -1 ## [load] ## [init_arguments] diff --git a/samples/python/tutorial_code/ImgTrans/HoughCircle/hough_circle.py b/samples/python/tutorial_code/ImgTrans/HoughCircle/hough_circle.py index 1f0a74cbf8..8da7eefed6 100644 --- a/samples/python/tutorial_code/ImgTrans/HoughCircle/hough_circle.py +++ b/samples/python/tutorial_code/ImgTrans/HoughCircle/hough_circle.py @@ -5,11 +5,11 @@ import numpy as np def main(argv): ## [load] - default_file = "../../../../data/smarties.png" + default_file = 'smarties.png' filename = argv[0] if len(argv) > 0 else default_file # Loads an image - src = cv.imread(filename, cv.IMREAD_COLOR) + src = cv.imread(cv.samples.findFile(filename), cv.IMREAD_COLOR) # Check if image is loaded fine if src is None: diff --git a/samples/python/tutorial_code/ImgTrans/HoughLine/hough_lines.py b/samples/python/tutorial_code/ImgTrans/HoughLine/hough_lines.py index 697f388e2f..71e5a92239 100644 --- a/samples/python/tutorial_code/ImgTrans/HoughLine/hough_lines.py +++ b/samples/python/tutorial_code/ImgTrans/HoughLine/hough_lines.py @@ -10,11 +10,11 @@ import numpy as np def main(argv): ## [load] - default_file = "../../../../data/sudoku.png" + default_file = 'sudoku.png' filename = argv[0] if len(argv) > 0 else default_file # Loads an image - src = cv.imread(filename, cv.IMREAD_GRAYSCALE) + src = cv.imread(cv.samples.findFile(filename), cv.IMREAD_GRAYSCALE) # Check if image is loaded fine if src is None: diff --git a/samples/python/tutorial_code/ImgTrans/LaPlace/laplace_demo.py b/samples/python/tutorial_code/ImgTrans/LaPlace/laplace_demo.py index 1cff041d36..a90af4da1d 100644 --- a/samples/python/tutorial_code/ImgTrans/LaPlace/laplace_demo.py +++ b/samples/python/tutorial_code/ImgTrans/LaPlace/laplace_demo.py @@ -14,14 +14,14 @@ def main(argv): # [variables] # [load] - imageName = argv[0] if len(argv) > 0 else "../data/lena.jpg" + imageName = argv[0] if len(argv) > 0 else 'lena.jpg' - src = cv.imread(imageName, cv.IMREAD_COLOR) # Load an image + src = cv.imread(cv.samples.findFile(imageName), cv.IMREAD_COLOR) # Load an image # Check if image is loaded fine if src is None: print ('Error opening image') - print ('Program Arguments: [image_name -- default ../data/lena.jpg]') + print ('Program Arguments: [image_name -- default lena.jpg]') return -1 # [load] diff --git a/samples/python/tutorial_code/ImgTrans/MakeBorder/copy_make_border.py b/samples/python/tutorial_code/ImgTrans/MakeBorder/copy_make_border.py index 453037fa37..ff1f3669c7 100644 --- a/samples/python/tutorial_code/ImgTrans/MakeBorder/copy_make_border.py +++ b/samples/python/tutorial_code/ImgTrans/MakeBorder/copy_make_border.py @@ -14,15 +14,15 @@ def main(argv): window_name = "copyMakeBorder Demo" ## [variables] ## [load] - imageName = argv[0] if len(argv) > 0 else "../data/lena.jpg" + imageName = argv[0] if len(argv) > 0 else 'lena.jpg' # Loads an image - src = cv.imread(imageName, cv.IMREAD_COLOR) + src = cv.imread(cv.samples.findFile(imageName), cv.IMREAD_COLOR) # Check if image is loaded fine if src is None: print ('Error opening image!') - print ('Usage: copy_make_border.py [image_name -- default ../data/lena.jpg] \n') + print ('Usage: copy_make_border.py [image_name -- default lena.jpg] \n') return -1 ## [load] # Brief how-to for this program diff --git a/samples/python/tutorial_code/ImgTrans/canny_detector/CannyDetector_Demo.py b/samples/python/tutorial_code/ImgTrans/canny_detector/CannyDetector_Demo.py index 6699512975..391572816b 100644 --- a/samples/python/tutorial_code/ImgTrans/canny_detector/CannyDetector_Demo.py +++ b/samples/python/tutorial_code/ImgTrans/canny_detector/CannyDetector_Demo.py @@ -17,10 +17,10 @@ def CannyThreshold(val): cv.imshow(window_name, dst) parser = argparse.ArgumentParser(description='Code for Canny Edge Detector tutorial.') -parser.add_argument('--input', help='Path to input image.', default='../data/fruits.jpg') +parser.add_argument('--input', help='Path to input image.', default='fruits.jpg') args = parser.parse_args() -src = cv.imread(args.input) +src = cv.imread(cv.samples.findFile(args.input)) if src is None: print('Could not open or find the image: ', args.input) exit(0) diff --git a/samples/python/tutorial_code/ImgTrans/distance_transformation/imageSegmentation.py b/samples/python/tutorial_code/ImgTrans/distance_transformation/imageSegmentation.py index e679001bc1..0ab56cfb30 100644 --- a/samples/python/tutorial_code/ImgTrans/distance_transformation/imageSegmentation.py +++ b/samples/python/tutorial_code/ImgTrans/distance_transformation/imageSegmentation.py @@ -11,10 +11,10 @@ rng.seed(12345) parser = argparse.ArgumentParser(description='Code for Image Segmentation with Distance Transform and Watershed Algorithm.\ Sample code showing how to segment overlapping objects using Laplacian filtering, \ in addition to Watershed and Distance Transformation') -parser.add_argument('--input', help='Path to input image.', default='../data/cards.png') +parser.add_argument('--input', help='Path to input image.', default='cards.png') args = parser.parse_args() -src = cv.imread(args.input) +src = cv.imread(cv.samples.findFile(args.input)) if src is None: print('Could not open or find the image:', args.input) exit(0) diff --git a/samples/python/tutorial_code/ImgTrans/remap/Remap_Demo.py b/samples/python/tutorial_code/ImgTrans/remap/Remap_Demo.py index e9c764d2e0..f50aa36571 100644 --- a/samples/python/tutorial_code/ImgTrans/remap/Remap_Demo.py +++ b/samples/python/tutorial_code/ImgTrans/remap/Remap_Demo.py @@ -32,11 +32,11 @@ def update_map(ind, map_x, map_y): ## [Update] parser = argparse.ArgumentParser(description='Code for Remapping tutorial.') -parser.add_argument('--input', help='Path to input image.', default='../data/chicky_512.png') +parser.add_argument('--input', help='Path to input image.', default='chicky_512.png') args = parser.parse_args() ## [Load] -src = cv.imread(args.input, cv.IMREAD_COLOR) +src = cv.imread(cv.samples.findFile(args.input), cv.IMREAD_COLOR) if src is None: print('Could not open or find the image: ', args.input) exit(0) diff --git a/samples/python/tutorial_code/ImgTrans/warp_affine/Geometric_Transforms_Demo.py b/samples/python/tutorial_code/ImgTrans/warp_affine/Geometric_Transforms_Demo.py index 462a412f47..d141470c92 100644 --- a/samples/python/tutorial_code/ImgTrans/warp_affine/Geometric_Transforms_Demo.py +++ b/samples/python/tutorial_code/ImgTrans/warp_affine/Geometric_Transforms_Demo.py @@ -5,10 +5,10 @@ import argparse ## [Load the image] parser = argparse.ArgumentParser(description='Code for Affine Transformations tutorial.') -parser.add_argument('--input', help='Path to input image.', default='../data/lena.jpg') +parser.add_argument('--input', help='Path to input image.', default='lena.jpg') args = parser.parse_args() -src = cv.imread(args.input) +src = cv.imread(cv.samples.findFile(args.input)) if src is None: print('Could not open or find the image:', args.input) exit(0) diff --git a/samples/python/tutorial_code/ShapeDescriptors/bounding_rects_circles/generalContours_demo1.py b/samples/python/tutorial_code/ShapeDescriptors/bounding_rects_circles/generalContours_demo1.py index fb5d68ac07..5de2d21fc2 100644 --- a/samples/python/tutorial_code/ShapeDescriptors/bounding_rects_circles/generalContours_demo1.py +++ b/samples/python/tutorial_code/ShapeDescriptors/bounding_rects_circles/generalContours_demo1.py @@ -53,10 +53,10 @@ def thresh_callback(val): ## [setup] # Load source image parser = argparse.ArgumentParser(description='Code for Creating Bounding boxes and circles for contours tutorial.') -parser.add_argument('--input', help='Path to input image.', default='../data/stuff.jpg') +parser.add_argument('--input', help='Path to input image.', default='stuff.jpg') args = parser.parse_args() -src = cv.imread(args.input) +src = cv.imread(cv.samples.findFile(args.input)) if src is None: print('Could not open or find the image:', args.input) exit(0) diff --git a/samples/python/tutorial_code/ShapeDescriptors/bounding_rotated_ellipses/generalContours_demo2.py b/samples/python/tutorial_code/ShapeDescriptors/bounding_rotated_ellipses/generalContours_demo2.py index 16787718f6..38d5ca43bd 100644 --- a/samples/python/tutorial_code/ShapeDescriptors/bounding_rotated_ellipses/generalContours_demo2.py +++ b/samples/python/tutorial_code/ShapeDescriptors/bounding_rotated_ellipses/generalContours_demo2.py @@ -53,10 +53,10 @@ def thresh_callback(val): ## [setup] # Load source image parser = argparse.ArgumentParser(description='Code for Creating Bounding rotated boxes and ellipses for contours tutorial.') -parser.add_argument('--input', help='Path to input image.', default='../data/stuff.jpg') +parser.add_argument('--input', help='Path to input image.', default='stuff.jpg') args = parser.parse_args() -src = cv.imread(args.input) +src = cv.imread(cv.samples.findFile(args.input)) if src is None: print('Could not open or find the image:', args.input) exit(0) diff --git a/samples/python/tutorial_code/ShapeDescriptors/find_contours/findContours_demo.py b/samples/python/tutorial_code/ShapeDescriptors/find_contours/findContours_demo.py index f4cbb5f401..96b4067b6b 100644 --- a/samples/python/tutorial_code/ShapeDescriptors/find_contours/findContours_demo.py +++ b/samples/python/tutorial_code/ShapeDescriptors/find_contours/findContours_demo.py @@ -26,10 +26,10 @@ def thresh_callback(val): # Load source image parser = argparse.ArgumentParser(description='Code for Finding contours in your image tutorial.') -parser.add_argument('--input', help='Path to input image.', default='../data/HappyFish.jpg') +parser.add_argument('--input', help='Path to input image.', default='HappyFish.jpg') args = parser.parse_args() -src = cv.imread(args.input) +src = cv.imread(cv.samples.findFile(args.input)) if src is None: print('Could not open or find the image:', args.input) exit(0) diff --git a/samples/python/tutorial_code/ShapeDescriptors/hull/hull_demo.py b/samples/python/tutorial_code/ShapeDescriptors/hull/hull_demo.py index 3254941ac0..f5b643f19c 100644 --- a/samples/python/tutorial_code/ShapeDescriptors/hull/hull_demo.py +++ b/samples/python/tutorial_code/ShapeDescriptors/hull/hull_demo.py @@ -33,10 +33,10 @@ def thresh_callback(val): # Load source image parser = argparse.ArgumentParser(description='Code for Convex Hull tutorial.') -parser.add_argument('--input', help='Path to input image.', default='../data/stuff.jpg') +parser.add_argument('--input', help='Path to input image.', default='stuff.jpg') args = parser.parse_args() -src = cv.imread(args.input) +src = cv.imread(cv.samples.findFile(args.input)) if src is None: print('Could not open or find the image:', args.input) exit(0) diff --git a/samples/python/tutorial_code/ShapeDescriptors/moments/moments_demo.py b/samples/python/tutorial_code/ShapeDescriptors/moments/moments_demo.py index c528110ba1..31dd43359a 100644 --- a/samples/python/tutorial_code/ShapeDescriptors/moments/moments_demo.py +++ b/samples/python/tutorial_code/ShapeDescriptors/moments/moments_demo.py @@ -54,10 +54,10 @@ def thresh_callback(val): ## [setup] # Load source image parser = argparse.ArgumentParser(description='Code for Image Moments tutorial.') -parser.add_argument('--input', help='Path to input image.', default='../data/stuff.jpg') +parser.add_argument('--input', help='Path to input image.', default='stuff.jpg') args = parser.parse_args() -src = cv.imread(args.input) +src = cv.imread(cv.samples.findFile(args.input)) if src is None: print('Could not open or find the image:', args.input) exit(0) diff --git a/samples/python/tutorial_code/TrackingMotion/corner_subpixels/cornerSubPix_Demo.py b/samples/python/tutorial_code/TrackingMotion/corner_subpixels/cornerSubPix_Demo.py index 72ce96b1a6..6d8738b310 100644 --- a/samples/python/tutorial_code/TrackingMotion/corner_subpixels/cornerSubPix_Demo.py +++ b/samples/python/tutorial_code/TrackingMotion/corner_subpixels/cornerSubPix_Demo.py @@ -50,10 +50,10 @@ def goodFeaturesToTrack_Demo(val): # Load source image and convert it to gray parser = argparse.ArgumentParser(description='Code for Shi-Tomasi corner detector tutorial.') -parser.add_argument('--input', help='Path to input image.', default='../data/pic3.png') +parser.add_argument('--input', help='Path to input image.', default='pic3.png') args = parser.parse_args() -src = cv.imread(args.input) +src = cv.imread(cv.samples.findFile(args.input)) if src is None: print('Could not open or find the image:', args.input) exit(0) diff --git a/samples/python/tutorial_code/TrackingMotion/generic_corner_detector/cornerDetector_Demo.py b/samples/python/tutorial_code/TrackingMotion/generic_corner_detector/cornerDetector_Demo.py index d135367fc2..653307879c 100644 --- a/samples/python/tutorial_code/TrackingMotion/generic_corner_detector/cornerDetector_Demo.py +++ b/samples/python/tutorial_code/TrackingMotion/generic_corner_detector/cornerDetector_Demo.py @@ -35,10 +35,10 @@ def myShiTomasi_function(val): # Load source image and convert it to gray parser = argparse.ArgumentParser(description='Code for Creating your own corner detector tutorial.') -parser.add_argument('--input', help='Path to input image.', default='../data/building.jpg') +parser.add_argument('--input', help='Path to input image.', default='building.jpg') args = parser.parse_args() -src = cv.imread(args.input) +src = cv.imread(cv.samples.findFile(args.input)) if src is None: print('Could not open or find the image:', args.input) exit(0) diff --git a/samples/python/tutorial_code/TrackingMotion/good_features_to_track/goodFeaturesToTrack_Demo.py b/samples/python/tutorial_code/TrackingMotion/good_features_to_track/goodFeaturesToTrack_Demo.py index 57e767ccee..3fb8441d92 100644 --- a/samples/python/tutorial_code/TrackingMotion/good_features_to_track/goodFeaturesToTrack_Demo.py +++ b/samples/python/tutorial_code/TrackingMotion/good_features_to_track/goodFeaturesToTrack_Demo.py @@ -38,10 +38,10 @@ def goodFeaturesToTrack_Demo(val): # Load source image and convert it to gray parser = argparse.ArgumentParser(description='Code for Shi-Tomasi corner detector tutorial.') -parser.add_argument('--input', help='Path to input image.', default='../data/pic3.png') +parser.add_argument('--input', help='Path to input image.', default='pic3.png') args = parser.parse_args() -src = cv.imread(args.input) +src = cv.imread(cv.samples.findFile(args.input)) if src is None: print('Could not open or find the image:', args.input) exit(0) diff --git a/samples/python/tutorial_code/TrackingMotion/harris_detector/cornerHarris_Demo.py b/samples/python/tutorial_code/TrackingMotion/harris_detector/cornerHarris_Demo.py index cee7679adf..63d765f202 100644 --- a/samples/python/tutorial_code/TrackingMotion/harris_detector/cornerHarris_Demo.py +++ b/samples/python/tutorial_code/TrackingMotion/harris_detector/cornerHarris_Demo.py @@ -35,10 +35,10 @@ def cornerHarris_demo(val): # Load source image and convert it to gray parser = argparse.ArgumentParser(description='Code for Harris corner detector tutorial.') -parser.add_argument('--input', help='Path to input image.', default='../data/building.jpg') +parser.add_argument('--input', help='Path to input image.', default='building.jpg') args = parser.parse_args() -src = cv.imread(args.input) +src = cv.imread(cv.samples.findFile(args.input)) if src is None: print('Could not open or find the image:', args.input) exit(0) diff --git a/samples/python/tutorial_code/core/AddingImages/adding_images.py b/samples/python/tutorial_code/core/AddingImages/adding_images.py index 65c6154d62..928686d18e 100644 --- a/samples/python/tutorial_code/core/AddingImages/adding_images.py +++ b/samples/python/tutorial_code/core/AddingImages/adding_images.py @@ -16,8 +16,8 @@ input_alpha = float(raw_input().strip()) if 0 <= alpha <= 1: alpha = input_alpha # [load] -src1 = cv.imread('../../../../data/LinuxLogo.jpg') -src2 = cv.imread('../../../../data/WindowsLogo.jpg') +src1 = cv.imread(cv.samples.findFile('LinuxLogo.jpg')) +src2 = cv.imread(cv.samples.findFile('WindowsLogo.jpg')) # [load] if src1 is None: print("Error loading src1") diff --git a/samples/python/tutorial_code/core/discrete_fourier_transform/discrete_fourier_transform.py b/samples/python/tutorial_code/core/discrete_fourier_transform/discrete_fourier_transform.py index 96535acbcd..a89a1097ac 100644 --- a/samples/python/tutorial_code/core/discrete_fourier_transform/discrete_fourier_transform.py +++ b/samples/python/tutorial_code/core/discrete_fourier_transform/discrete_fourier_transform.py @@ -10,16 +10,16 @@ def print_help(): This program demonstrated the use of the discrete Fourier transform (DFT). The dft of an image is taken and it's power spectrum is displayed. Usage: - discrete_fourier_transform.py [image_name -- default ../../../../data/lena.jpg]''') + discrete_fourier_transform.py [image_name -- default lena.jpg]''') def main(argv): print_help() - filename = argv[0] if len(argv) > 0 else "../../../../data/lena.jpg" + filename = argv[0] if len(argv) > 0 else 'lena.jpg' - I = cv.imread(filename, cv.IMREAD_GRAYSCALE) + I = cv.imread(cv.samples.findFile(filename), cv.IMREAD_GRAYSCALE) if I is None: print('Error opening image') return -1 diff --git a/samples/python/tutorial_code/core/mat_mask_operations/mat_mask_operations.py b/samples/python/tutorial_code/core/mat_mask_operations/mat_mask_operations.py index b151575f15..3b9385020e 100644 --- a/samples/python/tutorial_code/core/mat_mask_operations/mat_mask_operations.py +++ b/samples/python/tutorial_code/core/mat_mask_operations/mat_mask_operations.py @@ -45,7 +45,7 @@ def sharpen(my_image): ## [basic_method] def main(argv): - filename = "../../../../data/lena.jpg" + filename = 'lena.jpg' img_codec = cv.IMREAD_COLOR if argv: @@ -53,12 +53,12 @@ def main(argv): if len(argv) >= 2 and sys.argv[2] == "G": img_codec = cv.IMREAD_GRAYSCALE - src = cv.imread(filename, img_codec) + src = cv.imread(cv.samples.findFile(filename), img_codec) if src is None: print("Can't open image [" + filename + "]") print("Usage:") - print("mat_mask_operations.py [image_path -- default ../../../../data/lena.jpg] [G -- grayscale]") + print("mat_mask_operations.py [image_path -- default lena.jpg] [G -- grayscale]") return -1 cv.namedWindow("Input", cv.WINDOW_AUTOSIZE) diff --git a/samples/python/tutorial_code/features2D/akaze_matching/AKAZE_match.py b/samples/python/tutorial_code/features2D/akaze_matching/AKAZE_match.py index 0d9818a3c1..61d1e93a67 100644 --- a/samples/python/tutorial_code/features2D/akaze_matching/AKAZE_match.py +++ b/samples/python/tutorial_code/features2D/akaze_matching/AKAZE_match.py @@ -6,18 +6,18 @@ from math import sqrt ## [load] parser = argparse.ArgumentParser(description='Code for AKAZE local features matching tutorial.') -parser.add_argument('--input1', help='Path to input image 1.', default='../data/graf1.png') -parser.add_argument('--input2', help='Path to input image 2.', default='../data/graf3.png') -parser.add_argument('--homography', help='Path to the homography matrix.', default='../data/H1to3p.xml') +parser.add_argument('--input1', help='Path to input image 1.', default='graf1.png') +parser.add_argument('--input2', help='Path to input image 2.', default='graf3.png') +parser.add_argument('--homography', help='Path to the homography matrix.', default='H1to3p.xml') args = parser.parse_args() -img1 = cv.imread(args.input1, cv.IMREAD_GRAYSCALE) -img2 = cv.imread(args.input2, cv.IMREAD_GRAYSCALE) +img1 = cv.imread(cv.samples.findFile(args.input1), cv.IMREAD_GRAYSCALE) +img2 = cv.imread(cv.samples.findFile(args.input2), cv.IMREAD_GRAYSCALE) if img1 is None or img2 is None: print('Could not open or find the images!') exit(0) -fs = cv.FileStorage(args.homography, cv.FILE_STORAGE_READ) +fs = cv.FileStorage(cv.samples.findFile(args.homography), cv.FILE_STORAGE_READ) homography = fs.getFirstTopLevelNode().mat() ## [load] diff --git a/samples/python/tutorial_code/features2D/feature_description/SURF_matching_Demo.py b/samples/python/tutorial_code/features2D/feature_description/SURF_matching_Demo.py index f50e48d858..d7f84814a7 100644 --- a/samples/python/tutorial_code/features2D/feature_description/SURF_matching_Demo.py +++ b/samples/python/tutorial_code/features2D/feature_description/SURF_matching_Demo.py @@ -4,12 +4,12 @@ import numpy as np import argparse parser = argparse.ArgumentParser(description='Code for Feature Detection tutorial.') -parser.add_argument('--input1', help='Path to input image 1.', default='../data/box.png') -parser.add_argument('--input2', help='Path to input image 2.', default='../data/box_in_scene.png') +parser.add_argument('--input1', help='Path to input image 1.', default='box.png') +parser.add_argument('--input2', help='Path to input image 2.', default='box_in_scene.png') args = parser.parse_args() -img1 = cv.imread(args.input1, cv.IMREAD_GRAYSCALE) -img2 = cv.imread(args.input2, cv.IMREAD_GRAYSCALE) +img1 = cv.imread(cv.samples.findFile(args.input1), cv.IMREAD_GRAYSCALE) +img2 = cv.imread(cv.samples.findFile(args.input2), cv.IMREAD_GRAYSCALE) if img1 is None or img2 is None: print('Could not open or find the images!') exit(0) diff --git a/samples/python/tutorial_code/features2D/feature_detection/SURF_detection_Demo.py b/samples/python/tutorial_code/features2D/feature_detection/SURF_detection_Demo.py index 717d9f13c0..7a30e11577 100644 --- a/samples/python/tutorial_code/features2D/feature_detection/SURF_detection_Demo.py +++ b/samples/python/tutorial_code/features2D/feature_detection/SURF_detection_Demo.py @@ -4,10 +4,10 @@ import numpy as np import argparse parser = argparse.ArgumentParser(description='Code for Feature Detection tutorial.') -parser.add_argument('--input', help='Path to input image.', default='../data/box.png') +parser.add_argument('--input', help='Path to input image.', default='box.png') args = parser.parse_args() -src = cv.imread(args.input, cv.IMREAD_GRAYSCALE) +src = cv.imread(cv.samples.findFile(args.input), cv.IMREAD_GRAYSCALE) if src is None: print('Could not open or find the image:', args.input) exit(0) diff --git a/samples/python/tutorial_code/features2D/feature_flann_matcher/SURF_FLANN_matching_Demo.py b/samples/python/tutorial_code/features2D/feature_flann_matcher/SURF_FLANN_matching_Demo.py index fbe35675d7..e0a684cd8e 100644 --- a/samples/python/tutorial_code/features2D/feature_flann_matcher/SURF_FLANN_matching_Demo.py +++ b/samples/python/tutorial_code/features2D/feature_flann_matcher/SURF_FLANN_matching_Demo.py @@ -4,12 +4,12 @@ import numpy as np import argparse parser = argparse.ArgumentParser(description='Code for Feature Matching with FLANN tutorial.') -parser.add_argument('--input1', help='Path to input image 1.', default='../data/box.png') -parser.add_argument('--input2', help='Path to input image 2.', default='../data/box_in_scene.png') +parser.add_argument('--input1', help='Path to input image 1.', default='box.png') +parser.add_argument('--input2', help='Path to input image 2.', default='box_in_scene.png') args = parser.parse_args() -img1 = cv.imread(args.input1, cv.IMREAD_GRAYSCALE) -img2 = cv.imread(args.input2, cv.IMREAD_GRAYSCALE) +img1 = cv.imread(cv.samples.findFile(args.input1), cv.IMREAD_GRAYSCALE) +img2 = cv.imread(cv.samples.findFile(args.input2), cv.IMREAD_GRAYSCALE) if img1 is None or img2 is None: print('Could not open or find the images!') exit(0) diff --git a/samples/python/tutorial_code/features2D/feature_homography/SURF_FLANN_matching_homography_Demo.py b/samples/python/tutorial_code/features2D/feature_homography/SURF_FLANN_matching_homography_Demo.py index 8ef500e7af..72cc4633e4 100644 --- a/samples/python/tutorial_code/features2D/feature_homography/SURF_FLANN_matching_homography_Demo.py +++ b/samples/python/tutorial_code/features2D/feature_homography/SURF_FLANN_matching_homography_Demo.py @@ -4,12 +4,12 @@ import numpy as np import argparse parser = argparse.ArgumentParser(description='Code for Feature Matching with FLANN tutorial.') -parser.add_argument('--input1', help='Path to input image 1.', default='../data/box.png') -parser.add_argument('--input2', help='Path to input image 2.', default='../data/box_in_scene.png') +parser.add_argument('--input1', help='Path to input image 1.', default='box.png') +parser.add_argument('--input2', help='Path to input image 2.', default='box_in_scene.png') args = parser.parse_args() -img_object = cv.imread(args.input1, cv.IMREAD_GRAYSCALE) -img_scene = cv.imread(args.input2, cv.IMREAD_GRAYSCALE) +img_object = cv.imread(cv.samples.findFile(args.input1), cv.IMREAD_GRAYSCALE) +img_scene = cv.imread(cv.samples.findFile(args.input2), cv.IMREAD_GRAYSCALE) if img_object is None or img_scene is None: print('Could not open or find the images!') exit(0) diff --git a/samples/python/tutorial_code/highgui/trackbar/AddingImagesTrackbar.py b/samples/python/tutorial_code/highgui/trackbar/AddingImagesTrackbar.py index 2ccc978a8e..ffb978049c 100644 --- a/samples/python/tutorial_code/highgui/trackbar/AddingImagesTrackbar.py +++ b/samples/python/tutorial_code/highgui/trackbar/AddingImagesTrackbar.py @@ -15,14 +15,14 @@ def on_trackbar(val): ## [on_trackbar] parser = argparse.ArgumentParser(description='Code for Adding a Trackbar to our applications tutorial.') -parser.add_argument('--input1', help='Path to the first input image.', default='../data/LinuxLogo.jpg') -parser.add_argument('--input2', help='Path to the second input image.', default='../data/WindowsLogo.jpg') +parser.add_argument('--input1', help='Path to the first input image.', default='LinuxLogo.jpg') +parser.add_argument('--input2', help='Path to the second input image.', default='WindowsLogo.jpg') args = parser.parse_args() ## [load] # Read images ( both have to be of the same size and type ) -src1 = cv.imread(args.input1) -src2 = cv.imread(args.input2) +src1 = cv.imread(cv.samples.findFile(args.input1)) +src2 = cv.imread(cv.samples.findFile(args.input2)) ## [load] if src1 is None: print('Could not open or find the image: ', args.input1) diff --git a/samples/python/tutorial_code/imgProc/Pyramids/pyramids.py b/samples/python/tutorial_code/imgProc/Pyramids/pyramids.py index 387e26cc94..429156b573 100644 --- a/samples/python/tutorial_code/imgProc/Pyramids/pyramids.py +++ b/samples/python/tutorial_code/imgProc/Pyramids/pyramids.py @@ -11,10 +11,10 @@ def main(argv): * [ESC] -> Close program """) ## [load] - filename = argv[0] if len(argv) > 0 else "../data/chicky_512.png" + filename = argv[0] if len(argv) > 0 else 'chicky_512.png' # Load the image - src = cv.imread(filename) + src = cv.imread(cv.samples.findFile(filename)) # Check if image is loaded fine if src is None: diff --git a/samples/python/tutorial_code/imgProc/Smoothing/smoothing.py b/samples/python/tutorial_code/imgProc/Smoothing/smoothing.py index e7096580ad..a67b92dc5e 100644 --- a/samples/python/tutorial_code/imgProc/Smoothing/smoothing.py +++ b/samples/python/tutorial_code/imgProc/Smoothing/smoothing.py @@ -17,10 +17,10 @@ def main(argv): cv.namedWindow(window_name, cv.WINDOW_AUTOSIZE) # Load the source image - imageName = argv[0] if len(argv) > 0 else "../data/lena.jpg" + imageName = argv[0] if len(argv) > 0 else 'lena.jpg' global src - src = cv.imread(imageName, 1) + src = cv.imread(cv.samples.findFile(imageName)) if src is None: print ('Error opening image') print ('Usage: smoothing.py [image_name -- default ../data/lena.jpg] \n') diff --git a/samples/python/tutorial_code/imgProc/changing_contrast_brightness_image/BasicLinearTransforms.py b/samples/python/tutorial_code/imgProc/changing_contrast_brightness_image/BasicLinearTransforms.py index 28baf3f8a0..6b299a6203 100644 --- a/samples/python/tutorial_code/imgProc/changing_contrast_brightness_image/BasicLinearTransforms.py +++ b/samples/python/tutorial_code/imgProc/changing_contrast_brightness_image/BasicLinearTransforms.py @@ -7,10 +7,10 @@ import argparse # Read image given by user ## [basic-linear-transform-load] parser = argparse.ArgumentParser(description='Code for Changing the contrast and brightness of an image! tutorial.') -parser.add_argument('--input', help='Path to input image.', default='../data/lena.jpg') +parser.add_argument('--input', help='Path to input image.', default='lena.jpg') args = parser.parse_args() -image = cv.imread(args.input) +image = cv.imread(cv.samples.findFile(args.input)) if image is None: print('Could not open or find the image: ', args.input) exit(0) diff --git a/samples/python/tutorial_code/imgProc/changing_contrast_brightness_image/changing_contrast_brightness_image.py b/samples/python/tutorial_code/imgProc/changing_contrast_brightness_image/changing_contrast_brightness_image.py index 704df1aecb..b3f316396a 100644 --- a/samples/python/tutorial_code/imgProc/changing_contrast_brightness_image/changing_contrast_brightness_image.py +++ b/samples/python/tutorial_code/imgProc/changing_contrast_brightness_image/changing_contrast_brightness_image.py @@ -44,10 +44,10 @@ def on_gamma_correction_trackbar(val): gammaCorrection() parser = argparse.ArgumentParser(description='Code for Changing the contrast and brightness of an image! tutorial.') -parser.add_argument('--input', help='Path to input image.', default='../data/lena.jpg') +parser.add_argument('--input', help='Path to input image.', default='lena.jpg') args = parser.parse_args() -img_original = cv.imread(args.input) +img_original = cv.imread(cv.samples.findFile(args.input)) if img_original is None: print('Could not open or find the image: ', args.input) exit(0) diff --git a/samples/python/tutorial_code/imgProc/erosion_dilatation/morphology_1.py b/samples/python/tutorial_code/imgProc/erosion_dilatation/morphology_1.py index cb3af732e8..502457b471 100644 --- a/samples/python/tutorial_code/imgProc/erosion_dilatation/morphology_1.py +++ b/samples/python/tutorial_code/imgProc/erosion_dilatation/morphology_1.py @@ -42,10 +42,10 @@ def dilatation(val): cv.imshow(title_dilatation_window, dilatation_dst) parser = argparse.ArgumentParser(description='Code for Eroding and Dilating tutorial.') -parser.add_argument('--input', help='Path to input image.', default='../data/LinuxLogo.jpg') +parser.add_argument('--input', help='Path to input image.', default='LinuxLogo.jpg') args = parser.parse_args() -src = cv.imread(args.input) +src = cv.imread(cv.samples.findFile(args.input)) if src is None: print('Could not open or find the image: ', args.input) exit(0) diff --git a/samples/python/tutorial_code/imgProc/hough_line_transform/hough_line_transform.py b/samples/python/tutorial_code/imgProc/hough_line_transform/hough_line_transform.py index 6af4e2865b..9a30923c7b 100644 --- a/samples/python/tutorial_code/imgProc/hough_line_transform/hough_line_transform.py +++ b/samples/python/tutorial_code/imgProc/hough_line_transform/hough_line_transform.py @@ -1,7 +1,7 @@ import cv2 as cv import numpy as np -img = cv.imread('../data/sudoku.png') +img = cv.imread(cv.samples.findFile('sudoku.png')) gray = cv.cvtColor(img,cv.COLOR_BGR2GRAY) edges = cv.Canny(gray,50,150,apertureSize = 3) diff --git a/samples/python/tutorial_code/imgProc/hough_line_transform/probabilistic_hough_line_transform.py b/samples/python/tutorial_code/imgProc/hough_line_transform/probabilistic_hough_line_transform.py index 7e510db32b..d01fe8952f 100644 --- a/samples/python/tutorial_code/imgProc/hough_line_transform/probabilistic_hough_line_transform.py +++ b/samples/python/tutorial_code/imgProc/hough_line_transform/probabilistic_hough_line_transform.py @@ -1,7 +1,7 @@ import cv2 as cv import numpy as np -img = cv.imread('../data/sudoku.png') +img = cv.imread(cv.samples.findFile('sudoku.png')) gray = cv.cvtColor(img,cv.COLOR_BGR2GRAY) edges = cv.Canny(gray,50,150,apertureSize = 3) lines = cv.HoughLinesP(edges,1,np.pi/180,100,minLineLength=100,maxLineGap=10) diff --git a/samples/python/tutorial_code/imgProc/opening_closing_hats/morphology_2.py b/samples/python/tutorial_code/imgProc/opening_closing_hats/morphology_2.py index 5dfdece1b6..e0fc758467 100644 --- a/samples/python/tutorial_code/imgProc/opening_closing_hats/morphology_2.py +++ b/samples/python/tutorial_code/imgProc/opening_closing_hats/morphology_2.py @@ -31,10 +31,10 @@ def morphology_operations(val): cv.imshow(title_window, dst) parser = argparse.ArgumentParser(description='Code for More Morphology Transformations tutorial.') -parser.add_argument('--input', help='Path to input image.', default='../data/LinuxLogo.jpg') +parser.add_argument('--input', help='Path to input image.', default='LinuxLogo.jpg') args = parser.parse_args() -src = cv.imread(args.input) +src = cv.imread(cv.samples.findFile(args.input)) if src is None: print('Could not open or find the image: ', args.input) exit(0) diff --git a/samples/python/tutorial_code/imgProc/threshold/threshold.py b/samples/python/tutorial_code/imgProc/threshold/threshold.py index 1ba38126c9..209ff75705 100644 --- a/samples/python/tutorial_code/imgProc/threshold/threshold.py +++ b/samples/python/tutorial_code/imgProc/threshold/threshold.py @@ -23,12 +23,12 @@ def Threshold_Demo(val): ## [Threshold_Demo] parser = argparse.ArgumentParser(description='Code for Basic Thresholding Operations tutorial.') -parser.add_argument('--input', help='Path to input image.', default='../data/stuff.jpg') +parser.add_argument('--input', help='Path to input image.', default='stuff.jpg') args = parser.parse_args() ## [load] # Load an image -src = cv.imread(args.input) +src = cv.imread(cv.samples.findFile(args.input)) if src is None: print('Could not open or find the image: ', args.input) exit(0) diff --git a/samples/python/tutorial_code/ml/introduction_to_pca/introduction_to_pca.py b/samples/python/tutorial_code/ml/introduction_to_pca/introduction_to_pca.py index af312d58f5..62c7516bf0 100644 --- a/samples/python/tutorial_code/ml/introduction_to_pca/introduction_to_pca.py +++ b/samples/python/tutorial_code/ml/introduction_to_pca/introduction_to_pca.py @@ -61,10 +61,10 @@ def getOrientation(pts, img): # Load image parser = argparse.ArgumentParser(description='Code for Introduction to Principal Component Analysis (PCA) tutorial.\ This program demonstrates how to use OpenCV PCA to extract the orientation of an object.') -parser.add_argument('--input', help='Path to input image.', default='../data/pca_test1.jpg') +parser.add_argument('--input', help='Path to input image.', default='pca_test1.jpg') args = parser.parse_args() -src = cv.imread(args.input) +src = cv.imread(cv.samples.findFile(args.input)) # Check if image is loaded successfully if src is None: print('Could not open or find the image: ', args.input) diff --git a/samples/python/tutorial_code/objectDetection/cascade_classifier/objectDetection.py b/samples/python/tutorial_code/objectDetection/cascade_classifier/objectDetection.py index 343c9d66fa..5ac5575a9e 100644 --- a/samples/python/tutorial_code/objectDetection/cascade_classifier/objectDetection.py +++ b/samples/python/tutorial_code/objectDetection/cascade_classifier/objectDetection.py @@ -23,8 +23,8 @@ def detectAndDisplay(frame): cv.imshow('Capture - Face detection', frame) parser = argparse.ArgumentParser(description='Code for Cascade Classifier tutorial.') -parser.add_argument('--face_cascade', help='Path to face cascade.', default='../../data/haarcascades/haarcascade_frontalface_alt.xml') -parser.add_argument('--eyes_cascade', help='Path to eyes cascade.', default='../../data/haarcascades/haarcascade_eye_tree_eyeglasses.xml') +parser.add_argument('--face_cascade', help='Path to face cascade.', default='data/haarcascades/haarcascade_frontalface_alt.xml') +parser.add_argument('--eyes_cascade', help='Path to eyes cascade.', default='data/haarcascades/haarcascade_eye_tree_eyeglasses.xml') parser.add_argument('--camera', help='Camera devide number.', type=int, default=0) args = parser.parse_args() @@ -35,10 +35,10 @@ face_cascade = cv.CascadeClassifier() eyes_cascade = cv.CascadeClassifier() #-- 1. Load the cascades -if not face_cascade.load(face_cascade_name): +if not face_cascade.load(cv.samples.findFile(face_cascade_name)): print('--(!)Error loading face cascade') exit(0) -if not eyes_cascade.load(eyes_cascade_name): +if not eyes_cascade.load(cv.samples.findFile(eyes_cascade_name)): print('--(!)Error loading eyes cascade') exit(0) diff --git a/samples/python/tutorial_code/video/background_subtraction/bg_sub.py b/samples/python/tutorial_code/video/background_subtraction/bg_sub.py index dd14c11539..15330fc8b0 100644 --- a/samples/python/tutorial_code/video/background_subtraction/bg_sub.py +++ b/samples/python/tutorial_code/video/background_subtraction/bg_sub.py @@ -4,7 +4,7 @@ import argparse parser = argparse.ArgumentParser(description='This program shows how to use background subtraction methods provided by \ OpenCV. You can process both videos and images.') -parser.add_argument('--input', type=str, help='Path to a video or a sequence of image.', default='../data/vtest.avi') +parser.add_argument('--input', type=str, help='Path to a video or a sequence of image.', default='vtest.avi') parser.add_argument('--algo', type=str, help='Background subtraction method (KNN, MOG2).', default='MOG2') args = parser.parse_args() @@ -17,7 +17,7 @@ else: ## [create] ## [capture] -capture = cv.VideoCapture(args.input) +capture = cv.VideoCapture(cv.samples.findFileOrKeep(args.input)) if not capture.isOpened: print('Unable to open: ' + args.input) exit(0) diff --git a/samples/python/video.py b/samples/python/video.py index e4eb2d39e1..3a33e60f28 100755 --- a/samples/python/video.py +++ b/samples/python/video.py @@ -20,8 +20,8 @@ Usage: - synth: for procedural video Synth examples: - synth:bg=../data/lena.jpg:noise=0.1 - synth:class=chess:bg=../data/lena.jpg:noise=0.1:size=640x480 + synth:bg=lena.jpg:noise=0.1 + synth:class=chess:bg=lena.jpg:noise=0.1:size=640x480 Keys: ESC - exit @@ -49,7 +49,7 @@ class VideoSynthBase(object): self.bg = None self.frame_size = (640, 480) if bg is not None: - self.bg = cv.imread(bg, 1) + self.bg = cv.imread(cv.samples.findFile(bg)) h, w = self.bg.shape[:2] self.frame_size = (w, h) @@ -85,8 +85,8 @@ class VideoSynthBase(object): class Book(VideoSynthBase): def __init__(self, **kw): super(Book, self).__init__(**kw) - backGr = cv.imread('../data/graf1.png') - fgr = cv.imread('../data/box.png') + backGr = cv.imread(cv.samples.findFile('graf1.png')) + fgr = cv.imread(cv.samples.findFile('box.png')) self.render = TestSceneRender(backGr, fgr, speed = 1) def read(self, dst=None): @@ -98,7 +98,7 @@ class Book(VideoSynthBase): class Cube(VideoSynthBase): def __init__(self, **kw): super(Cube, self).__init__(**kw) - self.render = TestSceneRender(cv.imread('../data/pca_test1.jpg'), deformation = True, speed = 1) + self.render = TestSceneRender(cv.imread(cv.samples.findFile('pca_test1.jpg')), deformation = True, speed = 1) def read(self, dst=None): noise = np.zeros(self.render.sceneBg.shape, np.int8) @@ -158,10 +158,10 @@ classes = dict(chess=Chess, book=Book, cube=Cube) presets = dict( empty = 'synth:', - lena = 'synth:bg=../data/lena.jpg:noise=0.1', - chess = 'synth:class=chess:bg=../data/lena.jpg:noise=0.1:size=640x480', - book = 'synth:class=book:bg=../data/graf1.png:noise=0.1:size=640x480', - cube = 'synth:class=cube:bg=../data/pca_test1.jpg:noise=0.0:size=640x480' + lena = 'synth:bg=lena.jpg:noise=0.1', + chess = 'synth:class=chess:bg=lena.jpg:noise=0.1:size=640x480', + book = 'synth:class=book:bg=graf1.png:noise=0.1:size=640x480', + cube = 'synth:class=cube:bg=pca_test1.jpg:noise=0.0:size=640x480' ) diff --git a/samples/python/watershed.py b/samples/python/watershed.py index 9ca254ed8a..b2bfbddcf9 100755 --- a/samples/python/watershed.py +++ b/samples/python/watershed.py @@ -80,6 +80,6 @@ if __name__ == '__main__': try: fn = sys.argv[1] except: - fn = '../data/fruits.jpg' + fn = 'fruits.jpg' print(__doc__) - App(fn).run() + App(cv.samples.findFile(fn)).run()