Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/python/test/test_goodfeatures.py
16337 views
1
#!/usr/bin/env python
2
3
# Python 2/3 compatibility
4
from __future__ import print_function
5
6
import cv2 as cv
7
import numpy as np
8
9
from tests_common import NewOpenCVTests
10
11
class TestGoodFeaturesToTrack_test(NewOpenCVTests):
12
def test_goodFeaturesToTrack(self):
13
arr = self.get_sample('samples/data/lena.jpg', 0)
14
original = arr.copy(True)
15
threshes = [ x / 100. for x in range(1,10) ]
16
numPoints = 20000
17
18
results = dict([(t, cv.goodFeaturesToTrack(arr, numPoints, t, 2, useHarrisDetector=True)) for t in threshes])
19
# Check that GoodFeaturesToTrack has not modified input image
20
self.assertTrue(arr.tostring() == original.tostring())
21
# Check for repeatability
22
for i in range(1):
23
results2 = dict([(t, cv.goodFeaturesToTrack(arr, numPoints, t, 2, useHarrisDetector=True)) for t in threshes])
24
for t in threshes:
25
self.assertTrue(len(results2[t]) == len(results[t]))
26
for i in range(len(results[t])):
27
self.assertTrue(cv.norm(results[t][i][0] - results2[t][i][0]) == 0)
28
29
for t0,t1 in zip(threshes, threshes[1:]):
30
r0 = results[t0]
31
r1 = results[t1]
32
# Increasing thresh should make result list shorter
33
self.assertTrue(len(r0) > len(r1))
34
# Increasing thresh should monly truncate result list
35
for i in range(len(r1)):
36
self.assertTrue(cv.norm(r1[i][0] - r0[i][0])==0)
37
38
39
if __name__ == '__main__':
40
NewOpenCVTests.bootstrap()
41
42