| 1 |
/* |
| 2 |
* This file is part of the apvlv package |
| 3 |
* |
| 4 |
* Copyright (C) 2008 Alf. |
| 5 |
* |
| 6 |
* Contact: Alf <[email protected]> |
| 7 |
* |
| 8 |
* This program is free software; you can redistribute it and/or |
| 9 |
* modify it under the terms of the GNU General Public License |
| 10 |
* as published by the Free Software Foundation; either version 2.0 of |
| 11 |
* the License, or (at your option) any later version. |
| 12 |
* |
| 13 |
* This program is distributed in the hope that it will be useful, but |
| 14 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
* General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU General Public |
| 19 |
* License along with this program; if not, write to the Free Software |
| 20 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 |
* |
| 22 |
*/ |
| 23 |
/* @CPPFILE ApvlvOCR.cc |
| 24 |
* |
| 25 |
* Author: Alf <[email protected]> |
| 26 |
*/ |
| 27 |
|
| 28 |
#include "ApvlvOCR.h" |
| 29 |
#include "ApvlvParams.h" |
| 30 |
|
| 31 |
namespace apvlv |
| 32 |
{ |
| 33 |
|
| 34 |
using namespace std; |
| 35 |
|
| 36 |
OCR::OCR () |
| 37 |
{ |
| 38 |
auto lang = ApvlvParams::instance ()->getGroupStringOrDefault ( |
| 39 |
"ocr", "lang", "eng+chi_sim"); |
| 40 |
mTessBaseAPI.Init (nullptr, lang.c_str ()); |
| 41 |
} |
| 42 |
|
| 43 |
OCR::~OCR () { mTessBaseAPI.End (); } |
| 44 |
|
| 45 |
std::unique_ptr<TextAreaVector> |
| 46 |
OCR::getTextArea (const QPixmap &pixmap) |
| 47 |
{ |
| 48 |
return nullptr; |
| 49 |
} |
| 50 |
|
| 51 |
std::unique_ptr<char> |
| 52 |
OCR::getTextFromPixmap (const QPixmap &pixmap, QRect area) |
| 53 |
{ |
| 54 |
auto image = pixmap.toImage (); |
| 55 |
image = image.convertToFormat (QImage::Format_RGB888); |
| 56 |
mTessBaseAPI.SetImage (image.bits (), image.width (), image.height (), 3, |
| 57 |
static_cast<int> (image.bytesPerLine ())); |
| 58 |
auto text = mTessBaseAPI.GetUTF8Text (); |
| 59 |
if (area.isValid ()) |
| 60 |
{ |
| 61 |
mTessBaseAPI.SetRectangle (area.left (), area.top (), area.width (), |
| 62 |
area.height ()); |
| 63 |
} |
| 64 |
mTessBaseAPI.Clear (); |
| 65 |
return unique_ptr<char> (text); |
| 66 |
} |
| 67 |
|
| 68 |
} |