SklavaBot 0.1.0
Telegram Bot in C++
Loading...
Searching...
No Matches
ocr.cpp
Go to the documentation of this file.
1#include <boost/date_time/posix_time/conversion.hpp>
2#include <boost/date_time/posix_time/posix_time.hpp>
3#include <chrono>
4#include <iostream>
5#include <leptonica/allheaders.h>
6#include <string>
7#include <tesseract/baseapi.h>
8
9#include "utils.hpp"
10
11namespace tools {
12
13std::string getTextFromImage(Pix *image) {
14 char *outText;
15 tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
16 // Initialize tesseract-ocr with English, without specifying tessdata path
17 if (api->Init(NULL, "eng")) {
18 log_cmd("Unable to initialize tesseract-ocr", "OCR",
19 boost::posix_time::to_time_t(
20 boost::posix_time::second_clock::universal_time()),
22 exit(1);
23 }
24
25 api->SetImage(image);
26 outText = api->GetUTF8Text();
27
28 api->End();
29 delete api;
30
31 return std::string(outText);
32}
33
34} // namespace tools
const std::string Error
Definition utils.hpp:46
Definition metar.hpp:6
void log_cmd(std::string command, std::string user, std::int32_t timestamp, const std::string log_type)
Function to print a better log.
Definition utils.cpp:17
std::string getTextFromImage(Pix *image)
Definition ocr.cpp:13