#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();
}
