mirror of https://github.com/opencv/opencv.git
Open Source Computer Vision Library
https://opencv.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
910 B
27 lines
910 B
8 years ago
|
#!/usr/bin/env python
|
||
7 years ago
|
import cv2 as cv
|
||
8 years ago
|
|
||
|
from tests_common import NewOpenCVTests
|
||
|
|
||
|
class shape_test(NewOpenCVTests):
|
||
|
|
||
|
def test_computeDistance(self):
|
||
|
|
||
7 years ago
|
a = self.get_sample('samples/data/shape_sample/1.png', cv.IMREAD_GRAYSCALE)
|
||
|
b = self.get_sample('samples/data/shape_sample/2.png', cv.IMREAD_GRAYSCALE)
|
||
8 years ago
|
|
||
7 years ago
|
_, ca, _ = cv.findContours(a, cv.RETR_CCOMP, cv.CHAIN_APPROX_TC89_KCOS)
|
||
|
_, cb, _ = cv.findContours(b, cv.RETR_CCOMP, cv.CHAIN_APPROX_TC89_KCOS)
|
||
8 years ago
|
|
||
7 years ago
|
hd = cv.createHausdorffDistanceExtractor()
|
||
|
sd = cv.createShapeContextDistanceExtractor()
|
||
8 years ago
|
|
||
|
d1 = hd.computeDistance(ca[0], cb[0])
|
||
|
d2 = sd.computeDistance(ca[0], cb[0])
|
||
|
|
||
|
self.assertAlmostEqual(d1, 26.4196891785, 3, "HausdorffDistanceExtractor")
|
||
|
self.assertAlmostEqual(d2, 0.25804194808, 3, "ShapeContextDistanceExtractor")
|
||
7 years ago
|
|
||
|
if __name__ == '__main__':
|
||
|
NewOpenCVTests.bootstrap()
|