Prepare complex image for OCR

后端 未结 3 638
执念已碎
执念已碎 2020-12-30 07:29

I want to recognize digits from a credit card. To make things worse, the source image is not guaranteed to be of high quality. The OCR is to be realized through a neural net

3条回答
  •  灰色年华
    2020-12-30 07:54

    in my implementation i tried to use the code from here:http://rnd.azoft.com/algorithm-identifying-barely-legible-embossed-text-image/ results are better but not enough... i find it hard to find the right params for texture cards.

    (void)processingByStrokesMethod:(cv::Mat)src dst:(cv::Mat*)dst { 
    cv::Mat tmp;  
    cv::GaussianBlur(src, tmp, cv::Size(3,3), 2.0);                    // gaussian blur  
    tmp = cv::abs(src - tmp);                                          // matrix of differences between source image and blur iamge  
    
    //Binarization:  
    cv::threshold(tmp, tmp, 0, 255, CV_THRESH_BINARY | CV_THRESH_OTSU);  
    
    //Using method of strokes:  
    int Wout = 12;  
    int Win = Wout/2;  
    int startXY = Win;  
    int endY = src.rows - Win;  
    int endX = src.cols - Win;  
    
    for (int j = startXY; j < endY; j++) {  
        for (int i = startXY; i < endX; i++) {  
            //Only edge pixels:  
            if (tmp.at(j,i) == 255)  
            {  
                //Calculating maxP and minP within Win-region:  
                unsigned char minP = src.at(j,i);  
                unsigned char maxP = src.at(j,i);  
                int offsetInWin = Win/2;  
    
                for (int m = - offsetInWin; m < offsetInWin; m++) {  
                    for (int n = - offsetInWin; n < offsetInWin; n++) {  
                        if (src.at(j+m,i+n) < minP) {  
                            minP = src.at(j+m,i+n);  
                        }else if (src.at(j+m,i+n) > maxP) {  
                            maxP = src.at(j+m,i+n);  
                        }  
                    }  
                }  
    
                //Voiting:  
                unsigned char meanP = lroundf((minP+maxP)/2.0);  
    
                for (int l = -Win; l < Win; l++) {  
                    for (int k = -Win; k < Win; k++) {  
                        if (src.at(j+l,i+k) >= meanP) {  
                            dst->at(j+l,i+k)++;  
                        }  
                    }  
                }  
            }  
        }  
    }  
    
    ///// Normalization of imageOut:  
    unsigned char maxValue = dst->at(0,0);  
    
    for (int j = 0; j < dst->rows; j++) {              //finding max value of imageOut  
        for (int i = 0; i < dst->cols; i++) {  
            if (dst->at(j,i) > maxValue)  
                maxValue = dst->at(j,i);  
        }  
    }  
    float knorm = 255.0 / maxValue;  
    
    for (int j = 0; j < dst->rows; j++) {             //normalization of imageOut  
        for (int i = 0; i < dst->cols; i++) {  
            dst->at(j,i) = lroundf(dst->at(j,i)*knorm);  
        }  
    }  
    

提交回复
热议问题