Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
c371df4a
Commit
c371df4a
authored
Nov 14, 2018
by
Alexander Alekhin
Committed by
Alexander Alekhin
Nov 16, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
samples: use findFile() in "python"
parent
9ea8c775
Hide whitespace changes
Inline
Side-by-side
Showing
69 changed files
with
179 additions
and
173 deletions
+179
-173
asift.py
samples/python/asift.py
+4
-4
browse.py
samples/python/browse.py
+1
-1
calibrate.py
samples/python/calibrate.py
+1
-1
camera_calibration_show_extrinsics.py
samples/python/camera_calibration_show_extrinsics.py
+2
-2
coherence.py
samples/python/coherence.py
+2
-2
color_histogram.py
samples/python/color_histogram.py
+1
-1
deconvolution.py
samples/python/deconvolution.py
+5
-5
dft.py
samples/python/dft.py
+6
-4
digits.py
samples/python/digits.py
+4
-3
distrans.py
samples/python/distrans.py
+3
-2
facedetect.py
samples/python/facedetect.py
+2
-2
find_obj.py
samples/python/find_obj.py
+4
-4
floodfill.py
samples/python/floodfill.py
+2
-2
gabor_threads.py
samples/python/gabor_threads.py
+2
-2
grabcut.py
samples/python/grabcut.py
+3
-3
hist.py
samples/python/hist.py
+2
-2
houghcircles.py
samples/python/houghcircles.py
+3
-3
houghlines.py
samples/python/houghlines.py
+3
-3
inpaint.py
samples/python/inpaint.py
+2
-2
letter_recog.py
samples/python/letter_recog.py
+5
-3
logpolar.py
samples/python/logpolar.py
+2
-2
morphology.py
samples/python/morphology.py
+2
-2
peopledetect.py
samples/python/peopledetect.py
+1
-1
stereo_match.py
samples/python/stereo_match.py
+2
-2
texture_flow.py
samples/python/texture_flow.py
+2
-2
tst_scene_render.py
samples/python/tst_scene_render.py
+2
-2
calcHist_Demo.py
...istograms_Matching/histogram_calculation/calcHist_Demo.py
+2
-2
EqualizeHist_Demo.py
...rams_Matching/histogram_equalization/EqualizeHist_Demo.py
+2
-2
filter2D.py
samples/python/tutorial_code/ImgTrans/Filter2D/filter2D.py
+3
-3
hough_circle.py
...python/tutorial_code/ImgTrans/HoughCircle/hough_circle.py
+2
-2
hough_lines.py
...es/python/tutorial_code/ImgTrans/HoughLine/hough_lines.py
+2
-2
laplace_demo.py
...les/python/tutorial_code/ImgTrans/LaPlace/laplace_demo.py
+3
-3
copy_make_border.py
...hon/tutorial_code/ImgTrans/MakeBorder/copy_make_border.py
+3
-3
CannyDetector_Demo.py
...torial_code/ImgTrans/canny_detector/CannyDetector_Demo.py
+2
-2
imageSegmentation.py
...ode/ImgTrans/distance_transformation/imageSegmentation.py
+2
-2
Remap_Demo.py
samples/python/tutorial_code/ImgTrans/remap/Remap_Demo.py
+2
-2
Geometric_Transforms_Demo.py
...al_code/ImgTrans/warp_affine/Geometric_Transforms_Demo.py
+2
-2
generalContours_demo1.py
...scriptors/bounding_rects_circles/generalContours_demo1.py
+2
-2
generalContours_demo2.py
...iptors/bounding_rotated_ellipses/generalContours_demo2.py
+2
-2
findContours_demo.py
..._code/ShapeDescriptors/find_contours/findContours_demo.py
+2
-2
hull_demo.py
...s/python/tutorial_code/ShapeDescriptors/hull/hull_demo.py
+2
-2
moments_demo.py
...on/tutorial_code/ShapeDescriptors/moments/moments_demo.py
+2
-2
cornerSubPix_Demo.py
...code/TrackingMotion/corner_subpixels/cornerSubPix_Demo.py
+2
-2
cornerDetector_Demo.py
...kingMotion/generic_corner_detector/cornerDetector_Demo.py
+2
-2
goodFeaturesToTrack_Demo.py
...Motion/good_features_to_track/goodFeaturesToTrack_Demo.py
+2
-2
cornerHarris_Demo.py
..._code/TrackingMotion/harris_detector/cornerHarris_Demo.py
+2
-2
adding_images.py
...s/python/tutorial_code/core/AddingImages/adding_images.py
+2
-2
discrete_fourier_transform.py
.../discrete_fourier_transform/discrete_fourier_transform.py
+3
-3
mat_mask_operations.py
...rial_code/core/mat_mask_operations/mat_mask_operations.py
+3
-3
AKAZE_match.py
...on/tutorial_code/features2D/akaze_matching/AKAZE_match.py
+6
-6
SURF_matching_Demo.py
...code/features2D/feature_description/SURF_matching_Demo.py
+4
-4
SURF_detection_Demo.py
..._code/features2D/feature_detection/SURF_detection_Demo.py
+2
-2
SURF_FLANN_matching_Demo.py
...tures2D/feature_flann_matcher/SURF_FLANN_matching_Demo.py
+4
-4
SURF_FLANN_matching_homography_Demo.py
...feature_homography/SURF_FLANN_matching_homography_Demo.py
+4
-4
AddingImagesTrackbar.py
...on/tutorial_code/highgui/trackbar/AddingImagesTrackbar.py
+4
-4
pyramids.py
samples/python/tutorial_code/imgProc/Pyramids/pyramids.py
+2
-2
smoothing.py
samples/python/tutorial_code/imgProc/Smoothing/smoothing.py
+2
-2
BasicLinearTransforms.py
...anging_contrast_brightness_image/BasicLinearTransforms.py
+2
-2
changing_contrast_brightness_image.py
...st_brightness_image/changing_contrast_brightness_image.py
+2
-2
morphology_1.py
.../tutorial_code/imgProc/erosion_dilatation/morphology_1.py
+2
-2
hough_line_transform.py
...code/imgProc/hough_line_transform/hough_line_transform.py
+1
-1
probabilistic_hough_line_transform.py
...ough_line_transform/probabilistic_hough_line_transform.py
+1
-1
morphology_2.py
...utorial_code/imgProc/opening_closing_hats/morphology_2.py
+2
-2
threshold.py
samples/python/tutorial_code/imgProc/threshold/threshold.py
+2
-2
introduction_to_pca.py
...torial_code/ml/introduction_to_pca/introduction_to_pca.py
+2
-2
objectDetection.py
...ode/objectDetection/cascade_classifier/objectDetection.py
+4
-4
bg_sub.py
...thon/tutorial_code/video/background_subtraction/bg_sub.py
+2
-2
video.py
samples/python/video.py
+10
-10
watershed.py
samples/python/watershed.py
+2
-2
No files found.
samples/python/asift.py
View file @
c371df4a
...
...
@@ -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
:
...
...
samples/python/browse.py
View file @
c371df4a
...
...
@@ -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
:
...
...
samples/python/calibrate.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/camera_calibration_show_extrinsics.py
View file @
c371df4a
...
...
@@ -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
()
...
...
samples/python/coherence.py
View file @
c371df4a
...
...
@@ -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
...
...
samples/python/color_histogram.py
View file @
c371df4a
...
...
@@ -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
()
...
...
samples/python/deconvolution.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/dft.py
View file @
c371df4a
...
...
@@ -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 <image_file>"
)
im
=
cv
.
imread
(
cv
.
samples
.
findFile
(
fname
))
# convert to grayscale
im
=
cv
.
cvtColor
(
im
,
cv
.
COLOR_BGR2GRAY
)
h
,
w
=
im
.
shape
[:
2
]
...
...
samples/python/digits.py
View file @
c371df4a
...
...
@@ -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
...
...
samples/python/distrans.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/facedetect.py
View file @
c371df4a
...
...
@@ -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
))
...
...
samples/python/find_obj.py
View file @
c371df4a
...
...
@@ -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
:
...
...
samples/python/floodfill.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/gabor_threads.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/grabcut.py
View file @
c371df4a
...
...
@@ -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 <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
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
...
...
samples/python/hist.py
View file @
c371df4a
...
...
@@ -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 <image_file>"
)
im
=
cv
.
imread
(
fname
)
im
=
cv
.
imread
(
cv
.
samples
.
findFile
(
fname
)
)
if
im
is
None
:
print
(
'Failed to load image file:'
,
fname
)
...
...
samples/python/houghcircles.py
View file @
c371df4a
...
...
@@ -5,7 +5,7 @@ This example illustrates how to use cv.HoughCircles() function.
Usage:
houghcircles.py [<image_name>]
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
...
...
samples/python/houghlines.py
View file @
c371df4a
...
...
@@ -5,7 +5,7 @@ This example illustrates how to use Hough Transform to find lines
Usage:
houghlines.py [<image_name>]
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
)
...
...
samples/python/inpaint.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/letter_recog.py
View file @
c371df4a
...
...
@@ -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
()
...
...
samples/python/logpolar.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/morphology.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/peopledetect.py
View file @
c371df4a
...
...
@@ -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
,
' - '
,)
...
...
samples/python/stereo_match.py
View file @
c371df4a
...
...
@@ -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
...
...
samples/python/texture_flow.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tst_scene_render.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tutorial_code/Histograms_Matching/histogram_calculation/calcHist_Demo.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tutorial_code/Histograms_Matching/histogram_equalization/EqualizeHist_Demo.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tutorial_code/ImgTrans/Filter2D/filter2D.py
View file @
c371df4a
...
...
@@ -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]
...
...
samples/python/tutorial_code/ImgTrans/HoughCircle/hough_circle.py
View file @
c371df4a
...
...
@@ -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
:
...
...
samples/python/tutorial_code/ImgTrans/HoughLine/hough_lines.py
View file @
c371df4a
...
...
@@ -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
:
...
...
samples/python/tutorial_code/ImgTrans/LaPlace/laplace_demo.py
View file @
c371df4a
...
...
@@ -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]
...
...
samples/python/tutorial_code/ImgTrans/MakeBorder/copy_make_border.py
View file @
c371df4a
...
...
@@ -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
...
...
samples/python/tutorial_code/ImgTrans/canny_detector/CannyDetector_Demo.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tutorial_code/ImgTrans/distance_transformation/imageSegmentation.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tutorial_code/ImgTrans/remap/Remap_Demo.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tutorial_code/ImgTrans/warp_affine/Geometric_Transforms_Demo.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tutorial_code/ShapeDescriptors/bounding_rects_circles/generalContours_demo1.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tutorial_code/ShapeDescriptors/bounding_rotated_ellipses/generalContours_demo2.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tutorial_code/ShapeDescriptors/find_contours/findContours_demo.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tutorial_code/ShapeDescriptors/hull/hull_demo.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tutorial_code/ShapeDescriptors/moments/moments_demo.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tutorial_code/TrackingMotion/corner_subpixels/cornerSubPix_Demo.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tutorial_code/TrackingMotion/generic_corner_detector/cornerDetector_Demo.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tutorial_code/TrackingMotion/good_features_to_track/goodFeaturesToTrack_Demo.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tutorial_code/TrackingMotion/harris_detector/cornerHarris_Demo.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tutorial_code/core/AddingImages/adding_images.py
View file @
c371df4a
...
...
@@ -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"
)
...
...
samples/python/tutorial_code/core/discrete_fourier_transform/discrete_fourier_transform.py
View file @
c371df4a
...
...
@@ -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
...
...
samples/python/tutorial_code/core/mat_mask_operations/mat_mask_operations.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tutorial_code/features2D/akaze_matching/AKAZE_match.py
View file @
c371df4a
...
...
@@ -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]
...
...
samples/python/tutorial_code/features2D/feature_description/SURF_matching_Demo.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tutorial_code/features2D/feature_detection/SURF_detection_Demo.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tutorial_code/features2D/feature_flann_matcher/SURF_FLANN_matching_Demo.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tutorial_code/features2D/feature_homography/SURF_FLANN_matching_homography_Demo.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tutorial_code/highgui/trackbar/AddingImagesTrackbar.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tutorial_code/imgProc/Pyramids/pyramids.py
View file @
c371df4a
...
...
@@ -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
:
...
...
samples/python/tutorial_code/imgProc/Smoothing/smoothing.py
View file @
c371df4a
...
...
@@ -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
'
)
...
...
samples/python/tutorial_code/imgProc/changing_contrast_brightness_image/BasicLinearTransforms.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tutorial_code/imgProc/changing_contrast_brightness_image/changing_contrast_brightness_image.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tutorial_code/imgProc/erosion_dilatation/morphology_1.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tutorial_code/imgProc/hough_line_transform/hough_line_transform.py
View file @
c371df4a
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
)
...
...
samples/python/tutorial_code/imgProc/hough_line_transform/probabilistic_hough_line_transform.py
View file @
c371df4a
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
)
...
...
samples/python/tutorial_code/imgProc/opening_closing_hats/morphology_2.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tutorial_code/imgProc/threshold/threshold.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tutorial_code/ml/introduction_to_pca/introduction_to_pca.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tutorial_code/objectDetection/cascade_classifier/objectDetection.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/tutorial_code/video/background_subtraction/bg_sub.py
View file @
c371df4a
...
...
@@ -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
)
...
...
samples/python/video.py
View file @
c371df4a
...
...
@@ -20,8 +20,8 @@ Usage:
- synth:<params> 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'
)
...
...
samples/python/watershed.py
View file @
c371df4a
...
...
@@ -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
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment