-
Notifications
You must be signed in to change notification settings - Fork 0
/
imagereader.cpp
39 lines (36 loc) · 1.19 KB
/
imagereader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "imagereader.h"
#include <QDebug>
#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h>
#include <locale.h>
#include <QStringList>
ImageReader::ImageReader()
{
qDebug() << "Init ImageReader()";
}
//Takes a path to an image
//Uses OCR on the image
//Returns the needed text fields from the receipt for survey filling
QStringList ImageReader::readImage(QString fileName)
{
qDebug() << "Reading image: " + fileName;
//Init fieldContents to store the fields we find
QStringList fieldContents;
//Init Tesseract
tesseract::TessBaseAPI* tesseract = new tesseract::TessBaseAPI();
setlocale(LC_NUMERIC, "C");
if(tesseract->Init(NULL, "eng")) {
qDebug() << "Could not init tesseract";
return fieldContents;
}
//OCR the image in the file
Pix* image = pixRead(fileName.toUtf8());
//TODO: MANIPULATE THE IMAGE TO MAKE OCR BETTER
tesseract->SetImage(image);
QString output(tesseract->GetUTF8Text());
qDebug() << "OCR DONE";
//TODO: Fill fieldContents with the actual content from OCR (Parse OCR)
fieldContents << "65355" << "3/17/16" << "0000049822" << "16:38:03";
qDebug() << fieldContents;
return fieldContents;
}