Skip to content

Commit

Permalink
Use variable step size in stroke width ray construction.
Browse files Browse the repository at this point in the history
  • Loading branch information
aperrault committed Jul 7, 2012
1 parent 3d1b1e3 commit fe79952
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions TextDetection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ void strokeWidthTransform (IplImage * edgeImage,
IplImage * SWTImage,
std::vector<Ray> & rays) {
// First pass
float prec = .05;
float eps = 0.0001;
for( int row = 0; row < edgeImage->height; row++ ){
const uchar* ptr = (const uchar*)(edgeImage->imageData + row * edgeImage->widthStep);
for ( int col = 0; col < edgeImage->width; col++ ){
Expand All @@ -407,6 +407,7 @@ void strokeWidthTransform (IplImage * edgeImage,
int curPixY = row;
float G_x = CV_IMAGE_ELEM ( gradientX, float, row, col);
float G_y = CV_IMAGE_ELEM ( gradientY, float, row, col);
float xdist,ydist,incr;
// normalize gradient
float mag = sqrt( (G_x * G_x) + (G_y * G_y) );
if (dark_on_light){
Expand All @@ -417,9 +418,26 @@ void strokeWidthTransform (IplImage * edgeImage,
G_y = G_y/mag;

}
//std::cout << G_x << " " << G_y << std::endl;
while (true) {
curX += G_x*prec;
curY += G_y*prec;
// populate curX and curY
if (G_x < 0) {
xdist = curX - floor(curX);
} else {
xdist = ceil(curX) - curX;
}
if (G_y < 0) {
ydist = curY - floor(curY);
} else {
ydist = ceil(curY) - curY;
}
incr = std::min(std::abs(ydist/G_y),std::abs(xdist/G_x))+eps;
//std::cout << std::abs(ydist/G_y) << ' ' << std::abs(xdist/G_x) << std::endl;
//std::cout << curX << ' ' << curY << std::endl;
//std::cout << incr << std::endl;
//std::cout.flush();
curX += G_x*incr;
curY += G_y*incr;
if ((int)(floor(curX)) != curPixX || (int)(floor(curY)) != curPixY) {
curPixX = (int)(floor(curX));
curPixY = (int)(floor(curY));
Expand Down

0 comments on commit fe79952

Please sign in to comment.