File indexing completed on 2025-01-19 03:52:36

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2022-08-26
0007  * Description : OCR Tesseract engine
0008  *
0009  * SPDX-FileCopyrightText: 2008-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 2022      by Quoc Hung Tran <quochungtran1999 at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #ifndef OCR_TESSERACT_ENGINE_H
0017 #define OCR_TESSERACT_ENGINE_H
0018 
0019 // Qt includes
0020 
0021 #include <QString>
0022 #include <QObject>
0023 #include <QUrl>
0024 
0025 // Local includes
0026 
0027 #include "ocroptions.h"
0028 #include "dmetadata.h"
0029 
0030 using namespace Digikam;
0031 
0032 namespace DigikamGenericTextConverterPlugin
0033 {
0034 
0035 class OcrTesseractEngine : public QObject
0036 {
0037     Q_OBJECT
0038 
0039 public:
0040 
0041     enum ConvertError
0042     {
0043         PROCESS_CONTINUE =  1,        ///< Current stages is done.
0044         PROCESS_COMPLETE =  0,        ///< All stages done.
0045         PROCESS_FAILED   = -1,        ///< A failure happen while processing.
0046         PROCESS_CANCELED = -2,        ///< User has canceled processing.
0047     };
0048 
0049 public:
0050 
0051     explicit OcrTesseractEngine();
0052     ~OcrTesseractEngine();
0053 
0054     QString inputFile()          const;
0055     QString outputFile()         const;
0056     QString outputText()         const;
0057 
0058     void setInputFile(const QString& filePath);
0059     void setOutputFile(const QString& filePath);
0060 
0061     OcrOptions ocrOptions() const;
0062     void setOcrOptions(const OcrOptions& opt);
0063 
0064 public:
0065 
0066     static void translate(MetaEngine::AltLangMap& commentsMap,
0067                           const QStringList& langs);
0068 
0069     static void saveTextFile(const QString& inFile,
0070                              QString& outFile,
0071                              const MetaEngine::AltLangMap& commentsMap);
0072 
0073     static void saveXMP(const QUrl& url,
0074                         const MetaEngine::AltLangMap& commentsMap,
0075                         DInfoInterface* const iface);
0076 
0077     int  runOcrProcess();
0078 
0079     void cancelOcrProcess();
0080 
0081 private:
0082 
0083     // Disable
0084 
0085     OcrTesseractEngine(const OcrTesseractEngine&)            = delete;
0086     OcrTesseractEngine& operator=(const OcrTesseractEngine&) = delete;
0087 
0088 private:
0089 
0090     void saveOcrResult();
0091 
0092 private:
0093 
0094     class Private;
0095     Private* const d;
0096 };
0097 
0098 } // namespace DigikamGenericTextConverterPlugin
0099 
0100 #endif // OCR_TESSERACT_ENGINE_H