Path: blob/master/modules/python/test/test_goodfeatures.py
16337 views
#!/usr/bin/env python12# Python 2/3 compatibility3from __future__ import print_function45import cv2 as cv6import numpy as np78from tests_common import NewOpenCVTests910class TestGoodFeaturesToTrack_test(NewOpenCVTests):11def test_goodFeaturesToTrack(self):12arr = self.get_sample('samples/data/lena.jpg', 0)13original = arr.copy(True)14threshes = [ x / 100. for x in range(1,10) ]15numPoints = 200001617results = dict([(t, cv.goodFeaturesToTrack(arr, numPoints, t, 2, useHarrisDetector=True)) for t in threshes])18# Check that GoodFeaturesToTrack has not modified input image19self.assertTrue(arr.tostring() == original.tostring())20# Check for repeatability21for i in range(1):22results2 = dict([(t, cv.goodFeaturesToTrack(arr, numPoints, t, 2, useHarrisDetector=True)) for t in threshes])23for t in threshes:24self.assertTrue(len(results2[t]) == len(results[t]))25for i in range(len(results[t])):26self.assertTrue(cv.norm(results[t][i][0] - results2[t][i][0]) == 0)2728for t0,t1 in zip(threshes, threshes[1:]):29r0 = results[t0]30r1 = results[t1]31# Increasing thresh should make result list shorter32self.assertTrue(len(r0) > len(r1))33# Increasing thresh should monly truncate result list34for i in range(len(r1)):35self.assertTrue(cv.norm(r1[i][0] - r0[i][0])==0)363738if __name__ == '__main__':39NewOpenCVTests.bootstrap()404142