MCPcopy Create free account
hub / github.com/davisking/dlib / run_hough_test

Function run_hough_test

dlib/test/image.cpp:1938–1992  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1936// ----------------------------------------------------------------------------------------
1937
1938 void run_hough_test()
1939 {
1940 array2d<unsigned char> img(300,300);
1941
1942
1943 for (int k = -2; k <= 2; ++k)
1944 {
1945 print_spinner();
1946 running_stats<double> rs;
1947 array2d<int> himg;
1948 hough_transform ht(200+k);
1949 double angle1 = 0;
1950 double angle2 = 0;
1951 const int len = 90;
1952 // Draw a bunch of random lines, hough transform them, then make sure the hough
1953 // transform detects them accurately.
1954 for (int i = 0; i < 500; ++i)
1955 {
1956 point cent = center(get_rect(img));
1957 point arc = cent + point(len,0);
1958 arc = rotate_point(cent, arc, angle1);
1959
1960 point l = arc + point(500,0);
1961 point r = arc - point(500,0);
1962 l = rotate_point(arc, l, angle2);
1963 r = rotate_point(arc, r, angle2);
1964
1965 angle1 += pi/13;
1966 angle2 += pi/40;
1967
1968 assign_all_pixels(img, 0);
1969 draw_line(img, l, r, 255);
1970 rectangle box = translate_rect(get_rect(ht),point(50,50));
1971 ht(img, box, himg);
1972
1973 point p = max_point(mat(himg));
1974 DLIB_TEST(himg[p.y()][p.x()] > 255*3);
1975
1976 l -= point(50,50);
1977 r -= point(50,50);
1978 std::pair<point,point> line = ht.get_line(p);
1979 // make sure the best scoring hough point matches the line we drew.
1980 double dist1 = distance_to_line(make_pair(l,r), line.first);
1981 double dist2 = distance_to_line(make_pair(l,r), line.second);
1982 //cout << "DIST1: " << dist1 << endl;
1983 //cout << "DIST2: " << dist2 << endl;
1984 rs.add(dist1);
1985 rs.add(dist2);
1986 DLIB_TEST(dist1 < 2.5);
1987 DLIB_TEST(dist2 < 2.5);
1988 }
1989 //cout << "rs.mean(): " << rs.mean() << endl;
1990 DLIB_TEST(rs.mean() < 0.7);
1991 }
1992 }
1993
1994// ----------------------------------------------------------------------------------------
1995

Callers 1

perform_testMethod · 0.85

Calls 14

print_spinnerFunction · 0.85
get_rectFunction · 0.85
rotate_pointFunction · 0.85
assign_all_pixelsFunction · 0.85
max_pointFunction · 0.85
distance_to_lineFunction · 0.85
get_lineMethod · 0.80
centerFunction · 0.50
pointClass · 0.50
draw_lineFunction · 0.50
translate_rectFunction · 0.50
matFunction · 0.50

Tested by

no test coverage detected