Threshold setting in Canny edge algorithm

I wanted to try my hand at text recognition, so I used opencv to track edges and C ++ to find slopes, curves, etc., the edge algorithm works well on large and uncluttered character sets, but when this happens, small printed text or text with a lot of background noise, such as the captcha embedded in it, which fights and looks incomplete, I assume that I did not set the threshold values ​​correctly and did not fulfill different values ​​without success.

enter image description here

enter image description here

Here is my code:

#include "cv.h"
#include "highgui.h"
using namespace cv;
const int low_threshold  = 50;
const int high_threshold = 150;


int main()
{

    IplImage* newImg; 
    IplImage* grayImg; 
    IplImage* cannyImg; 

    newImg = cvLoadImage("ocv.bmp",1);

    grayImg = cvCreateImage( cvSize(newImg->width, newImg->height), IPL_DEPTH_8U, 1 );

    cvCvtColor( newImg, grayImg, CV_BGR2GRAY );
    cannyImg = cvCreateImage(cvGetSize(newImg), IPL_DEPTH_8U, 1);

    cvCanny(grayImg, cannyImg, low_threshold, high_threshold, 3);
    cvNamedWindow   ("Source", 1);
    cvNamedWindow   ("Destination",1);
    cvShowImage     ("Source", newImg );
    cvShowImage     ("Destination", cannyImg );
    cvWaitKey(0);
    cvDestroyWindow ("Source" );
    cvDestroyWindow ("Destination" );
    cvReleaseImage  (&newImg );
    cvReleaseImage  (&grayImg );
    cvReleaseImage  (&cannyImg );

return 0;

}

I looked through the network and saw some difficult threshold conditions, as in this code from this site:

% Set direction to either 0, 45, -45 or 90 depending on angle.
[x,y]=size(f1);
for i=1:x-1,
    for j=1:y-1,
        if ((gradAngle(i,j)>67.5 && gradAngle(i,j)<=90) || (gradAngle(i,j)>=-90 && gradAngle(i,j)<=-67.5)) 
            gradDirection(i,j)=0;
        elseif ((gradAngle(i,j)>22.5 && gradAngle(i,j)<=67.5))
            gradDirection(i,j)=45;
        elseif ((gradAngle(i,j)>-22.5 && gradAngle(i,j)<=22.5))
            gradDirection(i,j)=90;
        elseif ((gradAngle(i,j)>-67.5 && gradAngle(i,j)<=-22.5))
            gradDirection(i,j)=-45;
        end
    end
end

If this is a solution, can someone provide me with the C ++ equivalent of this algorithm, if that is not what else I can do?

+5
1

- ( ) ( ). wikipedia. , , 70% ( - , ), , . 40% . , , , .

, CAPTCHA-s , , , , (, ).

+5