Ejemplo n.º 1
0
//Extract features of char, input char size is 15*15
Mat OCR::features(Mat in, int sizeData){
    //Histogram features
    Mat vhist=ProjectedHistogram(in, VERTICAL);
    Mat hhist=ProjectedHistogram(in, HORIZONTAL);
    
    //Feature of low resolution data
    Mat lowData;
    resize(in, lowData, Size(sizeData, sizeData) );

    //Show Char Features
    drawVisualFeatures(in, hhist, vhist, lowData);
    
    //Last 10 is the number of moments components
    int numCols=vhist.cols+hhist.cols+lowData.cols*lowData.cols;
    
    Mat out=Mat::zeros(1,numCols,CV_32F);
    //Assign values to feature
    int j=0;
    for(int i=0; i<vhist.cols; i++)
    {
        out.at<float>(j)=vhist.at<float>(i);
        j++;
    }
    for(int i=0; i<hhist.cols; i++)
    {
        out.at<float>(j)=hhist.at<float>(i);
        j++;
    }
    for(int x=0; x<lowData.cols; x++)
    {
        for(int y=0; y<lowData.rows; y++){
            out.at<float>(j)=(float)lowData.at<unsigned char>(x,y);
            j++;
        }
    }
//    if(showSteps) {
//    	cout << "\n==============Char Features================\n";
//        cout << out;
//        cout << "\n===========================================\n";
//        cvWaitKey(0);
//    }
    return out;
}
Ejemplo n.º 2
0
// 特征提取
Mat OCR::features(Mat in, int sizeData) {
    //Histogram features
    Mat vhist = ProjectedHistogram(in, VERTICAL);
    Mat hhist = ProjectedHistogram(in, HORIZONTAL);

    Mat lowData;
    resize(in, lowData, Size(sizeData, sizeData));

    if (DEBUG)
        drawVisualFeatures(in, hhist, vhist, lowData);

    int numCols = vhist.cols + hhist.cols + lowData.cols*lowData.cols;

    Mat out = Mat::zeros(1, numCols, CV_32F);

    int j = 0;
    for (int i = 0; i<vhist.cols; i++)
    {
        out.at<float>(j) = vhist.at<float>(i);
        j++;
    }
    for (int i = 0; i<hhist.cols; i++)
    {
        out.at<float>(j) = hhist.at<float>(i);
        j++;
    }
    for (int x = 0; x<lowData.cols; x++)
    {
        for (int y = 0; y<lowData.rows; y++) {
            out.at<float>(j) = (float)lowData.at<unsigned char>(x, y);
            j++;
        }
    }
    if (DEBUG)
        cout << out << "\n===========================================\n";
    return out;
}