1#!/usr/bin/env python
2
3import cv2.cv as cv
4import unittest
5
6class TestGoodFeaturesToTrack(unittest.TestCase):
7    def test(self):
8        arr = cv.LoadImage("../samples/c/lena.jpg", 0)
9        original = cv.CloneImage(arr)
10        size = cv.GetSize(arr)
11        eig_image = cv.CreateImage(size, cv.IPL_DEPTH_32F, 1)
12        temp_image = cv.CreateImage(size, cv.IPL_DEPTH_32F, 1)
13        threshes = [ x / 100. for x in range(1,10) ]
14
15        results = dict([(t, cv.GoodFeaturesToTrack(arr, eig_image, temp_image, 20000, t, 2, useHarris = 1)) for t in threshes])
16
17        # Check that GoodFeaturesToTrack has not modified input image
18        self.assert_(arr.tostring() == original.tostring())
19
20        # Check for repeatability
21        for i in range(10):
22            results2 = dict([(t, cv.GoodFeaturesToTrack(arr, eig_image, temp_image, 20000, t, 2, useHarris = 1)) for t in threshes])
23            self.assert_(results == results2)
24
25        for t0,t1 in zip(threshes, threshes[1:]):
26             r0 = results[t0]
27             r1 = results[t1]
28
29             # Increasing thresh should make result list shorter
30             self.assert_(len(r0) > len(r1))
31
32             # Increasing thresh should monly truncate result list
33             self.assert_(r0[:len(r1)] == r1)
34
35if __name__ == '__main__':
36    unittest.main()
37