From fd60e98c5b69fead0ed7b6657374cf5ec52abfcb Mon Sep 17 00:00:00 2001 From: berak Date: Thu, 1 Jan 2015 10:30:44 +0100 Subject: [PATCH] fixes for latest changes in opencv3.0 api fixes for latest changes in opencv3.0 api waitKey() normalization fixed mser bindings --- modules/features2d/include/opencv2/features2d.hpp | 2 +- samples/python2/calibrate.py | 2 +- samples/python2/common.py | 4 ++-- samples/python2/deconvolution.py | 2 +- samples/python2/digits_video.py | 2 +- samples/python2/edge.py | 2 +- samples/python2/find_obj.py | 12 +++++++----- samples/python2/fitline.py | 2 +- samples/python2/lappyr.py | 2 +- samples/python2/mosse.py | 2 +- samples/python2/mser.py | 4 ++-- samples/python2/plane_ar.py | 2 +- samples/python2/plane_tracker.py | 4 ++-- samples/python2/squares.py | 2 +- samples/python2/stereo_match.py | 13 ++++++------- 15 files changed, 29 insertions(+), 28 deletions(-) diff --git a/modules/features2d/include/opencv2/features2d.hpp b/modules/features2d/include/opencv2/features2d.hpp index c6223fb6bb..3d70172284 100644 --- a/modules/features2d/include/opencv2/features2d.hpp +++ b/modules/features2d/include/opencv2/features2d.hpp @@ -337,7 +337,7 @@ public: double _min_margin=0.003, int _edge_blur_size=5 ); CV_WRAP virtual void detectRegions( InputArray image, - std::vector >& msers, + CV_OUT std::vector >& msers, std::vector& bboxes ) = 0; CV_WRAP virtual void setDelta(int delta) = 0; diff --git a/samples/python2/calibrate.py b/samples/python2/calibrate.py index 2c759ff972..9f6f60cb73 100755 --- a/samples/python2/calibrate.py +++ b/samples/python2/calibrate.py @@ -26,7 +26,7 @@ if __name__ == '__main__': try: img_mask = img_mask[0] except: - img_mask = '../cpp/left*.jpg' + img_mask = '../data/left*.jpg' img_names = glob(img_mask) debug_dir = args.get('--debug') diff --git a/samples/python2/common.py b/samples/python2/common.py index 5ba1a71f4d..0ad811ae20 100755 --- a/samples/python2/common.py +++ b/samples/python2/common.py @@ -71,8 +71,8 @@ def mtx2rvec(R): return axis * np.arctan2(s, c) def draw_str(dst, (x, y), s): - cv2.putText(dst, s, (x+1, y+1), cv2.FONT_HERSHEY_PLAIN, 1.0, (0, 0, 0), thickness = 2, lineType=cv2.CV_AA) - cv2.putText(dst, s, (x, y), cv2.FONT_HERSHEY_PLAIN, 1.0, (255, 255, 255), lineType=cv2.CV_AA) + cv2.putText(dst, s, (x+1, y+1), cv2.FONT_HERSHEY_PLAIN, 1.0, (0, 0, 0), thickness = 2, lineType=cv2.LINE_AA) + cv2.putText(dst, s, (x, y), cv2.FONT_HERSHEY_PLAIN, 1.0, (255, 255, 255), lineType=cv2.LINE_AA) class Sketcher: def __init__(self, windowname, dests, colors_func): diff --git a/samples/python2/deconvolution.py b/samples/python2/deconvolution.py index 218efe883b..bbb1567bd4 100755 --- a/samples/python2/deconvolution.py +++ b/samples/python2/deconvolution.py @@ -119,7 +119,7 @@ if __name__ == '__main__': update(None) while True: - ch = cv2.waitKey() + ch = cv2.waitKey() & 0xFF if ch == 27: break if ch == ord(' '): diff --git a/samples/python2/digits_video.py b/samples/python2/digits_video.py index ca72a93501..bb142eb687 100755 --- a/samples/python2/digits_video.py +++ b/samples/python2/digits_video.py @@ -86,7 +86,7 @@ def main(): cv2.imshow('frame', frame) cv2.imshow('bin', bin) - ch = cv2.waitKey(1) + ch = cv2.waitKey(1) & 0xFF if ch == 27: break diff --git a/samples/python2/edge.py b/samples/python2/edge.py index bd0c8bde79..413bf8859b 100755 --- a/samples/python2/edge.py +++ b/samples/python2/edge.py @@ -45,7 +45,7 @@ if __name__ == '__main__': vis /= 2 vis[edge != 0] = (0, 255, 0) cv2.imshow('edge', vis) - ch = cv2.waitKey(5) + ch = cv2.waitKey(5) & 0xFF if ch == 27: break cv2.destroyAllWindows() diff --git a/samples/python2/find_obj.py b/samples/python2/find_obj.py index fb1e0730d9..35bce86fde 100755 --- a/samples/python2/find_obj.py +++ b/samples/python2/find_obj.py @@ -3,6 +3,8 @@ ''' Feature-based image matching sample. +Note, that you will need the https://github.com/Itseez/opencv_contrib repo for SIFT and SURF + USAGE find_obj.py [--feature=[-flann]] [ ] @@ -23,19 +25,19 @@ FLANN_INDEX_LSH = 6 def init_feature(name): chunks = name.split('-') if chunks[0] == 'sift': - detector = cv2.xfeatures2d.SIFT() + detector = cv2.xfeatures2d.SIFT_create() norm = cv2.NORM_L2 elif chunks[0] == 'surf': - detector = cv2.xfeatures2d.SURF(800) + detector = cv2.xfeatures2d.SURF_create(800) norm = cv2.NORM_L2 elif chunks[0] == 'orb': - detector = cv2.ORB(400) + detector = cv2.ORB_create(400) norm = cv2.NORM_HAMMING elif chunks[0] == 'akaze': - detector = cv2.AKAZE() + detector = cv2.AKAZE_create() norm = cv2.NORM_HAMMING elif chunks[0] == 'brisk': - detector = cv2.BRISK() + detector = cv2.BRISK_create() norm = cv2.NORM_HAMMING else: return None, None diff --git a/samples/python2/fitline.py b/samples/python2/fitline.py index 82b45b0232..c91a7e4535 100755 --- a/samples/python2/fitline.py +++ b/samples/python2/fitline.py @@ -79,7 +79,7 @@ if __name__ == '__main__': cv2.createTrackbar('outlier %', 'fit line', 30, 100, update) while True: update() - ch = cv2.waitKey(0) + ch = cv2.waitKey(0) & 0xFF if ch == ord('f'): cur_func_name = dist_func_names.next() if ch == 27: diff --git a/samples/python2/lappyr.py b/samples/python2/lappyr.py index 0c08484de9..3cf2679b08 100755 --- a/samples/python2/lappyr.py +++ b/samples/python2/lappyr.py @@ -62,5 +62,5 @@ if __name__ == '__main__': cv2.imshow('laplacian pyramid filter', res) - if cv2.waitKey(1) == 27: + if cv2.waitKey(1) & 0xFF == 27: break diff --git a/samples/python2/mosse.py b/samples/python2/mosse.py index 0e2e7eed98..81196dcc36 100755 --- a/samples/python2/mosse.py +++ b/samples/python2/mosse.py @@ -168,7 +168,7 @@ class App: self.rect_sel.draw(vis) cv2.imshow('frame', vis) - ch = cv2.waitKey(10) + ch = cv2.waitKey(10) & 0xFF if ch == 27: break if ch == ord(' '): diff --git a/samples/python2/mser.py b/samples/python2/mser.py index beaa6e7dcb..9d7a65c10f 100755 --- a/samples/python2/mser.py +++ b/samples/python2/mser.py @@ -26,13 +26,13 @@ if __name__ == '__main__': video_src = 0 cam = video.create_capture(video_src) - mser = cv2.MSER() + mser = cv2.MSER_create() while True: ret, img = cam.read() gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) vis = img.copy() - regions = mser.detect(gray, None) + regions = mser.detectRegions(gray, None) hulls = [cv2.convexHull(p.reshape(-1, 1, 2)) for p in regions] cv2.polylines(vis, hulls, 1, (0, 255, 0)) diff --git a/samples/python2/plane_ar.py b/samples/python2/plane_ar.py index dcb5559cdf..6580be7d05 100755 --- a/samples/python2/plane_ar.py +++ b/samples/python2/plane_ar.py @@ -71,7 +71,7 @@ class App: self.rect_sel.draw(vis) cv2.imshow('plane', vis) - ch = cv2.waitKey(1) + ch = cv2.waitKey(1) & 0xFF if ch == ord(' '): self.paused = not self.paused if ch == ord('c'): diff --git a/samples/python2/plane_tracker.py b/samples/python2/plane_tracker.py index de5d7a0ec9..5ae0933bc0 100755 --- a/samples/python2/plane_tracker.py +++ b/samples/python2/plane_tracker.py @@ -61,7 +61,7 @@ TrackedTarget = namedtuple('TrackedTarget', 'target, p0, p1, H, quad') class PlaneTracker: def __init__(self): - self.detector = cv2.ORB( nfeatures = 1000 ) + self.detector = cv2.ORB_create( nfeatures = 1000 ) self.matcher = cv2.FlannBasedMatcher(flann_params, {}) # bug : need to pass empty dict (#1329) self.targets = [] @@ -160,7 +160,7 @@ class App: self.rect_sel.draw(vis) cv2.imshow('plane', vis) - ch = cv2.waitKey(1) + ch = cv2.waitKey(1) & 0xFF if ch == ord(' '): self.paused = not self.paused if ch == ord('c'): diff --git a/samples/python2/squares.py b/samples/python2/squares.py index c12b884011..84160a2919 100755 --- a/samples/python2/squares.py +++ b/samples/python2/squares.py @@ -37,7 +37,7 @@ def find_squares(img): if __name__ == '__main__': from glob import glob - for fn in glob('../cpp/pic*.png'): + for fn in glob('../data/pic*.png'): img = cv2.imread(fn) squares = find_squares(img) cv2.drawContours( img, squares, -1, (0, 255, 0), 3 ) diff --git a/samples/python2/stereo_match.py b/samples/python2/stereo_match.py index 5b21617cca..e53ae77025 100755 --- a/samples/python2/stereo_match.py +++ b/samples/python2/stereo_match.py @@ -39,16 +39,15 @@ if __name__ == '__main__': window_size = 3 min_disp = 16 num_disp = 112-min_disp - stereo = cv2.StereoSGBM(minDisparity = min_disp, + stereo = cv2.StereoSGBM_create(minDisparity = min_disp, numDisparities = num_disp, - SADWindowSize = window_size, - uniquenessRatio = 10, - speckleWindowSize = 100, - speckleRange = 32, - disp12MaxDiff = 1, + blockSize = 16, P1 = 8*3*window_size**2, P2 = 32*3*window_size**2, - fullDP = False + disp12MaxDiff = 1, + uniquenessRatio = 10, + speckleWindowSize = 100, + speckleRange = 32 ) print 'computing disparity...'