1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 07:13:02 +04:00

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:
flp
2015-12-13 02:43:58 +01:00
parent 5cdf0e3e89
commit 4ed2d6328b
23 changed files with 218 additions and 131 deletions
+5 -2
View File
@@ -10,6 +10,9 @@ Usage:
texture_flow.py [<image>]
'''
# Python 2/3 compatibility
from __future__ import print_function
import numpy as np
import cv2
@@ -22,7 +25,7 @@ if __name__ == '__main__':
img = cv2.imread(fn)
if img is None:
print 'Failed to load image file:', fn
print('Failed to load image file:', fn)
sys.exit(1)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
@@ -36,7 +39,7 @@ if __name__ == '__main__':
vis[:] = (192 + np.uint32(vis)) / 2
d = 12
points = np.dstack( np.mgrid[d/2:w:d, d/2:h:d] ).reshape(-1, 2)
for x, y in points:
for x, y in np.int32(points):
vx, vy = np.int32(flow[y, x]*d)
cv2.line(vis, (x-vx, y-vy), (x+vx, y+vy), (0, 0, 0), 1, cv2.LINE_AA)
cv2.imshow('input', img)