Converting Mat to PIX to setImage

喜欢而已 提交于 2019-12-02 04:35:57

Problem is seems to be in a gray image. As tesseract's pix.h header says library works on images with 32-bit per pixel depth. Also tesseract weighs colors, so right alignment of them should be done (opencv on default stores colors as BGR, but tesseract wait RGBA). Resume:

#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h>    
#include <opencv2/opencv.hpp>
...
char imagename[] = "testimg.jpg";
cv::Mat _mat = cv::imread(imagename);
cv::cvtColor(_mat, _mat, CV_BGR2RGBA); 
api.SetImage(_mat.data, _mat.cols, _mat.rows, 4, 4*_mat.cols);
char *outtext = api.GetUTF8Text();
...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!