Various Python samples updated for Python 2/3 compatibility.
This commit is contained in:
@@ -9,6 +9,14 @@ inspired by
|
||||
http://www.mia.uni-saarland.de/Publications/weickert-dagm03.pdf
|
||||
'''
|
||||
|
||||
# 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
|
||||
|
||||
@@ -16,7 +24,7 @@ def coherence_filter(img, sigma = 11, str_sigma = 11, blend = 0.5, iter_n = 4):
|
||||
h, w = img.shape[:2]
|
||||
|
||||
for i in xrange(iter_n):
|
||||
print i,
|
||||
print(i)
|
||||
|
||||
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
||||
eigen = cv2.cornerEigenValsAndVecs(gray, str_sigma, 3)
|
||||
@@ -34,7 +42,7 @@ def coherence_filter(img, sigma = 11, str_sigma = 11, blend = 0.5, iter_n = 4):
|
||||
img1 = ero
|
||||
img1[m] = dil[m]
|
||||
img = np.uint8(img*(1.0 - blend) + img1*blend)
|
||||
print 'done'
|
||||
print('done')
|
||||
return img
|
||||
|
||||
|
||||
@@ -54,7 +62,7 @@ if __name__ == '__main__':
|
||||
sigma = cv2.getTrackbarPos('sigma', 'control')*2+1
|
||||
str_sigma = cv2.getTrackbarPos('str_sigma', 'control')*2+1
|
||||
blend = cv2.getTrackbarPos('blend', 'control') / 10.0
|
||||
print 'sigma: %d str_sigma: %d blend_coef: %f' % (sigma, str_sigma, blend)
|
||||
print('sigma: %d str_sigma: %d blend_coef: %f' % (sigma, str_sigma, blend))
|
||||
dst = coherence_filter(src, sigma=sigma, str_sigma = str_sigma, blend = blend)
|
||||
cv2.imshow('dst', dst)
|
||||
|
||||
@@ -64,7 +72,7 @@ if __name__ == '__main__':
|
||||
cv2.createTrackbar('str_sigma', 'control', 9, 15, nothing)
|
||||
|
||||
|
||||
print 'Press SPACE to update the image\n'
|
||||
print('Press SPACE to update the image\n')
|
||||
|
||||
cv2.imshow('src', src)
|
||||
update()
|
||||
|
Reference in New Issue
Block a user