#!/usr/bin/env python# Python 2/3 compatibilityfrom__future__importprint_functionimportcv2importnumpyasnpfromtests_commonimportNewOpenCVTestsclassTestGoodFeaturesToTrack_test(NewOpenCVTests):deftest_goodFeaturesToTrack(self):arr=self.get_sample('samples/data/lena.jpg',0)original=arr.copy(True)threshes=[x/100.forxinrange(1,10)]numPoints=20000results=dict([(t,cv2.goodFeaturesToTrack(arr,numPoints,t,2,useHarrisDetector=True))fortinthreshes])# Check that GoodFeaturesToTrack has not modified input imageself.assertTrue(arr.tostring()==original.tostring())# Check for repeatabilityforiinrange(1):results2=dict([(t,cv2.goodFeaturesToTrack(arr,numPoints,t,2,useHarrisDetector=True))fortinthreshes])fortinthreshes:self.assertTrue(len(results2[t])==len(results[t]))foriinrange(len(results[t])):self.assertTrue(cv2.norm(results[t][i][0]-results2[t][i][0])==0)fort0,t1inzip(threshes,threshes[1:]):r0=results[t0]r1=results[t1]# Increasing thresh should make result list shorterself.assertTrue(len(r0)>len(r1))# Increasing thresh should monly truncate result listforiinrange(len(r1)):self.assertTrue(cv2.norm(r1[i][0]-r0[i][0])==0)