c++ - How may I remove "1.#QNAN" and "INF" error in gradient (float type) with image in case of inf or 0? -


in code extract text image (stroke width transform), using gradients @ specific pixels. in following code: gradientx, gradienty mat images. g_x , g_y gradients @ (row, col) pixel. getting error because g_x , g_y becoming out of bounds (1.#qnan 1.inf) in many cases. in cases, both become such mag becomes inf or 1.#qnan . please suggest change code such problem can mitigated? normalize them 1 in case of inf , make changes similarly.

            float g_x = gradientx.ptr<float>(row)[col];             float g_y = gradienty.ptr<float>(row)[col];             // normalize gradient             double mag =  sqrt( (g_x * g_x) + (g_y * g_y) );             if (dark_on_light){                 g_x = -g_x/mag;                 g_y = -g_y/mag;             } else {                 g_x = g_x/mag;                 g_y = g_y/mag;              } 


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -