/*
* Copyright (C) 2021, KylinSoft Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/

#include "imageoperationocr.h"
#include "../saneobject.h"
#include "../include/common.h"
#include <QDebug>
#include <libkyocr.hpp>

ImageOperationOCR::ImageOperationOCR(QImage *origin, QString path)
{
    m_origin = origin;
    m_path = path;
    isInterupt = false;
}

ImageOperationOCR::ImageOperationOCR(QImage *origin)
{
    m_origin = origin;
    isInterupt = false;
}

void ImageOperationOCR::ImageOP(){

    QVector<QString> result;
    kdk::kdkOCR OCR;
    std::vector<std::string> ret = OCR.getCls(m_path.toStdString(), 4);
    std::transform(ret.begin(), ret.end(), std::back_inserter(result), [](const std::string &v) {
        return QString::fromStdString(v);
    });
    QString results = "";
    for(int i = 0; i < result.length(); i++){
        results.append(result.at(i));
    }
    g_sane_object->ocrOutputText = results;
    g_user_signal->toolbarOcrOperationFinished();
    emit finished();
}
