C++ QT +tesseract+opencv3.1 problems

 成功的提升了漢字的識別準確率(感謝老師的幫忙,現在漢字識別準確率基本可以到95%以上了),但是當我在QT中導入文件:

  • I successfully improved the recognition accuracy of Chinese characters (thanks to the teacher's help, the recognition accuracy of Chinese characters can be more than 95% now), but when I imported the file in QT:

#ifndef CHARACTER_TESSERACT_H
#define CHARACTER_TESSERACT_H

//======================================================================
#include "3rdparty/tesseract4/include/tesseract/baseapi.h"
#include "3rdparty/tesseract4/include/leptonica/allheaders.h"
//======================================================================
#include <opencv2/opencv.hpp>
#include <opencv2\ml.hpp>
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
//======================================================================
#include <QDebug>
#include <tuple>
//======================================================================
//using namespace cv;
//using namespace tesseract;
class character_tesseract
{
public:
    character_tesseract();

    std::tuple<QString,double,bool> tesseract_recognition(cv::Mat sheet_image);
};

#endif // CHARACTER_TESSERACT_H

一直出現下面的這個error。在網上查閱是opencv與window中的函數命名衝突。然而我並沒有使用win中的函數接口。這個問題查閱了3個多小時,問題依舊是:

  • The error below keeps appearing.Looking it up on the web is a function name conflict between Opencv and window.However, I didn't use the function interface in WIN.After consulting this question for more than three hours, the question remains:

 原因:opencv3.0或者3.1的using namespace cv和windows.h中ACCESS_MASK定義衝突。 解決方案:註釋掉所有的using namespace cv,然後在需要的地方寫上cv::。 以後寫C++&opencv程序時,儘量不用using namespace ...

  • Reason: OpencV3.0 or 3.1's using Namespace CV and ACCESS_MASK definitions conflict in Windows.h.Solution: Comment out any using Namespace CV, and write CV :: where necessary.When writing C++&opencv programs in the future, try not to use namespace...

我嘗試將文件直接放在*.cpp,奇怪的問題解決了,具體是什麼原因我也沒有搞清楚!!!

  • I tried to put the file directly in *. CPP, but the strange problem was solved. I didn't know the specific reason!!

#include "character_tesseract.h"
#include "3rdparty/tesseract4/include/tesseract/baseapi.h"
#include "3rdparty/tesseract4/include/leptonica/allheaders.h"
character_tesseract::character_tesseract()
{

}

std::tuple<QString,double,bool> character_tesseract::tesseract_recognition(cv::Mat sheet_image)
{
    tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
    cv::Mat gray;
    cv::Mat testimage;
    cv::cvtColor(sheet_image, gray, CV_BGR2GRAY);
    QString outText;
    double confidence_value = 0.0;
    bool isInitSuccess = false;
    if (api->Init(".//tessdata//", "chi_sim",tesseract::OEM_LSTM_ONLY))//chi_sim
    {
        fprintf(stderr, "Could not initialize tesseract.\n");
        isInitSuccess = false;
    }
    else
    {
        isInitSuccess = true;
        api->SetImage((uchar*)gray.data, gray.cols, gray.rows, 1, gray.cols);
        outText = QString(api->GetUTF8Text());
        confidence_value = *api->AllWordConfidences()/100;
        qDebug()<< confidence_value << endl;
        qDebug()<< outText << endl;
        api->End();
    }
    return std::make_tuple(outText,confidence_value,isInitSuccess);
}

I hope I can help you,If you have any questions, please  comment on this blog or send me a private message. I will reply in my free time.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章