无效的分辨率dpi。 Tesseract

时间:2018-09-03 03:34:40

标签: c++ opencv ocr tesseract

enter image description here我对图像进行了一些更改,例如直方图,膨胀,灰度,边缘检测等,以识别图像中的车牌。下面的代码是我在其中分割每个租船人的一部分车牌号并将其存储在Mat中。现在,我想使用tesseract来识别每个字符。但是相反,tesseract会发出此警告。 “警告。无效的分辨率0 dpi。改为使用70。” OCR输出为空。谁能帮我。 注意:目前我只做一张照片。只是检查它是否有效。

if (!Plate.empty())
{

    imshow("Final Plate", Plate);
    waitKey();
    int x = OTSU(Plate);
    Mat BlurBinary = ConvertToBinary(Plate, x);
    Mat BinPlate = BlurBinary.clone();
    imshow("BinaryBlurImg", BlurBinary);
    waitKey();

    vector<vector<Point>>contours2;
    vector<Vec4i>hierachy2;
    findContours(BlurBinary, contours2, hierachy2, RETR_EXTERNAL, CHAIN_APPROX_NONE, Point(0, 0));
    Mat dst1 = Mat::zeros(BlurBinary.size(), CV_8UC3);
    if (!contours1.empty()) {
        int i = 0;
        for (int i = 0; i < contours2.size(); i++) {
            Scalar color((rand() & 255), (rand() & 255), (rand() & 255));
            drawContours(dst1, contours2, i, color, CV_FILLED, 8, hierachy2);

        }

    }

    Rect BlobRect2;
    for (int i = 0; i < contours2.size(); i++) {
        BlobRect2 = boundingRect(contours2[i]);
        if (BlobRect2.height < 10)
        {
            drawContours(BinPlate, contours2, i, black, CV_FILLED, 8, hierachy2);
        }
        else
        {
            Mat character;
            character = Plate(BlobRect2);
            imshow("character", character);
            waitKey();

            imwrite(format("C:/Users/Di/source/repos/LPRrecognition/Characters/Img%d.tif", i), character);

        }

    }
}
else {
    cout << "no plate sorry";
}

char *outText;

tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
// Initialize tesseract-ocr with English, without specifying tessdata path
if (api->Init(NULL, "eng")) {
    fprintf(stderr, "Could not initialize tesseract.\n");
    exit(1);
}

// Open input image with leptonica library
Pix *image1 = pixRead("C:\\Users\\Di\\source\\repos\\LPRrecognition\\Characters\\Img1.tif");

api->SetImage(image1);
// Get OCR result
outText = api->GetUTF8Text();
printf("OCR output:\n%s", outText);
cout << outText;

// Destroy used object and release memory
api->End();
delete[] outText;
pixDestroy(&image1);

0 个答案:

没有答案