2016-03-17 20:33:28 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# Python 2/3 compatibility
|
|
|
|
from __future__ import print_function
|
|
|
|
|
2017-12-11 17:55:03 +08:00
|
|
|
import cv2 as cv
|
2016-03-17 20:33:28 +08:00
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
from tests_common import NewOpenCVTests
|
|
|
|
|
|
|
|
class TestGoodFeaturesToTrack_test(NewOpenCVTests):
|
|
|
|
def test_goodFeaturesToTrack(self):
|
|
|
|
arr = self.get_sample('samples/data/lena.jpg', 0)
|
2020-09-28 05:14:55 +08:00
|
|
|
original = arr.copy()
|
2016-03-17 20:33:28 +08:00
|
|
|
threshes = [ x / 100. for x in range(1,10) ]
|
|
|
|
numPoints = 20000
|
|
|
|
|
2017-12-11 17:55:03 +08:00
|
|
|
results = dict([(t, cv.goodFeaturesToTrack(arr, numPoints, t, 2, useHarrisDetector=True)) for t in threshes])
|
2016-03-17 20:33:28 +08:00
|
|
|
# Check that GoodFeaturesToTrack has not modified input image
|
|
|
|
self.assertTrue(arr.tostring() == original.tostring())
|
|
|
|
# Check for repeatability
|
|
|
|
for i in range(1):
|
2017-12-11 17:55:03 +08:00
|
|
|
results2 = dict([(t, cv.goodFeaturesToTrack(arr, numPoints, t, 2, useHarrisDetector=True)) for t in threshes])
|
2016-03-17 20:33:28 +08:00
|
|
|
for t in threshes:
|
|
|
|
self.assertTrue(len(results2[t]) == len(results[t]))
|
|
|
|
for i in range(len(results[t])):
|
2017-12-11 17:55:03 +08:00
|
|
|
self.assertTrue(cv.norm(results[t][i][0] - results2[t][i][0]) == 0)
|
2016-03-17 20:33:28 +08:00
|
|
|
|
|
|
|
for t0,t1 in zip(threshes, threshes[1:]):
|
2017-09-03 19:17:15 +08:00
|
|
|
r0 = results[t0]
|
|
|
|
r1 = results[t1]
|
|
|
|
# Increasing thresh should make result list shorter
|
|
|
|
self.assertTrue(len(r0) > len(r1))
|
|
|
|
# Increasing thresh should monly truncate result list
|
|
|
|
for i in range(len(r1)):
|
2017-12-11 17:55:03 +08:00
|
|
|
self.assertTrue(cv.norm(r1[i][0] - r0[i][0])==0)
|
2017-09-03 20:01:25 +08:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
NewOpenCVTests.bootstrap()
|