Created
December 13, 2018 11:31
-
-
Save maidis/980caa428f9cf1bd804d108f217cb11b to your computer and use it in GitHub Desktop.
A simple OCR application using Tesseract and OpenCV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <string> | |
| #include <tesseract/baseapi.h> | |
| #include <leptonica/allheaders.h> | |
| #include <opencv2/opencv.hpp> | |
| using namespace std; | |
| using namespace cv; | |
| int main(int argc, char* argv[]) | |
| { | |
| string outText; | |
| string imPath = argv[1]; | |
| // Tesseract nesnesini oluştur | |
| tesseract::TessBaseAPI *ocr = new tesseract::TessBaseAPI(); | |
| // tesseract'ı Türkçe (tur) ve yalnızca LSTM motoru kullanacak şekilde ilklendir | |
| ocr->Init(NULL, "tur", tesseract::OEM_LSTM_ONLY); | |
| // Sayfa bölümleme kipini PSM_AUTO (3) olarak ayarla | |
| ocr->SetPageSegMode(tesseract::PSM_AUTO); | |
| // OpenCV'yi kullanarak girdi görüntüsünü aç | |
| Mat im = cv::imread(imPath, IMREAD_COLOR); | |
| // Görüntü verisini ayarla | |
| ocr->SetImage(im.data, im.cols, im.rows, 3, im.step); | |
| // Resimde Tesseract'ı çalıştır | |
| outText = string(ocr->GetUTF8Text()); | |
| // Tanınan metni yazdır | |
| cout << outText << endl; | |
| // Kullanılan nesneyi imha et ve belleği serbest bırak | |
| ocr->End(); | |
| return EXIT_SUCCESS; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment