繁体   English   中英

如何识别模拟计数器的数字?

[英]How to recognize digits from the analog counter?

我正试图从柜台读取以下千瓦时数字。 问题是tesseract OCR无法识别模拟数字。

计数器

问题是:在不同的位置制作所有数字(从0到9)的照片会更好吗(我的意思是当数字位于中心时,当它位于顶部且数字2时正在出现等)并尝试图像识别而不是文本识别?

据我所知,区别在于,图像识别比较照片,而文字识别......我不知道......

有什么建议?

由于计数器不是数字的,而是模拟的,我们在转换时遇到问题。 文本/数字识别库无法像这样识别smth。 我发现的解决方案是: 机器学习

首先,我让用户制作图片,其中数字占图像的70-80%(为了删除不需要的细节)。

然后我正在寻找平行线(如果有的话)并剪切图片,即它们之间(如果距离足够大)。

之后,我正在过滤图片(使用对比度,亮度,设置灰度),然后使用滤镜,使图像只包含两种颜色( #000000 (黑色)和#ffffff (白色))。 为了更容易找到轮廓。

然后我通过使用Canny算法找到轮廓并通过删除不需要的细节来过滤它们。

之后,我使用K-Nearest-Neighbour算法来识别数字。

但在我能够识别任何东西之前,我需要教授算法,数字的外观以及它们是什么。

我希望它有用!

也许你没有正确配置tesseract。 我使用它编写了一个代码来解决你的问题:

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <tesseract/baseapi.h>
#include <iostream>

using namespace cv;

int main(int argc, char** argv)
{
    cv::Mat input = cv::imread("img.jpg");

    //rectangle containing just the kWh numbers
    Rect roi(358,327,532,89);

    //convert to gray scale
    Mat input_gray;
    cvtColor(input(roi),input_gray,CV_BGR2GRAY);

    //threshold image
    Mat binary_img = input_gray>200;

    //make a copy to use on findcontours
    Mat copy_binary_img = binary_img.clone();

    vector<vector<Point> > contours;
    vector<Vec4i> hierarchy;

    //identify each blob in order to eliminate the small ones 
    findContours(copy_binary_img, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0,0));

    //filter blobs by their sizes
    for (vector<vector<Point> >::iterator it = contours.begin(); it!=contours.end(); )
    {
        if (it->size()>20)
            it=contours.erase(it);
        else
            ++it;
    }

    //Erase blobs which have countour size smaller than 20
    for( int i = 0; i< contours.size(); i++ )
    {
        drawContours( binary_img, contours, i, 0, -1, 8, hierarchy, 0, Point() );
    }

    //initialize tesseract OCR
    tesseract::TessBaseAPI tess;
    tess.Init(NULL, "eng", tesseract::OEM_DEFAULT);

    tess.SetVariable("tessedit_char_whitelist", "0123456789-.");

    tess.SetPageSegMode(tesseract::PSM_SINGLE_BLOCK);

    //set input 
    tess.SetImage((uchar*)binary_img.data
            , binary_img.cols
            , binary_img.rows
            , 1
            , binary_img.cols);

    // Get the text
    char* out = tess.GetUTF8Text();
    std::cout << out << std::endl;
    waitKey();
    return 0;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM