samples: use findFile() in "python"

pull/12354/head
Alexander Alekhin 6 years ago committed by Alexander Alekhin
parent 9ea8c775f8
commit c371df4aa2
  1. 8
      samples/python/asift.py
  2. 2
      samples/python/browse.py
  3. 2
      samples/python/calibrate.py
  4. 4
      samples/python/camera_calibration_show_extrinsics.py
  5. 4
      samples/python/coherence.py
  6. 2
      samples/python/color_histogram.py
  7. 10
      samples/python/deconvolution.py
  8. 10
      samples/python/dft.py
  9. 7
      samples/python/digits.py
  10. 5
      samples/python/distrans.py
  11. 4
      samples/python/facedetect.py
  12. 8
      samples/python/find_obj.py
  13. 4
      samples/python/floodfill.py
  14. 4
      samples/python/gabor_threads.py
  15. 6
      samples/python/grabcut.py
  16. 4
      samples/python/hist.py
  17. 6
      samples/python/houghcircles.py
  18. 6
      samples/python/houghlines.py
  19. 4
      samples/python/inpaint.py
  20. 8
      samples/python/letter_recog.py
  21. 4
      samples/python/logpolar.py
  22. 4
      samples/python/morphology.py
  23. 2
      samples/python/peopledetect.py
  24. 4
      samples/python/stereo_match.py
  25. 4
      samples/python/texture_flow.py
  26. 4
      samples/python/tst_scene_render.py
  27. 4
      samples/python/tutorial_code/Histograms_Matching/histogram_calculation/calcHist_Demo.py
  28. 4
      samples/python/tutorial_code/Histograms_Matching/histogram_equalization/EqualizeHist_Demo.py
  29. 6
      samples/python/tutorial_code/ImgTrans/Filter2D/filter2D.py
  30. 4
      samples/python/tutorial_code/ImgTrans/HoughCircle/hough_circle.py
  31. 4
      samples/python/tutorial_code/ImgTrans/HoughLine/hough_lines.py
  32. 6
      samples/python/tutorial_code/ImgTrans/LaPlace/laplace_demo.py
  33. 6
      samples/python/tutorial_code/ImgTrans/MakeBorder/copy_make_border.py
  34. 4
      samples/python/tutorial_code/ImgTrans/canny_detector/CannyDetector_Demo.py
  35. 4
      samples/python/tutorial_code/ImgTrans/distance_transformation/imageSegmentation.py
  36. 4
      samples/python/tutorial_code/ImgTrans/remap/Remap_Demo.py
  37. 4
      samples/python/tutorial_code/ImgTrans/warp_affine/Geometric_Transforms_Demo.py
  38. 4
      samples/python/tutorial_code/ShapeDescriptors/bounding_rects_circles/generalContours_demo1.py
  39. 4
      samples/python/tutorial_code/ShapeDescriptors/bounding_rotated_ellipses/generalContours_demo2.py
  40. 4
      samples/python/tutorial_code/ShapeDescriptors/find_contours/findContours_demo.py
  41. 4
      samples/python/tutorial_code/ShapeDescriptors/hull/hull_demo.py
  42. 4
      samples/python/tutorial_code/ShapeDescriptors/moments/moments_demo.py
  43. 4
      samples/python/tutorial_code/TrackingMotion/corner_subpixels/cornerSubPix_Demo.py
  44. 4
      samples/python/tutorial_code/TrackingMotion/generic_corner_detector/cornerDetector_Demo.py
  45. 4
      samples/python/tutorial_code/TrackingMotion/good_features_to_track/goodFeaturesToTrack_Demo.py
  46. 4
      samples/python/tutorial_code/TrackingMotion/harris_detector/cornerHarris_Demo.py
  47. 4
      samples/python/tutorial_code/core/AddingImages/adding_images.py
  48. 6
      samples/python/tutorial_code/core/discrete_fourier_transform/discrete_fourier_transform.py
  49. 6
      samples/python/tutorial_code/core/mat_mask_operations/mat_mask_operations.py
  50. 12
      samples/python/tutorial_code/features2D/akaze_matching/AKAZE_match.py
  51. 8
      samples/python/tutorial_code/features2D/feature_description/SURF_matching_Demo.py
  52. 4
      samples/python/tutorial_code/features2D/feature_detection/SURF_detection_Demo.py
  53. 8
      samples/python/tutorial_code/features2D/feature_flann_matcher/SURF_FLANN_matching_Demo.py
  54. 8
      samples/python/tutorial_code/features2D/feature_homography/SURF_FLANN_matching_homography_Demo.py
  55. 8
      samples/python/tutorial_code/highgui/trackbar/AddingImagesTrackbar.py
  56. 4
      samples/python/tutorial_code/imgProc/Pyramids/pyramids.py
  57. 4
      samples/python/tutorial_code/imgProc/Smoothing/smoothing.py
  58. 4
      samples/python/tutorial_code/imgProc/changing_contrast_brightness_image/BasicLinearTransforms.py
  59. 4
      samples/python/tutorial_code/imgProc/changing_contrast_brightness_image/changing_contrast_brightness_image.py
  60. 4
      samples/python/tutorial_code/imgProc/erosion_dilatation/morphology_1.py
  61. 2
      samples/python/tutorial_code/imgProc/hough_line_transform/hough_line_transform.py
  62. 2
      samples/python/tutorial_code/imgProc/hough_line_transform/probabilistic_hough_line_transform.py
  63. 4
      samples/python/tutorial_code/imgProc/opening_closing_hats/morphology_2.py
  64. 4
      samples/python/tutorial_code/imgProc/threshold/threshold.py
  65. 4
      samples/python/tutorial_code/ml/introduction_to_pca/introduction_to_pca.py
  66. 8
      samples/python/tutorial_code/objectDetection/cascade_classifier/objectDetection.py
  67. 4
      samples/python/tutorial_code/video/background_subtraction/bg_sub.py
  68. 20
      samples/python/video.py
  69. 4
      samples/python/watershed.py

@ -116,11 +116,11 @@ if __name__ == '__main__':
try: try:
fn1, fn2 = args fn1, fn2 = args
except: except:
fn1 = '../data/aero1.jpg' fn1 = 'aero1.jpg'
fn2 = '../data/aero3.jpg' fn2 = 'aero3.jpg'
img1 = cv.imread(fn1, 0) img1 = cv.imread(cv.samples.findFile(fn1), cv.IMREAD_GRAYSCALE)
img2 = cv.imread(fn2, 0) img2 = cv.imread(cv.samples.findFile(fn2), cv.IMREAD_GRAYSCALE)
detector, matcher = init_feature(feature_name) detector, matcher = init_feature(feature_name)
if img1 is None: if img1 is None:

@ -32,7 +32,7 @@ if __name__ == '__main__':
print() print()
if len(sys.argv) > 1: if len(sys.argv) > 1:
fn = sys.argv[1] fn = cv.samples.findFile(sys.argv[1])
print('loading %s ...' % fn) print('loading %s ...' % fn)
img = cv.imread(fn) img = cv.imread(fn)
if img is None: if img is None:

@ -53,7 +53,7 @@ if __name__ == '__main__':
obj_points = [] obj_points = []
img_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): def processImage(fn):
print('processing %s... ' % fn) print('processing %s... ' % fn)

@ -160,7 +160,7 @@ def draw_camera_boards(ax, camera_matrix, cam_width, cam_height, scale_focal,
def main(): def main():
parser = argparse.ArgumentParser(description='Plot camera calibration extrinsics.', parser = argparse.ArgumentParser(description='Plot camera calibration extrinsics.',
formatter_class=argparse.ArgumentDefaultsHelpFormatter) 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.') help='YAML camera calibration file.')
parser.add_argument('--cam_width', type=float, default=0.064/2, parser.add_argument('--cam_width', type=float, default=0.064/2,
help='Width/2 of the displayed camera.') help='Width/2 of the displayed camera.')
@ -172,7 +172,7 @@ def main():
help='The calibration board is static and the camera is moving.') help='The calibration board is static and the camera is moving.')
args = parser.parse_args() 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_width = int(fs.getNode('board_width').real())
board_height = int(fs.getNode('board_height').real()) board_height = int(fs.getNode('board_height').real())
square_size = fs.getNode('square_size').real() square_size = fs.getNode('square_size').real()

@ -51,9 +51,9 @@ if __name__ == '__main__':
try: try:
fn = sys.argv[1] fn = sys.argv[1]
except: except:
fn = '../data/baboon.jpg' fn = 'baboon.jpg'
src = cv.imread(fn) src = cv.imread(cv.samples.findFile(fn))
def nothing(*argv): def nothing(*argv):
pass pass

@ -39,7 +39,7 @@ if __name__ == '__main__':
fn = sys.argv[1] fn = sys.argv[1]
except: except:
fn = 0 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: while True:
flag, frame = cam.read() flag, frame = cam.read()

@ -19,11 +19,11 @@ Usage:
ESC - exit ESC - exit
Examples: 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) (image source: http://www.topazlabs.com/infocus/_images/licenseplate_compare.jpg)
deconvolution.py --angle 86 --d 31 ../data/text_motion.jpg deconvolution.py --angle 86 --d 31 text_motion.jpg
deconvolution.py --circle --d 19 ../data/text_defocus.jpg deconvolution.py --circle --d 19 text_defocus.jpg
(image source: compact digital photo camera, no artificial distortion) (image source: compact digital photo camera, no artificial distortion)
@ -73,11 +73,11 @@ if __name__ == '__main__':
try: try:
fn = args[0] fn = args[0]
except: except:
fn = '../data/licenseplate_motion.jpg' fn = 'licenseplate_motion.jpg'
win = 'deconvolution' win = 'deconvolution'
img = cv.imread(fn, 0) img = cv.imread(cv.samples.findFile(fn), cv.IMREAD_GRAYSCALE)
if img is None: if img is None:
print('Failed to load file:', fn) print('Failed to load file:', fn)
sys.exit(1) sys.exit(1)

@ -38,8 +38,8 @@ def shift_dft(src, dst=None):
h, w = src.shape[:2] h, w = src.shape[:2]
cx1 = cx2 = w/2 cx1 = cx2 = w // 2
cy1 = cy2 = h/2 cy1 = cy2 = h // 2
# if the size is odd, then adjust the bottom/right quadrants # if the size is odd, then adjust the bottom/right quadrants
if w % 2 != 0: if w % 2 != 0:
@ -65,11 +65,13 @@ def shift_dft(src, dst=None):
if __name__ == "__main__": if __name__ == "__main__":
if len(sys.argv) > 1: if len(sys.argv) > 1:
im = cv.imread(sys.argv[1]) fname = sys.argv[1]
else: else:
im = cv.imread('../data/baboon.jpg') fname = 'baboon.jpg'
print("usage : python dft.py <image_file>") print("usage : python dft.py <image_file>")
im = cv.imread(cv.samples.findFile(fname))
# convert to grayscale # convert to grayscale
im = cv.cvtColor(im, cv.COLOR_BGR2GRAY) im = cv.cvtColor(im, cv.COLOR_BGR2GRAY)
h, w = im.shape[:2] h, w = im.shape[:2]

@ -3,7 +3,7 @@
''' '''
SVM and KNearest digit recognition. 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 Then it trains a SVM and KNearest classifiers on it and evaluates
their accuracy. their accuracy.
@ -42,7 +42,7 @@ from common import clock, mosaic
SZ = 20 # size of each digit is SZ x SZ SZ = 20 # size of each digit is SZ x SZ
CLASS_N = 10 CLASS_N = 10
DIGITS_FN = '../data/digits.png' DIGITS_FN = 'digits.png'
def split2d(img, cell_size, flatten=True): def split2d(img, cell_size, flatten=True):
h, w = img.shape[:2] h, w = img.shape[:2]
@ -54,8 +54,9 @@ def split2d(img, cell_size, flatten=True):
return cells return cells
def load_digits(fn): def load_digits(fn):
fn = cv.samples.findFile(fn)
print('loading "%s" ...' % 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)) digits = split2d(digits_img, (SZ, SZ))
labels = np.repeat(np.arange(CLASS_N), len(digits)/CLASS_N) labels = np.repeat(np.arange(CLASS_N), len(digits)/CLASS_N)
return digits, labels return digits, labels

@ -24,10 +24,11 @@ if __name__ == '__main__':
try: try:
fn = sys.argv[1] fn = sys.argv[1]
except: except:
fn = '../data/fruits.jpg' fn = 'fruits.jpg'
print(__doc__) print(__doc__)
img = cv.imread(fn, 0) fn = cv.samples.findFile(fn)
img = cv.imread(fn, cv.IMREAD_GRAYSCALE)
if img is None: if img is None:
print('Failed to load fn:', fn) print('Failed to load fn:', fn)
sys.exit(1) sys.exit(1)

@ -40,8 +40,8 @@ if __name__ == '__main__':
except: except:
video_src = 0 video_src = 0
args = dict(args) args = dict(args)
cascade_fn = args.get('--cascade', "../../data/haarcascades/haarcascade_frontalface_alt.xml") cascade_fn = args.get('--cascade', "data/haarcascades/haarcascade_frontalface_alt.xml")
nested_fn = args.get('--nested-cascade', "../../data/haarcascades/haarcascade_eye.xml") nested_fn = args.get('--nested-cascade', "data/haarcascades/haarcascade_eye.xml")
cascade = cv.CascadeClassifier(cv.samples.findFile(cascade_fn)) cascade = cv.CascadeClassifier(cv.samples.findFile(cascade_fn))
nested = cv.CascadeClassifier(cv.samples.findFile(nested_fn)) nested = cv.CascadeClassifier(cv.samples.findFile(nested_fn))

@ -147,11 +147,11 @@ if __name__ == '__main__':
try: try:
fn1, fn2 = args fn1, fn2 = args
except: except:
fn1 = '../data/box.png' fn1 = 'box.png'
fn2 = '../data/box_in_scene.png' fn2 = 'box_in_scene.png'
img1 = cv.imread(fn1, 0) img1 = cv.imread(cv.samples.findFile(fn1), cv.IMREAD_GRAYSCALE)
img2 = cv.imread(fn2, 0) img2 = cv.imread(cv.samples.findFile(fn2), cv.IMREAD_GRAYSCALE)
detector, matcher = init_feature(feature_name) detector, matcher = init_feature(feature_name)
if img1 is None: if img1 is None:

@ -25,10 +25,10 @@ if __name__ == '__main__':
try: try:
fn = sys.argv[1] fn = sys.argv[1]
except: except:
fn = '../data/fruits.jpg' fn = 'fruits.jpg'
print(__doc__) print(__doc__)
img = cv.imread(fn, True) img = cv.imread(cv.samples.findFile(fn))
if img is None: if img is None:
print('Failed to load image file:', fn) print('Failed to load image file:', fn)
sys.exit(1) sys.exit(1)

@ -55,9 +55,9 @@ if __name__ == '__main__':
try: try:
img_fn = sys.argv[1] img_fn = sys.argv[1]
except: 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: if img is None:
print('Failed to load image file:', img_fn) print('Failed to load image file:', img_fn)
sys.exit(1) sys.exit(1)

@ -107,11 +107,11 @@ if __name__ == '__main__':
if len(sys.argv) == 2: if len(sys.argv) == 2:
filename = sys.argv[1] # for drawing purposes filename = sys.argv[1] # for drawing purposes
else: 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 <filename> \n") print("Correct Usage: python grabcut.py <filename> \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 img2 = img.copy() # a copy of original image
mask = np.zeros(img.shape[:2],dtype = np.uint8) # mask initialized to PR_BG 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 output = np.zeros(img.shape,np.uint8) # output image to be shown

@ -60,10 +60,10 @@ if __name__ == '__main__':
if len(sys.argv)>1: if len(sys.argv)>1:
fname = sys.argv[1] fname = sys.argv[1]
else : else :
fname = '../data/lena.jpg' fname = 'lena.jpg'
print("usage : python hist.py <image_file>") print("usage : python hist.py <image_file>")
im = cv.imread(fname) im = cv.imread(cv.samples.findFile(fname))
if im is None: if im is None:
print('Failed to load image file:', fname) print('Failed to load image file:', fname)

@ -5,7 +5,7 @@ This example illustrates how to use cv.HoughCircles() function.
Usage: Usage:
houghcircles.py [<image_name>] houghcircles.py [<image_name>]
image argument defaults to ../data/board.jpg image argument defaults to board.jpg
''' '''
# Python 2/3 compatibility # Python 2/3 compatibility
@ -21,9 +21,9 @@ if __name__ == '__main__':
try: try:
fn = sys.argv[1] fn = sys.argv[1]
except IndexError: 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.cvtColor(src, cv.COLOR_BGR2GRAY)
img = cv.medianBlur(img, 5) img = cv.medianBlur(img, 5)
cimg = src.copy() # numpy function cimg = src.copy() # numpy function

@ -5,7 +5,7 @@ This example illustrates how to use Hough Transform to find lines
Usage: Usage:
houghlines.py [<image_name>] houghlines.py [<image_name>]
image argument defaults to ../data/pic1.png image argument defaults to pic1.png
''' '''
# Python 2/3 compatibility # Python 2/3 compatibility
@ -22,9 +22,9 @@ if __name__ == '__main__':
try: try:
fn = sys.argv[1] fn = sys.argv[1]
except IndexError: 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) dst = cv.Canny(src, 50, 200)
cdst = cv.cvtColor(dst, cv.COLOR_GRAY2BGR) cdst = cv.cvtColor(dst, cv.COLOR_GRAY2BGR)

@ -27,11 +27,11 @@ if __name__ == '__main__':
try: try:
fn = sys.argv[1] fn = sys.argv[1]
except: except:
fn = '../data/fruits.jpg' fn = 'fruits.jpg'
print(__doc__) print(__doc__)
img = cv.imread(fn) img = cv.imread(cv.samples.findFile(fn))
if img is None: if img is None:
print('Failed to load image file:', fn) print('Failed to load image file:', fn)
sys.exit(1) sys.exit(1)

@ -158,10 +158,12 @@ if __name__ == '__main__':
args, dummy = getopt.getopt(sys.argv[1:], '', ['model=', 'data=', 'load=', 'save=']) args, dummy = getopt.getopt(sys.argv[1:], '', ['model=', 'data=', 'load=', 'save='])
args = dict(args) args = dict(args)
args.setdefault('--model', 'svm') args.setdefault('--model', 'svm')
args.setdefault('--data', '../data/letter-recognition.data') args.setdefault('--data', 'letter-recognition.data')
print('loading data %s ...' % args['--data']) datafile = cv.samples.findFile(args['--data'])
samples, responses = load_base(args['--data'])
print('loading data %s ...' % datafile)
samples, responses = load_base(datafile)
Model = models[args['--model']] Model = models[args['--model']]
model = Model() model = Model()

@ -22,9 +22,9 @@ if __name__ == '__main__':
try: try:
fn = sys.argv[1] fn = sys.argv[1]
except IndexError: except IndexError:
fn = '../data/fruits.jpg' fn = 'fruits.jpg'
img = cv.imread(fn) img = cv.imread(cv.samples.findFile(fn))
if img is None: if img is None:
print('Failed to load image file:', fn) print('Failed to load image file:', fn)
sys.exit(1) sys.exit(1)

@ -31,9 +31,9 @@ if __name__ == '__main__':
try: try:
fn = sys.argv[1] fn = sys.argv[1]
except: except:
fn = '../data/baboon.jpg' fn = 'baboon.jpg'
img = cv.imread(fn) img = cv.imread(cv.samples.findFile(fn))
if img is None: if img is None:
print('Failed to load image file:', fn) print('Failed to load image file:', fn)

@ -40,7 +40,7 @@ if __name__ == '__main__':
hog = cv.HOGDescriptor() hog = cv.HOGDescriptor()
hog.setSVMDetector( cv.HOGDescriptor_getDefaultPeopleDetector() ) 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:])): for fn in it.chain(*map(glob, default + sys.argv[1:])):
print(fn, ' - ',) print(fn, ' - ',)

@ -35,8 +35,8 @@ def write_ply(fn, verts, colors):
if __name__ == '__main__': if __name__ == '__main__':
print('loading images...') print('loading images...')
imgL = cv.pyrDown( cv.imread('../data/aloeL.jpg') ) # downscale images for faster processing imgL = cv.pyrDown(cv.imread(cv.samples.findFile('aloeL.jpg'))) # downscale images for faster processing
imgR = cv.pyrDown( cv.imread('../data/aloeR.jpg') ) imgR = cv.pyrDown(cv.imread(cv.samples.findFile('aloeR.jpg')))
# disparity range is tuned for 'aloe' image pair # disparity range is tuned for 'aloe' image pair
window_size = 3 window_size = 3

@ -21,9 +21,9 @@ if __name__ == '__main__':
try: try:
fn = sys.argv[1] fn = sys.argv[1]
except: 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: if img is None:
print('Failed to load image file:', fn) print('Failed to load image file:', fn)
sys.exit(1) sys.exit(1)

@ -98,8 +98,8 @@ class TestSceneRender():
if __name__ == '__main__': if __name__ == '__main__':
backGr = cv.imread('../data/graf1.png') backGr = cv.imread(cv.samples.findFile('graf1.png'))
fgr = cv.imread('../data/box.png') fgr = cv.imread(cv.samples.findFile('box.png'))
render = TestSceneRender(backGr, fgr) render = TestSceneRender(backGr, fgr)

@ -6,10 +6,10 @@ import argparse
## [Load image] ## [Load image]
parser = argparse.ArgumentParser(description='Code for Histogram Calculation tutorial.') 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() args = parser.parse_args()
src = cv.imread(args.input) src = cv.imread(cv.samples.findFile(args.input))
if src is None: if src is None:
print('Could not open or find the image:', args.input) print('Could not open or find the image:', args.input)
exit(0) exit(0)

@ -4,10 +4,10 @@ import argparse
## [Load image] ## [Load image]
parser = argparse.ArgumentParser(description='Code for Histogram Equalization tutorial.') 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() args = parser.parse_args()
src = cv.imread(args.input) src = cv.imread(cv.samples.findFile(args.input))
if src is None: if src is None:
print('Could not open or find the image:', args.input) print('Could not open or find the image:', args.input)
exit(0) exit(0)

@ -11,15 +11,15 @@ def main(argv):
window_name = 'filter2D Demo' window_name = 'filter2D Demo'
## [load] ## [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 # 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 # Check if image is loaded fine
if src is None: if src is None:
print ('Error opening image!') 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 return -1
## [load] ## [load]
## [init_arguments] ## [init_arguments]

@ -5,11 +5,11 @@ import numpy as np
def main(argv): def main(argv):
## [load] ## [load]
default_file = "../../../../data/smarties.png" default_file = 'smarties.png'
filename = argv[0] if len(argv) > 0 else default_file filename = argv[0] if len(argv) > 0 else default_file
# Loads an image # 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 # Check if image is loaded fine
if src is None: if src is None:

@ -10,11 +10,11 @@ import numpy as np
def main(argv): def main(argv):
## [load] ## [load]
default_file = "../../../../data/sudoku.png" default_file = 'sudoku.png'
filename = argv[0] if len(argv) > 0 else default_file filename = argv[0] if len(argv) > 0 else default_file
# Loads an image # 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 # Check if image is loaded fine
if src is None: if src is None:

@ -14,14 +14,14 @@ def main(argv):
# [variables] # [variables]
# [load] # [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 # Check if image is loaded fine
if src is None: if src is None:
print ('Error opening image') print ('Error opening image')
print ('Program Arguments: [image_name -- default ../data/lena.jpg]') print ('Program Arguments: [image_name -- default lena.jpg]')
return -1 return -1
# [load] # [load]

@ -14,15 +14,15 @@ def main(argv):
window_name = "copyMakeBorder Demo" window_name = "copyMakeBorder Demo"
## [variables] ## [variables]
## [load] ## [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 # 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 # Check if image is loaded fine
if src is None: if src is None:
print ('Error opening image!') 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 return -1
## [load] ## [load]
# Brief how-to for this program # Brief how-to for this program

@ -17,10 +17,10 @@ def CannyThreshold(val):
cv.imshow(window_name, dst) cv.imshow(window_name, dst)
parser = argparse.ArgumentParser(description='Code for Canny Edge Detector tutorial.') 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() args = parser.parse_args()
src = cv.imread(args.input) src = cv.imread(cv.samples.findFile(args.input))
if src is None: if src is None:
print('Could not open or find the image: ', args.input) print('Could not open or find the image: ', args.input)
exit(0) exit(0)

@ -11,10 +11,10 @@ rng.seed(12345)
parser = argparse.ArgumentParser(description='Code for Image Segmentation with Distance Transform and Watershed Algorithm.\ 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, \ Sample code showing how to segment overlapping objects using Laplacian filtering, \
in addition to Watershed and Distance Transformation') 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() args = parser.parse_args()
src = cv.imread(args.input) src = cv.imread(cv.samples.findFile(args.input))
if src is None: if src is None:
print('Could not open or find the image:', args.input) print('Could not open or find the image:', args.input)
exit(0) exit(0)

@ -32,11 +32,11 @@ def update_map(ind, map_x, map_y):
## [Update] ## [Update]
parser = argparse.ArgumentParser(description='Code for Remapping tutorial.') 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() args = parser.parse_args()
## [Load] ## [Load]
src = cv.imread(args.input, cv.IMREAD_COLOR) src = cv.imread(cv.samples.findFile(args.input), cv.IMREAD_COLOR)
if src is None: if src is None:
print('Could not open or find the image: ', args.input) print('Could not open or find the image: ', args.input)
exit(0) exit(0)

@ -5,10 +5,10 @@ import argparse
## [Load the image] ## [Load the image]
parser = argparse.ArgumentParser(description='Code for Affine Transformations tutorial.') 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() args = parser.parse_args()
src = cv.imread(args.input) src = cv.imread(cv.samples.findFile(args.input))
if src is None: if src is None:
print('Could not open or find the image:', args.input) print('Could not open or find the image:', args.input)
exit(0) exit(0)

@ -53,10 +53,10 @@ def thresh_callback(val):
## [setup] ## [setup]
# Load source image # Load source image
parser = argparse.ArgumentParser(description='Code for Creating Bounding boxes and circles for contours tutorial.') 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() args = parser.parse_args()
src = cv.imread(args.input) src = cv.imread(cv.samples.findFile(args.input))
if src is None: if src is None:
print('Could not open or find the image:', args.input) print('Could not open or find the image:', args.input)
exit(0) exit(0)

@ -53,10 +53,10 @@ def thresh_callback(val):
## [setup] ## [setup]
# Load source image # Load source image
parser = argparse.ArgumentParser(description='Code for Creating Bounding rotated boxes and ellipses for contours tutorial.') 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() args = parser.parse_args()
src = cv.imread(args.input) src = cv.imread(cv.samples.findFile(args.input))
if src is None: if src is None:
print('Could not open or find the image:', args.input) print('Could not open or find the image:', args.input)
exit(0) exit(0)

@ -26,10 +26,10 @@ def thresh_callback(val):
# Load source image # Load source image
parser = argparse.ArgumentParser(description='Code for Finding contours in your image tutorial.') 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() args = parser.parse_args()
src = cv.imread(args.input) src = cv.imread(cv.samples.findFile(args.input))
if src is None: if src is None:
print('Could not open or find the image:', args.input) print('Could not open or find the image:', args.input)
exit(0) exit(0)

@ -33,10 +33,10 @@ def thresh_callback(val):
# Load source image # Load source image
parser = argparse.ArgumentParser(description='Code for Convex Hull tutorial.') 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() args = parser.parse_args()
src = cv.imread(args.input) src = cv.imread(cv.samples.findFile(args.input))
if src is None: if src is None:
print('Could not open or find the image:', args.input) print('Could not open or find the image:', args.input)
exit(0) exit(0)

@ -54,10 +54,10 @@ def thresh_callback(val):
## [setup] ## [setup]
# Load source image # Load source image
parser = argparse.ArgumentParser(description='Code for Image Moments tutorial.') 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() args = parser.parse_args()
src = cv.imread(args.input) src = cv.imread(cv.samples.findFile(args.input))
if src is None: if src is None:
print('Could not open or find the image:', args.input) print('Could not open or find the image:', args.input)
exit(0) exit(0)

@ -50,10 +50,10 @@ def goodFeaturesToTrack_Demo(val):
# Load source image and convert it to gray # Load source image and convert it to gray
parser = argparse.ArgumentParser(description='Code for Shi-Tomasi corner detector tutorial.') 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() args = parser.parse_args()
src = cv.imread(args.input) src = cv.imread(cv.samples.findFile(args.input))
if src is None: if src is None:
print('Could not open or find the image:', args.input) print('Could not open or find the image:', args.input)
exit(0) exit(0)

@ -35,10 +35,10 @@ def myShiTomasi_function(val):
# Load source image and convert it to gray # Load source image and convert it to gray
parser = argparse.ArgumentParser(description='Code for Creating your own corner detector tutorial.') 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() args = parser.parse_args()
src = cv.imread(args.input) src = cv.imread(cv.samples.findFile(args.input))
if src is None: if src is None:
print('Could not open or find the image:', args.input) print('Could not open or find the image:', args.input)
exit(0) exit(0)

@ -38,10 +38,10 @@ def goodFeaturesToTrack_Demo(val):
# Load source image and convert it to gray # Load source image and convert it to gray
parser = argparse.ArgumentParser(description='Code for Shi-Tomasi corner detector tutorial.') 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() args = parser.parse_args()
src = cv.imread(args.input) src = cv.imread(cv.samples.findFile(args.input))
if src is None: if src is None:
print('Could not open or find the image:', args.input) print('Could not open or find the image:', args.input)
exit(0) exit(0)

@ -35,10 +35,10 @@ def cornerHarris_demo(val):
# Load source image and convert it to gray # Load source image and convert it to gray
parser = argparse.ArgumentParser(description='Code for Harris corner detector tutorial.') 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() args = parser.parse_args()
src = cv.imread(args.input) src = cv.imread(cv.samples.findFile(args.input))
if src is None: if src is None:
print('Could not open or find the image:', args.input) print('Could not open or find the image:', args.input)
exit(0) exit(0)

@ -16,8 +16,8 @@ input_alpha = float(raw_input().strip())
if 0 <= alpha <= 1: if 0 <= alpha <= 1:
alpha = input_alpha alpha = input_alpha
# [load] # [load]
src1 = cv.imread('../../../../data/LinuxLogo.jpg') src1 = cv.imread(cv.samples.findFile('LinuxLogo.jpg'))
src2 = cv.imread('../../../../data/WindowsLogo.jpg') src2 = cv.imread(cv.samples.findFile('WindowsLogo.jpg'))
# [load] # [load]
if src1 is None: if src1 is None:
print("Error loading src1") print("Error loading src1")

@ -10,16 +10,16 @@ def print_help():
This program demonstrated the use of the discrete Fourier transform (DFT). 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. The dft of an image is taken and it's power spectrum is displayed.
Usage: Usage:
discrete_fourier_transform.py [image_name -- default ../../../../data/lena.jpg]''') discrete_fourier_transform.py [image_name -- default lena.jpg]''')
def main(argv): def main(argv):
print_help() 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: if I is None:
print('Error opening image') print('Error opening image')
return -1 return -1

@ -45,7 +45,7 @@ def sharpen(my_image):
## [basic_method] ## [basic_method]
def main(argv): def main(argv):
filename = "../../../../data/lena.jpg" filename = 'lena.jpg'
img_codec = cv.IMREAD_COLOR img_codec = cv.IMREAD_COLOR
if argv: if argv:
@ -53,12 +53,12 @@ def main(argv):
if len(argv) >= 2 and sys.argv[2] == "G": if len(argv) >= 2 and sys.argv[2] == "G":
img_codec = cv.IMREAD_GRAYSCALE img_codec = cv.IMREAD_GRAYSCALE
src = cv.imread(filename, img_codec) src = cv.imread(cv.samples.findFile(filename), img_codec)
if src is None: if src is None:
print("Can't open image [" + filename + "]") print("Can't open image [" + filename + "]")
print("Usage:") 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 return -1
cv.namedWindow("Input", cv.WINDOW_AUTOSIZE) cv.namedWindow("Input", cv.WINDOW_AUTOSIZE)

@ -6,18 +6,18 @@ from math import sqrt
## [load] ## [load]
parser = argparse.ArgumentParser(description='Code for AKAZE local features matching tutorial.') 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('--input1', help='Path to input image 1.', default='graf1.png')
parser.add_argument('--input2', help='Path to input image 2.', default='../data/graf3.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='../data/H1to3p.xml') parser.add_argument('--homography', help='Path to the homography matrix.', default='H1to3p.xml')
args = parser.parse_args() args = parser.parse_args()
img1 = cv.imread(args.input1, cv.IMREAD_GRAYSCALE) img1 = cv.imread(cv.samples.findFile(args.input1), cv.IMREAD_GRAYSCALE)
img2 = cv.imread(args.input2, cv.IMREAD_GRAYSCALE) img2 = cv.imread(cv.samples.findFile(args.input2), cv.IMREAD_GRAYSCALE)
if img1 is None or img2 is None: if img1 is None or img2 is None:
print('Could not open or find the images!') print('Could not open or find the images!')
exit(0) 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() homography = fs.getFirstTopLevelNode().mat()
## [load] ## [load]

@ -4,12 +4,12 @@ import numpy as np
import argparse import argparse
parser = argparse.ArgumentParser(description='Code for Feature Detection tutorial.') 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('--input1', help='Path to input image 1.', default='box.png')
parser.add_argument('--input2', help='Path to input image 2.', default='../data/box_in_scene.png') parser.add_argument('--input2', help='Path to input image 2.', default='box_in_scene.png')
args = parser.parse_args() args = parser.parse_args()
img1 = cv.imread(args.input1, cv.IMREAD_GRAYSCALE) img1 = cv.imread(cv.samples.findFile(args.input1), cv.IMREAD_GRAYSCALE)
img2 = cv.imread(args.input2, cv.IMREAD_GRAYSCALE) img2 = cv.imread(cv.samples.findFile(args.input2), cv.IMREAD_GRAYSCALE)
if img1 is None or img2 is None: if img1 is None or img2 is None:
print('Could not open or find the images!') print('Could not open or find the images!')
exit(0) exit(0)

@ -4,10 +4,10 @@ import numpy as np
import argparse import argparse
parser = argparse.ArgumentParser(description='Code for Feature Detection tutorial.') 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() 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: if src is None:
print('Could not open or find the image:', args.input) print('Could not open or find the image:', args.input)
exit(0) exit(0)

@ -4,12 +4,12 @@ import numpy as np
import argparse import argparse
parser = argparse.ArgumentParser(description='Code for Feature Matching with FLANN tutorial.') 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('--input1', help='Path to input image 1.', default='box.png')
parser.add_argument('--input2', help='Path to input image 2.', default='../data/box_in_scene.png') parser.add_argument('--input2', help='Path to input image 2.', default='box_in_scene.png')
args = parser.parse_args() args = parser.parse_args()
img1 = cv.imread(args.input1, cv.IMREAD_GRAYSCALE) img1 = cv.imread(cv.samples.findFile(args.input1), cv.IMREAD_GRAYSCALE)
img2 = cv.imread(args.input2, cv.IMREAD_GRAYSCALE) img2 = cv.imread(cv.samples.findFile(args.input2), cv.IMREAD_GRAYSCALE)
if img1 is None or img2 is None: if img1 is None or img2 is None:
print('Could not open or find the images!') print('Could not open or find the images!')
exit(0) exit(0)

@ -4,12 +4,12 @@ import numpy as np
import argparse import argparse
parser = argparse.ArgumentParser(description='Code for Feature Matching with FLANN tutorial.') 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('--input1', help='Path to input image 1.', default='box.png')
parser.add_argument('--input2', help='Path to input image 2.', default='../data/box_in_scene.png') parser.add_argument('--input2', help='Path to input image 2.', default='box_in_scene.png')
args = parser.parse_args() args = parser.parse_args()
img_object = cv.imread(args.input1, cv.IMREAD_GRAYSCALE) img_object = cv.imread(cv.samples.findFile(args.input1), cv.IMREAD_GRAYSCALE)
img_scene = cv.imread(args.input2, 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: if img_object is None or img_scene is None:
print('Could not open or find the images!') print('Could not open or find the images!')
exit(0) exit(0)

@ -15,14 +15,14 @@ def on_trackbar(val):
## [on_trackbar] ## [on_trackbar]
parser = argparse.ArgumentParser(description='Code for Adding a Trackbar to our applications tutorial.') 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('--input1', help='Path to the first input image.', default='LinuxLogo.jpg')
parser.add_argument('--input2', help='Path to the second input image.', default='../data/WindowsLogo.jpg') parser.add_argument('--input2', help='Path to the second input image.', default='WindowsLogo.jpg')
args = parser.parse_args() args = parser.parse_args()
## [load] ## [load]
# Read images ( both have to be of the same size and type ) # Read images ( both have to be of the same size and type )
src1 = cv.imread(args.input1) src1 = cv.imread(cv.samples.findFile(args.input1))
src2 = cv.imread(args.input2) src2 = cv.imread(cv.samples.findFile(args.input2))
## [load] ## [load]
if src1 is None: if src1 is None:
print('Could not open or find the image: ', args.input1) print('Could not open or find the image: ', args.input1)

@ -11,10 +11,10 @@ def main(argv):
* [ESC] -> Close program * [ESC] -> Close program
""") """)
## [load] ## [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 # Load the image
src = cv.imread(filename) src = cv.imread(cv.samples.findFile(filename))
# Check if image is loaded fine # Check if image is loaded fine
if src is None: if src is None:

@ -17,10 +17,10 @@ def main(argv):
cv.namedWindow(window_name, cv.WINDOW_AUTOSIZE) cv.namedWindow(window_name, cv.WINDOW_AUTOSIZE)
# Load the source image # 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 global src
src = cv.imread(imageName, 1) src = cv.imread(cv.samples.findFile(imageName))
if src is None: if src is None:
print ('Error opening image') print ('Error opening image')
print ('Usage: smoothing.py [image_name -- default ../data/lena.jpg] \n') print ('Usage: smoothing.py [image_name -- default ../data/lena.jpg] \n')

@ -7,10 +7,10 @@ import argparse
# Read image given by user # Read image given by user
## [basic-linear-transform-load] ## [basic-linear-transform-load]
parser = argparse.ArgumentParser(description='Code for Changing the contrast and brightness of an image! tutorial.') 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() args = parser.parse_args()
image = cv.imread(args.input) image = cv.imread(cv.samples.findFile(args.input))
if image is None: if image is None:
print('Could not open or find the image: ', args.input) print('Could not open or find the image: ', args.input)
exit(0) exit(0)

@ -44,10 +44,10 @@ def on_gamma_correction_trackbar(val):
gammaCorrection() gammaCorrection()
parser = argparse.ArgumentParser(description='Code for Changing the contrast and brightness of an image! tutorial.') 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() args = parser.parse_args()
img_original = cv.imread(args.input) img_original = cv.imread(cv.samples.findFile(args.input))
if img_original is None: if img_original is None:
print('Could not open or find the image: ', args.input) print('Could not open or find the image: ', args.input)
exit(0) exit(0)

@ -42,10 +42,10 @@ def dilatation(val):
cv.imshow(title_dilatation_window, dilatation_dst) cv.imshow(title_dilatation_window, dilatation_dst)
parser = argparse.ArgumentParser(description='Code for Eroding and Dilating tutorial.') 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() args = parser.parse_args()
src = cv.imread(args.input) src = cv.imread(cv.samples.findFile(args.input))
if src is None: if src is None:
print('Could not open or find the image: ', args.input) print('Could not open or find the image: ', args.input)
exit(0) exit(0)

@ -1,7 +1,7 @@
import cv2 as cv import cv2 as cv
import numpy as np 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) gray = cv.cvtColor(img,cv.COLOR_BGR2GRAY)
edges = cv.Canny(gray,50,150,apertureSize = 3) edges = cv.Canny(gray,50,150,apertureSize = 3)

@ -1,7 +1,7 @@
import cv2 as cv import cv2 as cv
import numpy as np 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) gray = cv.cvtColor(img,cv.COLOR_BGR2GRAY)
edges = cv.Canny(gray,50,150,apertureSize = 3) edges = cv.Canny(gray,50,150,apertureSize = 3)
lines = cv.HoughLinesP(edges,1,np.pi/180,100,minLineLength=100,maxLineGap=10) lines = cv.HoughLinesP(edges,1,np.pi/180,100,minLineLength=100,maxLineGap=10)

@ -31,10 +31,10 @@ def morphology_operations(val):
cv.imshow(title_window, dst) cv.imshow(title_window, dst)
parser = argparse.ArgumentParser(description='Code for More Morphology Transformations tutorial.') 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() args = parser.parse_args()
src = cv.imread(args.input) src = cv.imread(cv.samples.findFile(args.input))
if src is None: if src is None:
print('Could not open or find the image: ', args.input) print('Could not open or find the image: ', args.input)
exit(0) exit(0)

@ -23,12 +23,12 @@ def Threshold_Demo(val):
## [Threshold_Demo] ## [Threshold_Demo]
parser = argparse.ArgumentParser(description='Code for Basic Thresholding Operations tutorial.') 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() args = parser.parse_args()
## [load] ## [load]
# Load an image # Load an image
src = cv.imread(args.input) src = cv.imread(cv.samples.findFile(args.input))
if src is None: if src is None:
print('Could not open or find the image: ', args.input) print('Could not open or find the image: ', args.input)
exit(0) exit(0)

@ -61,10 +61,10 @@ def getOrientation(pts, img):
# Load image # Load image
parser = argparse.ArgumentParser(description='Code for Introduction to Principal Component Analysis (PCA) tutorial.\ 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.') 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() args = parser.parse_args()
src = cv.imread(args.input) src = cv.imread(cv.samples.findFile(args.input))
# Check if image is loaded successfully # Check if image is loaded successfully
if src is None: if src is None:
print('Could not open or find the image: ', args.input) print('Could not open or find the image: ', args.input)

@ -23,8 +23,8 @@ def detectAndDisplay(frame):
cv.imshow('Capture - Face detection', frame) cv.imshow('Capture - Face detection', frame)
parser = argparse.ArgumentParser(description='Code for Cascade Classifier tutorial.') 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('--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('--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) parser.add_argument('--camera', help='Camera devide number.', type=int, default=0)
args = parser.parse_args() args = parser.parse_args()
@ -35,10 +35,10 @@ face_cascade = cv.CascadeClassifier()
eyes_cascade = cv.CascadeClassifier() eyes_cascade = cv.CascadeClassifier()
#-- 1. Load the cascades #-- 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') print('--(!)Error loading face cascade')
exit(0) 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') print('--(!)Error loading eyes cascade')
exit(0) exit(0)

@ -4,7 +4,7 @@ import argparse
parser = argparse.ArgumentParser(description='This program shows how to use background subtraction methods provided by \ parser = argparse.ArgumentParser(description='This program shows how to use background subtraction methods provided by \
OpenCV. You can process both videos and images.') 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') parser.add_argument('--algo', type=str, help='Background subtraction method (KNN, MOG2).', default='MOG2')
args = parser.parse_args() args = parser.parse_args()
@ -17,7 +17,7 @@ else:
## [create] ## [create]
## [capture] ## [capture]
capture = cv.VideoCapture(args.input) capture = cv.VideoCapture(cv.samples.findFileOrKeep(args.input))
if not capture.isOpened: if not capture.isOpened:
print('Unable to open: ' + args.input) print('Unable to open: ' + args.input)
exit(0) exit(0)

@ -20,8 +20,8 @@ Usage:
- synth:<params> for procedural video - synth:<params> for procedural video
Synth examples: Synth examples:
synth:bg=../data/lena.jpg:noise=0.1 synth:bg=lena.jpg:noise=0.1
synth:class=chess:bg=../data/lena.jpg:noise=0.1:size=640x480 synth:class=chess:bg=lena.jpg:noise=0.1:size=640x480
Keys: Keys:
ESC - exit ESC - exit
@ -49,7 +49,7 @@ class VideoSynthBase(object):
self.bg = None self.bg = None
self.frame_size = (640, 480) self.frame_size = (640, 480)
if bg is not None: 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] h, w = self.bg.shape[:2]
self.frame_size = (w, h) self.frame_size = (w, h)
@ -85,8 +85,8 @@ class VideoSynthBase(object):
class Book(VideoSynthBase): class Book(VideoSynthBase):
def __init__(self, **kw): def __init__(self, **kw):
super(Book, self).__init__(**kw) super(Book, self).__init__(**kw)
backGr = cv.imread('../data/graf1.png') backGr = cv.imread(cv.samples.findFile('graf1.png'))
fgr = cv.imread('../data/box.png') fgr = cv.imread(cv.samples.findFile('box.png'))
self.render = TestSceneRender(backGr, fgr, speed = 1) self.render = TestSceneRender(backGr, fgr, speed = 1)
def read(self, dst=None): def read(self, dst=None):
@ -98,7 +98,7 @@ class Book(VideoSynthBase):
class Cube(VideoSynthBase): class Cube(VideoSynthBase):
def __init__(self, **kw): def __init__(self, **kw):
super(Cube, self).__init__(**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): def read(self, dst=None):
noise = np.zeros(self.render.sceneBg.shape, np.int8) noise = np.zeros(self.render.sceneBg.shape, np.int8)
@ -158,10 +158,10 @@ classes = dict(chess=Chess, book=Book, cube=Cube)
presets = dict( presets = dict(
empty = 'synth:', empty = 'synth:',
lena = 'synth:bg=../data/lena.jpg:noise=0.1', lena = 'synth:bg=lena.jpg:noise=0.1',
chess = 'synth:class=chess:bg=../data/lena.jpg:noise=0.1:size=640x480', chess = 'synth:class=chess:bg=lena.jpg:noise=0.1:size=640x480',
book = 'synth:class=book:bg=../data/graf1.png:noise=0.1:size=640x480', book = 'synth:class=book:bg=graf1.png:noise=0.1:size=640x480',
cube = 'synth:class=cube:bg=../data/pca_test1.jpg:noise=0.0:size=640x480' cube = 'synth:class=cube:bg=pca_test1.jpg:noise=0.0:size=640x480'
) )

@ -80,6 +80,6 @@ if __name__ == '__main__':
try: try:
fn = sys.argv[1] fn = sys.argv[1]
except: except:
fn = '../data/fruits.jpg' fn = 'fruits.jpg'
print(__doc__) print(__doc__)
App(fn).run() App(cv.samples.findFile(fn)).run()

Loading…
Cancel
Save