Path: blob/master/modules/python/test/test_houghlines.py
16337 views
#!/usr/bin/python12'''3This example illustrates how to use Hough Transform to find lines4'''56# Python 2/3 compatibility7from __future__ import print_function89import cv2 as cv10import numpy as np11import sys12import math1314from tests_common import NewOpenCVTests1516def linesDiff(line1, line2):1718norm1 = cv.norm(line1 - line2, cv.NORM_L2)19line3 = line1[2:4] + line1[0:2]20norm2 = cv.norm(line3 - line2, cv.NORM_L2)2122return min(norm1, norm2)2324class houghlines_test(NewOpenCVTests):2526def test_houghlines(self):2728fn = "/samples/data/pic1.png"2930src = self.get_sample(fn)31dst = cv.Canny(src, 50, 200)3233lines = cv.HoughLinesP(dst, 1, math.pi/180.0, 40, np.array([]), 50, 10)[:,0,:]3435eps = 536testLines = [37#rect138[ 232, 25, 43, 25],39[ 43, 129, 232, 129],40[ 43, 129, 43, 25],41[232, 129, 232, 25],42#rect243[251, 86, 314, 183],44[252, 86, 323, 40],45[315, 183, 386, 137],46[324, 40, 386, 136],47#triangle48[245, 205, 377, 205],49[244, 206, 305, 278],50[306, 279, 377, 205],51#rect352[153, 177, 196, 177],53[153, 277, 153, 179],54[153, 277, 196, 277],55[196, 177, 196, 277]]5657matches_counter = 05859for i in range(len(testLines)):60for j in range(len(lines)):61if linesDiff(testLines[i], lines[j]) < eps:62matches_counter += 16364self.assertGreater(float(matches_counter) / len(testLines), .7)656667if __name__ == '__main__':68NewOpenCVTests.bootstrap()697071