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

View File

@@ -14,6 +14,9 @@ Keys:
'''
# Python 2/3 compatibility
from __future__ import print_function
import cv2
def decode_fourcc(v):
@@ -24,13 +27,13 @@ font = cv2.FONT_HERSHEY_SIMPLEX
color = (0, 255, 0)
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_AUTOFOCUS, False)
cap.set(cv2.CAP_PROP_AUTOFOCUS, False) # Known bug: https://github.com/Itseez/opencv/pull/5474
cv2.namedWindow("Video")
convert_rgb = True
fps = int(cap.get(cv2.CAP_PROP_FPS))
focus = int(cap.get(cv2.CAP_PROP_FOCUS)) * 100
focus = int(min(cap.get(cv2.CAP_PROP_FOCUS) * 100, 2**31-1)) # ceil focus to C_LONG as Python3 int can go to +inf
cv2.createTrackbar("FPS", "Video", fps, 30, lambda v: cap.set(cv2.CAP_PROP_FPS, v))
cv2.createTrackbar("Focus", "Video", focus, 100, lambda v: cap.set(cv2.CAP_PROP_FOCUS, v / 100))
@@ -55,7 +58,7 @@ while True:
cv2.putText(img, "FPS: {}".format(fps), (15, 80), font, 1.0, color)
cv2.imshow("Video", img)
k = cv2.waitKey(1)
k = 0xFF & cv2.waitKey(1)
if k == 27:
break