我正试着从柜台上读出以下kWh号码。问题是tesseract OCR不识别模拟数字。

问题是:把所有数字的照片(从0到9)放在不同的位置(我的意思是指数字在中间,当数字在顶部,数字2出现等)会更好吗?试着用图像识别代替文本识别?
据我所知,不同的是,图像识别比较照片,而文本识别.我不知道..。
有什么建议吗?
发布于 2015-08-20 09:47:49
由于计数器不是数字的,而是模拟的,我们在过渡时有问题。文本/数字识别库不能识别这样的符号。我发现的解决方案是:机器学习。
首先,我让用户制作图片,其中数字占图像的70-80% (为了删除不必要的细节)。
然后我正在寻找平行线(如果有)和剪切图片,即在他们之间(如果距离足够大)。
之后,我过滤图片(播放对比度,亮度,设置灰度),然后使用过滤器,使图像只包含两种颜色(#000000 (黑色)和#ffffff (白色))。以便更容易地找到轮廓。
然后,我使用Canny算法找到轮廓,并对它们进行过滤,去除不必要的细节。
在此之后,我使用K-Nearest-Neighbour算法来识别数字。
,但是在我能识别出任何东西之前,我需要教算法,数字是什么样子的,它们是什么。
我希望这是有用的!
发布于 2015-08-05 00:13:40
也许您没有正确配置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;
}https://stackoverflow.com/questions/31818636
复制相似问题