Path: blob/master/modules/imgproc/perf/perf_houghlines.cpp
16339 views
// This file is part of OpenCV project.1// It is subject to the license terms in the LICENSE file found in the top-level directory2// of this distribution and at http://opencv.org/license.html.3#include "perf_precomp.hpp"45namespace opencv_test {67typedef tuple<string, double, double, double> Image_RhoStep_ThetaStep_Threshold_t;8typedef perf::TestBaseWithParam<Image_RhoStep_ThetaStep_Threshold_t> Image_RhoStep_ThetaStep_Threshold;910PERF_TEST_P(Image_RhoStep_ThetaStep_Threshold, HoughLines,11testing::Combine(12testing::Values( "cv/shared/pic5.png", "stitching/a1.png" ),13testing::Values( 1, 10 ),14testing::Values( 0.01, 0.1 ),15testing::Values( 0.5, 1.1 )16)17)18{19string filename = getDataPath(get<0>(GetParam()));20double rhoStep = get<1>(GetParam());21double thetaStep = get<2>(GetParam());22double threshold_ratio = get<3>(GetParam());2324Mat image = imread(filename, IMREAD_GRAYSCALE);25if (image.empty())26FAIL() << "Unable to load source image" << filename;2728Canny(image, image, 32, 128);2930// add some syntetic lines:31line(image, Point(0, 0), Point(image.cols, image.rows), Scalar::all(255), 3);32line(image, Point(image.cols, 0), Point(image.cols/2, image.rows), Scalar::all(255), 3);3334vector<Vec2f> lines;35declare.time(60);3637int hough_threshold = (int)(std::min(image.cols, image.rows) * threshold_ratio);3839TEST_CYCLE() HoughLines(image, lines, rhoStep, thetaStep, hough_threshold);4041printf("%dx%d: %d lines\n", image.cols, image.rows, (int)lines.size());4243if (threshold_ratio < 1.0)44{45EXPECT_GE(lines.size(), 2u);46}4748EXPECT_LT(lines.size(), 3000u);4950#if 051cv::cvtColor(image,image,cv::COLOR_GRAY2BGR);52for( size_t i = 0; i < lines.size(); i++ )53{54float rho = lines[i][0], theta = lines[i][1];55Point pt1, pt2;56double a = cos(theta), b = sin(theta);57double x0 = a*rho, y0 = b*rho;58pt1.x = cvRound(x0 + 1000*(-b));59pt1.y = cvRound(y0 + 1000*(a));60pt2.x = cvRound(x0 - 1000*(-b));61pt2.y = cvRound(y0 - 1000*(a));62line(image, pt1, pt2, Scalar(0,0,255), 1, cv::LINE_AA);63}64cv::imshow("result", image);65cv::waitKey();66#endif6768SANITY_CHECK_NOTHING();69}7071PERF_TEST_P(Image_RhoStep_ThetaStep_Threshold, HoughLines3f,72testing::Combine(73testing::Values( "cv/shared/pic5.png", "stitching/a1.png" ),74testing::Values( 1, 10 ),75testing::Values( 0.01, 0.1 ),76testing::Values( 0.5, 1.1 )77)78)79{80string filename = getDataPath(get<0>(GetParam()));81double rhoStep = get<1>(GetParam());82double thetaStep = get<2>(GetParam());83double threshold_ratio = get<3>(GetParam());8485Mat image = imread(filename, IMREAD_GRAYSCALE);86if (image.empty())87FAIL() << "Unable to load source image" << filename;8889Canny(image, image, 32, 128);9091// add some syntetic lines:92line(image, Point(0, 0), Point(image.cols, image.rows), Scalar::all(255), 3);93line(image, Point(image.cols, 0), Point(image.cols/2, image.rows), Scalar::all(255), 3);9495vector<Vec3f> lines;96declare.time(60);9798int hough_threshold = (int)(std::min(image.cols, image.rows) * threshold_ratio);99100TEST_CYCLE() HoughLines(image, lines, rhoStep, thetaStep, hough_threshold);101102printf("%dx%d: %d lines\n", image.cols, image.rows, (int)lines.size());103104if (threshold_ratio < 1.0)105{106EXPECT_GE(lines.size(), 2u);107}108109EXPECT_LT(lines.size(), 3000u);110111SANITY_CHECK_NOTHING();112}113114} // namespace115116117