Commit facd580f authored by Moshe Kaplan's avatar Moshe Kaplan

Small changes to Python samples

    Update find_obj.py:
    Added additional error checking for the loaded files and modified the detector check to be more pythonic (is versus ==).

    Update common.py:
    Fixed a typo (contais -> contains)
parent 9e12b7c3
#/usr/bin/env python #/usr/bin/env python
''' '''
This module contais some common routines used by other samples. This module contains some common routines used by other samples.
''' '''
import numpy as np import numpy as np
......
...@@ -9,7 +9,7 @@ USAGE ...@@ -9,7 +9,7 @@ USAGE
--feature - Feature to use. Can be sift, surf of orb. Append '-flann' to feature name --feature - Feature to use. Can be sift, surf of orb. Append '-flann' to feature name
to use Flann-based matcher instead bruteforce. to use Flann-based matcher instead bruteforce.
Press left mouse button on a feature point to see its mathcing point. Press left mouse button on a feature point to see its matching point.
''' '''
import numpy as np import numpy as np
...@@ -130,7 +130,8 @@ if __name__ == '__main__': ...@@ -130,7 +130,8 @@ if __name__ == '__main__':
opts, args = getopt.getopt(sys.argv[1:], '', ['feature=']) opts, args = getopt.getopt(sys.argv[1:], '', ['feature='])
opts = dict(opts) opts = dict(opts)
feature_name = opts.get('--feature', 'sift') feature_name = opts.get('--feature', 'sift')
try: fn1, fn2 = args try:
fn1, fn2 = args
except: except:
fn1 = '../c/box.png' fn1 = '../c/box.png'
fn2 = '../c/box_in_scene.png' fn2 = '../c/box_in_scene.png'
...@@ -138,12 +139,20 @@ if __name__ == '__main__': ...@@ -138,12 +139,20 @@ if __name__ == '__main__':
img1 = cv2.imread(fn1, 0) img1 = cv2.imread(fn1, 0)
img2 = cv2.imread(fn2, 0) img2 = cv2.imread(fn2, 0)
detector, matcher = init_feature(feature_name) detector, matcher = init_feature(feature_name)
if detector != None:
print 'using', feature_name if img1 is None:
else: print 'Failed to load fn1:', fn1
sys.exit(1)
if img2 is None:
print 'Failed to load fn2:', fn2
sys.exit(1)
if detector is None:
print 'unknown feature:', feature_name print 'unknown feature:', feature_name
sys.exit(1) sys.exit(1)
print 'using', feature_name
kp1, desc1 = detector.detectAndCompute(img1, None) kp1, desc1 = detector.detectAndCompute(img1, None)
kp2, desc2 = detector.detectAndCompute(img2, None) kp2, desc2 = detector.detectAndCompute(img2, None)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment