Python samples adapted for Python3 compatibility
Common fixes: - print function - int / float division - map, zip iterators in py3 but lists in py2 Known bugs with opencv 3.0.0 - digits.py, called via digits_video.py: https://github.com/Itseez/opencv/issues/4969 - gaussian_mix.py: https://github.com/Itseez/opencv/pull/4232 - video_v4l2.py: https://github.com/Itseez/opencv/pull/5474 Not working: - letter_recog.py due to changed ml_StatModel.train() signature
This commit is contained in:
@@ -21,6 +21,14 @@ Keys:
|
||||
Select a textured planar object to track by drawing a box with a mouse.
|
||||
'''
|
||||
|
||||
# Python 2/3 compatibility
|
||||
from __future__ import print_function
|
||||
import sys
|
||||
PY3 = sys.version_info[0] == 3
|
||||
|
||||
if PY3:
|
||||
xrange = range
|
||||
|
||||
import numpy as np
|
||||
import cv2
|
||||
|
||||
@@ -64,6 +72,7 @@ class PlaneTracker:
|
||||
self.detector = cv2.ORB_create( nfeatures = 1000 )
|
||||
self.matcher = cv2.FlannBasedMatcher(flann_params, {}) # bug : need to pass empty dict (#1329)
|
||||
self.targets = []
|
||||
self.frame_points = []
|
||||
|
||||
def add_target(self, image, rect, data=None):
|
||||
'''Add a new tracking target.'''
|
||||
@@ -87,8 +96,8 @@ class PlaneTracker:
|
||||
|
||||
def track(self, frame):
|
||||
'''Returns a list of detected TrackedTarget objects'''
|
||||
frame_points, frame_descrs = self.detect_features(frame)
|
||||
if len(frame_points) < MIN_MATCH_COUNT:
|
||||
self.frame_points, frame_descrs = self.detect_features(frame)
|
||||
if len(self.frame_points) < MIN_MATCH_COUNT:
|
||||
return []
|
||||
matches = self.matcher.knnMatch(frame_descrs, k = 2)
|
||||
matches = [m[0] for m in matches if len(m) == 2 and m[0].distance < m[1].distance * 0.75]
|
||||
@@ -103,7 +112,7 @@ class PlaneTracker:
|
||||
continue
|
||||
target = self.targets[imgIdx]
|
||||
p0 = [target.keypoints[m.trainIdx].pt for m in matches]
|
||||
p1 = [frame_points[m.queryIdx].pt for m in matches]
|
||||
p1 = [self.frame_points[m.queryIdx].pt for m in matches]
|
||||
p0, p1 = np.float32((p0, p1))
|
||||
H, status = cv2.findHomography(p0, p1, cv2.RANSAC, 3.0)
|
||||
status = status.ravel() != 0
|
||||
@@ -169,7 +178,7 @@ class App:
|
||||
break
|
||||
|
||||
if __name__ == '__main__':
|
||||
print __doc__
|
||||
print(__doc__)
|
||||
|
||||
import sys
|
||||
try:
|
||||
|
Reference in New Issue
Block a user