Skip to content

Commit 752222a

Browse files
authored
Update to work with difference in opencv KeyPoint constructor and add travis test for Python 3.9 (#1)
1 parent 2aecc9a commit 752222a

File tree

6 files changed

+38
-8
lines changed

6 files changed

+38
-8
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ python:
66
- "3.6"
77
- "3.7"
88
- "3.8"
9+
- "3.9"
910

1011
env:
1112
- OPENCV_VER=latest
@@ -16,6 +17,10 @@ jobs:
1617
env: OPENCV_VER=331
1718
- python: 3.6
1819
env: OPENCV_VER=331
20+
- python: 3.7
21+
env: OPENCV_VER=452
22+
- python: 3.7
23+
env: OPENCV_VER=453
1924

2025
script: ./test.py $TEST_SUITE
2126

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Build Status](https://travis-ci.org/neufieldrobotics/zernike_py.svg?branch=master)](https://travis-ci.org/neufieldrobotics/zernike_py)
1+
[![Build Status](https://app.travis-ci.com/neufieldrobotics/zernike_py.svg?branch=master)](https://app.travis-ci.com/github/neufieldrobotics/zernike_py/branches)
22

33
# zernike_py
44

requirements/base.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
matplotlib
22
numpy
3+
packaging
34
scipy

requirements/opencv_452.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-r base.txt
2+
opencv-python==4.5.2.*

requirements/opencv_453.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-r base.txt
2+
opencv-python==4.5.3.*

zernike_py/MultiHarrisZernike.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
np.set_printoptions(precision=5,suppress=True)
1010
import cv2
1111
import time
12+
from packaging import version
1213
#from matlab_imresize.imresize import imresize
1314
#from scipy.ndimage import convolve
1415

16+
OPENCV_NEWER_THAN_4_5_2 = version.parse(cv2.__version__) > version.parse('4.5.2')
17+
1518
# Inheriting from opencv class causes segfaults
1619
#class MultiHarrisZernike (cv2.Feature2D):
1720
class MultiHarrisZernike:
@@ -589,8 +592,13 @@ def FtDict2KeypointList(self, Ft, alpha):
589592
response = float(res)
590593
octave = int(sc)
591594
size = float(self.zrad*(octave+1)*2)
592-
keypoints.append(cv2.KeyPoint(pt_x, pt_y, size, _angle=angle,
593-
_response=response, _octave=octave))
595+
596+
if OPENCV_NEWER_THAN_4_5_2:
597+
keypoints.append(cv2.KeyPoint(x=pt_x, y=pt_y, size=size, angle=angle,
598+
response=response, octave=octave))
599+
else:
600+
keypoints.append(cv2.KeyPoint(pt_x, pt_y, size, _angle=angle,
601+
_response=response, _octave=octave))
594602
return keypoints
595603

596604
def keypointList2FtDict(self, keypoints, gr_shape):
@@ -708,8 +716,14 @@ def detectAndCompute(self, gr_img, mask=None, timing=False, computeEigVals=False
708716

709717
kp_eigVals = np.zeros((Ft['Nfeats'],2))
710718
# i at specified scale, j at specified scale and s scale
711-
for i, (si, sj, s) in enumerate(zip(Ft['sivec'], Ft['sjvec'], Ft['svec'])):
712-
kp_eigVals[i,:] = eigVals[s][si,sj]
719+
if OPENCV_NEWER_THAN_4_5_2:
720+
kp = [cv2.KeyPoint(x=float(x),y=float(y),size=float(self.zrad*(sc+1)*2),angle=float(ang),response=float(res),octave=int(sc))
721+
for x,y,ang,res,sc in zip(Ft['jvec'], Ft['ivec'], np.rad2deg(alpha),
722+
Ft['evec'],Ft['svec'])]
723+
else:
724+
kp = [cv2.KeyPoint(float(x),float(y),float(self.zrad*(sc+1)*2),_angle=float(ang),_response=float(res),_octave=int(sc))
725+
for x,y,ang,res,sc in zip(Ft['jvec'], Ft['ivec'], np.rad2deg(alpha),
726+
Ft['evec'],Ft['svec'])]
713727

714728
return kp, V, kp_eigVals, Ft
715729

@@ -746,9 +760,15 @@ def detect(self, gr_img, mask=None, timing=False):
746760
if timing: print("Feature Threshold - {:0.4f}".format(time.time()-st)); st=time.time()
747761
alpha = self.corner_angle(P, Ft)
748762
if timing: print("Angle computation - {:0.4f}".format(time.time()-st)); st=time.time()
749-
kp = [cv2.KeyPoint(x,y,self.zrad*(sc+1)*2,_angle=ang,_response=res,_octave=sc)
750-
for x,y,ang,res,sc in zip(Ft['jvec'], Ft['ivec'], np.rad2deg(alpha),
751-
Ft['evec'],Ft['svec'])]
763+
if OPENCV_NEWER_THAN_4_5_2:
764+
kp = [cv2.KeyPoint(x=x,y=y,size=self.zrad*(sc+1)*2,angle=ang,response=res,octave=sc)
765+
for x,y,ang,res,sc in zip(Ft['jvec'], Ft['ivec'], np.rad2deg(alpha),
766+
Ft['evec'],Ft['svec'])]
767+
else:
768+
kp = [cv2.KeyPoint(x,y,self.zrad*(sc+1)*2,_angle=ang,_response=res,_octave=sc)
769+
for x,y,ang,res,sc in zip(Ft['jvec'], Ft['ivec'], np.rad2deg(alpha),
770+
Ft['evec'],Ft['svec'])]
771+
752772
if timing: print("Keypoint export - {:0.4f}".format(time.time()-st)); st=time.time()
753773

754774
return kp

0 commit comments

Comments
 (0)