Added get_best_hough_point() to the hough_transform object.

This commit is contained in:
Davis King 2015-03-21 08:45:17 -04:00
parent f8e91c4f89
commit 0aad39c4e8
2 changed files with 166 additions and 0 deletions

View File

@ -8,6 +8,7 @@
#include "../geometry.h"
#include "../algs.h"
#include "assign_image.h"
#include <limits>
namespace dlib
{
@ -99,6 +100,144 @@ namespace dlib
return std::make_pair(p1,p2);
}
template <
typename image_type
>
point get_best_hough_point (
const point& p,
const image_type& himg
)
{
DLIB_ASSERT(himg.nr() == size() && himg.nc() == size() &&
rectangle(0,0,size()-1,size()-1).contains(p) == true,
"\t point hough_transform::get_best_hough_point()"
<< "\n\t Invalid arguments given to this function."
<< "\n\t himg.nr(): " << himg.nr()
<< "\n\t himg.nc(): " << himg.nc()
<< "\n\t size(): " << size()
<< "\n\t p: " << p
);
typedef typename image_traits<image_type>::pixel_type pixel_type;
COMPILE_TIME_ASSERT(pixel_traits<pixel_type>::grayscale == true);
pixel_type best_val = std::numeric_limits<pixel_type>::min();
point best_point;
const long max_n8 = (himg.nc()/8)*8;
const long max_n4 = (himg.nc()/4)*4;
const long r = p.y();
const long c = p.x();
const int32* ysin = &ysin_theta(r,0);
const int32* xcos = &xcos_theta(c,0);
long t = 0;
while(t < max_n8)
{
long rr0 = (*xcos++ + *ysin++)>>16;
long rr1 = (*xcos++ + *ysin++)>>16;
long rr2 = (*xcos++ + *ysin++)>>16;
long rr3 = (*xcos++ + *ysin++)>>16;
long rr4 = (*xcos++ + *ysin++)>>16;
long rr5 = (*xcos++ + *ysin++)>>16;
long rr6 = (*xcos++ + *ysin++)>>16;
long rr7 = (*xcos++ + *ysin++)>>16;
if (himg[rr0][t++] > best_val)
{
best_val = himg[rr0][t-1];
best_point.x() = t-1;
best_point.y() = rr0;
}
if (himg[rr1][t++] > best_val)
{
best_val = himg[rr1][t-1];
best_point.x() = t-1;
best_point.y() = rr1;
}
if (himg[rr2][t++] > best_val)
{
best_val = himg[rr2][t-1];
best_point.x() = t-1;
best_point.y() = rr2;
}
if (himg[rr3][t++] > best_val)
{
best_val = himg[rr3][t-1];
best_point.x() = t-1;
best_point.y() = rr3;
}
if (himg[rr4][t++] > best_val)
{
best_val = himg[rr4][t-1];
best_point.x() = t-1;
best_point.y() = rr4;
}
if (himg[rr5][t++] > best_val)
{
best_val = himg[rr5][t-1];
best_point.x() = t-1;
best_point.y() = rr5;
}
if (himg[rr6][t++] > best_val)
{
best_val = himg[rr6][t-1];
best_point.x() = t-1;
best_point.y() = rr6;
}
if (himg[rr7][t++] > best_val)
{
best_val = himg[rr7][t-1];
best_point.x() = t-1;
best_point.y() = rr7;
}
}
while(t < max_n4)
{
long rr0 = (*xcos++ + *ysin++)>>16;
long rr1 = (*xcos++ + *ysin++)>>16;
long rr2 = (*xcos++ + *ysin++)>>16;
long rr3 = (*xcos++ + *ysin++)>>16;
if (himg[rr0][t++] > best_val)
{
best_val = himg[rr0][t-1];
best_point.x() = t-1;
best_point.y() = rr0;
}
if (himg[rr1][t++] > best_val)
{
best_val = himg[rr1][t-1];
best_point.x() = t-1;
best_point.y() = rr1;
}
if (himg[rr2][t++] > best_val)
{
best_val = himg[rr2][t-1];
best_point.x() = t-1;
best_point.y() = rr2;
}
if (himg[rr3][t++] > best_val)
{
best_val = himg[rr3][t-1];
best_point.x() = t-1;
best_point.y() = rr3;
}
}
while(t < himg.nc())
{
long rr0 = (*xcos++ + *ysin++)>>16;
if (himg[rr0][t++] > best_val)
{
best_val = himg[rr0][t-1];
best_point.x() = t-1;
best_point.y() = rr0;
}
}
return best_point;
}
template <
typename in_image_type,
typename out_image_type

View File

@ -21,6 +21,10 @@ namespace dlib
contribute correspondingly more to the output of the Hough transform,
allowing stronger edges to create correspondingly stronger line detections
in the final Hough transform.
THREAD SAFETY
It is safe for multiple threads to make concurrent accesses to this object
without synchronization.
!*/
public:
@ -74,6 +78,29 @@ namespace dlib
- The returned points are inside rectangle(0,0,size()-1,size()-1).
!*/
template <
typename image_type
>
point get_best_hough_point (
const point& p,
const image_type& himg
);
/*!
requires
- image_type == an image object that implements the interface defined in
dlib/image_processing/generic_image.h and it must contain grayscale pixels.
- himg.nr() == size()
- himg.nc() == size()
- rectangle(0,0,size()-1,size()-1).contains(p) == true
ensures
- This function interprets himg as a Hough image and p as a point in the
original image space. Given this, it finds the maximum scoring line that
passes though p. That is, it checks all the Hough accumulator bins in
himg corresponding to lines though p and returns the location with the
largest score.
- returns a point X such that get_rect(himg).contains(X) == true
!*/
template <
typename in_image_type,
typename out_image_type