Merge pull request #2153 from scottbreyfogle:constrained-hough-lines
This commit is contained in:
commit
9dede73d9f
@ -358,11 +358,11 @@ HoughLines
|
||||
----------
|
||||
Finds lines in a binary image using the standard Hough transform.
|
||||
|
||||
.. ocv:function:: void HoughLines( InputArray image, OutputArray lines, double rho, double theta, int threshold, double srn=0, double stn=0 )
|
||||
.. ocv:function:: void HoughLines( InputArray image, OutputArray lines, double rho, double theta, int threshold, double srn=0, double stn=0, double min_theta=0, double max_theta=CV_PI )
|
||||
|
||||
.. ocv:pyfunction:: cv2.HoughLines(image, rho, theta, threshold[, lines[, srn[, stn]]]) -> lines
|
||||
.. ocv:pyfunction:: cv2.HoughLines(image, rho, theta, threshold[, lines[, srn[, stn[, min_theta[, max_theta]]]]]) -> lines
|
||||
|
||||
.. ocv:cfunction:: CvSeq* cvHoughLines2( CvArr* image, void* line_storage, int method, double rho, double theta, int threshold, double param1=0, double param2=0 )
|
||||
.. ocv:cfunction:: CvSeq* cvHoughLines2( CvArr* image, void* line_storage, int method, double rho, double theta, int threshold, double param1=0, double param2=0, double min_theta=0, double max_theta=CV_PI )
|
||||
|
||||
:param image: 8-bit, single-channel binary source image. The image may be modified by the function.
|
||||
|
||||
@ -378,6 +378,10 @@ Finds lines in a binary image using the standard Hough transform.
|
||||
|
||||
:param stn: For the multi-scale Hough transform, it is a divisor for the distance resolution ``theta``.
|
||||
|
||||
:param min_theta: For standard and multi-scale Hough transform, minimum angle to check for lines. Must fall between 0 and max_theta.
|
||||
|
||||
:param max_theta: For standard and multi-scale Hough transform, maximum angle to check for lines. Must fall between min_theta and CV_PI.
|
||||
|
||||
:param method: One of the following Hough transform variants:
|
||||
|
||||
* **CV_HOUGH_STANDARD** classical or standard Hough transform. Every line is represented by two floating-point numbers :math:`(\rho, \theta)` , where :math:`\rho` is a distance between (0,0) point and the line, and :math:`\theta` is the angle between x-axis and the normal to the line. Thus, the matrix must be (the created sequence will be) of ``CV_32FC2`` type
|
||||
|
@ -1147,7 +1147,8 @@ CV_EXPORTS_W void goodFeaturesToTrack( InputArray image, OutputArray corners,
|
||||
//! finds lines in the black-n-white image using the standard or pyramid Hough transform
|
||||
CV_EXPORTS_W void HoughLines( InputArray image, OutputArray lines,
|
||||
double rho, double theta, int threshold,
|
||||
double srn = 0, double stn = 0 );
|
||||
double srn = 0, double stn = 0,
|
||||
double min_theta = 0, double max_theta = CV_PI );
|
||||
|
||||
//! finds line segments in the black-n-white image using probabilistic Hough transform
|
||||
CV_EXPORTS_W void HoughLinesP( InputArray image, OutputArray lines,
|
||||
|
@ -601,7 +601,8 @@ CVAPI(void) cvGoodFeaturesToTrack( const CvArr* image, CvArr* eig_image,
|
||||
param1 ~ srn, param2 ~ stn - for multi-scale */
|
||||
CVAPI(CvSeq*) cvHoughLines2( CvArr* image, void* line_storage, int method,
|
||||
double rho, double theta, int threshold,
|
||||
double param1 CV_DEFAULT(0), double param2 CV_DEFAULT(0));
|
||||
double param1 CV_DEFAULT(0), double param2 CV_DEFAULT(0),
|
||||
double min_theta CV_DEFAULT(0), double max_theta CV_DEFAULT(CV_PI));
|
||||
|
||||
/* Finds circles in the image */
|
||||
CVAPI(CvSeq*) cvHoughCircles( CvArr* image, void* circle_storage,
|
||||
|
@ -75,7 +75,8 @@ Functions return the actual number of found lines.
|
||||
*/
|
||||
static void
|
||||
HoughLinesStandard( const Mat& img, float rho, float theta,
|
||||
int threshold, std::vector<Vec2f>& lines, int linesMax )
|
||||
int threshold, std::vector<Vec2f>& lines, int linesMax,
|
||||
double min_theta, double max_theta )
|
||||
{
|
||||
int i, j;
|
||||
float irho = 1 / rho;
|
||||
@ -87,7 +88,13 @@ HoughLinesStandard( const Mat& img, float rho, float theta,
|
||||
int width = img.cols;
|
||||
int height = img.rows;
|
||||
|
||||
int numangle = cvRound(CV_PI / theta);
|
||||
if (max_theta < 0 || max_theta > CV_PI ) {
|
||||
CV_Error( CV_StsBadArg, "max_theta must fall between 0 and pi" );
|
||||
}
|
||||
if (min_theta < 0 || min_theta > max_theta ) {
|
||||
CV_Error( CV_StsBadArg, "min_theta must fall between 0 and max_theta" );
|
||||
}
|
||||
int numangle = cvRound((max_theta - min_theta) / theta);
|
||||
int numrho = cvRound(((width + height) * 2 + 1) / rho);
|
||||
|
||||
AutoBuffer<int> _accum((numangle+2) * (numrho+2));
|
||||
@ -99,7 +106,7 @@ HoughLinesStandard( const Mat& img, float rho, float theta,
|
||||
|
||||
memset( accum, 0, sizeof(accum[0]) * (numangle+2) * (numrho+2) );
|
||||
|
||||
float ang = 0;
|
||||
float ang = static_cast<float>(min_theta);
|
||||
for(int n = 0; n < numangle; ang += theta, n++ )
|
||||
{
|
||||
tabSin[n] = (float)(sin((double)ang) * irho);
|
||||
@ -166,7 +173,8 @@ static void
|
||||
HoughLinesSDiv( const Mat& img,
|
||||
float rho, float theta, int threshold,
|
||||
int srn, int stn,
|
||||
std::vector<Vec2f>& lines, int linesMax )
|
||||
std::vector<Vec2f>& lines, int linesMax,
|
||||
double min_theta, double max_theta )
|
||||
{
|
||||
#define _POINT(row, column)\
|
||||
(image_src[(row)*step+(column)])
|
||||
@ -293,7 +301,7 @@ HoughLinesSDiv( const Mat& img,
|
||||
|
||||
if( count * 100 > rn * tn )
|
||||
{
|
||||
HoughLinesStandard( img, rho, theta, threshold, lines, linesMax );
|
||||
HoughLinesStandard( img, rho, theta, threshold, lines, linesMax, min_theta, max_theta );
|
||||
return;
|
||||
}
|
||||
|
||||
@ -601,15 +609,15 @@ HoughLinesProbabilistic( Mat& image,
|
||||
|
||||
void cv::HoughLines( InputArray _image, OutputArray _lines,
|
||||
double rho, double theta, int threshold,
|
||||
double srn, double stn )
|
||||
double srn, double stn, double min_theta, double max_theta )
|
||||
{
|
||||
Mat image = _image.getMat();
|
||||
std::vector<Vec2f> lines;
|
||||
|
||||
if( srn == 0 && stn == 0 )
|
||||
HoughLinesStandard(image, (float)rho, (float)theta, threshold, lines, INT_MAX);
|
||||
HoughLinesStandard(image, (float)rho, (float)theta, threshold, lines, INT_MAX, min_theta, max_theta );
|
||||
else
|
||||
HoughLinesSDiv(image, (float)rho, (float)theta, threshold, cvRound(srn), cvRound(stn), lines, INT_MAX);
|
||||
HoughLinesSDiv(image, (float)rho, (float)theta, threshold, cvRound(srn), cvRound(stn), lines, INT_MAX, min_theta, max_theta);
|
||||
|
||||
Mat(lines).copyTo(_lines);
|
||||
}
|
||||
@ -631,7 +639,8 @@ void cv::HoughLinesP(InputArray _image, OutputArray _lines,
|
||||
CV_IMPL CvSeq*
|
||||
cvHoughLines2( CvArr* src_image, void* lineStorage, int method,
|
||||
double rho, double theta, int threshold,
|
||||
double param1, double param2 )
|
||||
double param1, double param2,
|
||||
double min_theta, double max_theta )
|
||||
{
|
||||
cv::Mat image = cv::cvarrToMat(src_image);
|
||||
std::vector<cv::Vec2f> l2;
|
||||
@ -694,11 +703,11 @@ cvHoughLines2( CvArr* src_image, void* lineStorage, int method,
|
||||
{
|
||||
case CV_HOUGH_STANDARD:
|
||||
HoughLinesStandard( image, (float)rho,
|
||||
(float)theta, threshold, l2, linesMax );
|
||||
(float)theta, threshold, l2, linesMax, min_theta, max_theta );
|
||||
break;
|
||||
case CV_HOUGH_MULTI_SCALE:
|
||||
HoughLinesSDiv( image, (float)rho, (float)theta,
|
||||
threshold, iparam1, iparam2, l2, linesMax );
|
||||
threshold, iparam1, iparam2, l2, linesMax, min_theta, max_theta );
|
||||
break;
|
||||
case CV_HOUGH_PROBABILISTIC:
|
||||
HoughLinesProbabilistic( image, (float)rho, (float)theta,
|
||||
|
Loading…
x
Reference in New Issue
Block a user