Pix *mat8ToPix(cv::Mat *mat8)
{
Pix *pixd = pixCreate(mat8->size().width, mat8->size().height, 8);
for(int y=0; y<mat8->rows; y++) {
for(int x=0; x<mat8->cols; x++) {
pixSetPixel(pixd, x, y, (l_uint32) mat8->at<uchar>(y,x));
}
}
return pixd;
}
tesseract::TessBaseAPI *chi_api = new tesseract::TessBaseAPI();
if (chi_api->Init("/usr/share/tesseract-ocr/4.00/tessdata/", "chi"))
{
fprintf(stderr, "Could not initialize tesseract.\n");
exit(1);
}
cv::Mat mat ;
//= cv::imread("/home/yuxian/study/cccc/c++pro/studyPro/333.png", 0);
const std::string ADB_IP = "cdc3f475";
screenShot(&ADB_IP, &mat);
gettime();
cv::Mat mat2 (mat,cv::Rect(1577,37,240,60));
std::cout <<"size = "<<mat.size<<std::endl;
gettime();
for (size_t i = 0; i < mat.rows; i++)
{
cv::Vec3b *p = mat.ptr<cv::Vec3b>(i);
for (size_t j = 0; j < mat.cols; j++)
{
//std::cout << mat.at<cv::Vec3b>(i,j) <<std::endl;
if(253-p[j][0] > 30 || 233-p[j][1] > 30 || 255-p[j][2] > 30){
mat.at<cv::Vec3b>(i,j) = cv::Vec3b (0,0,0);
}
}
}
cv::cvtColor(mat2,mat2,cv::COLOR_BGR2GRAY);
Pix *image = mat8ToPix(&mat2);
chi_api->SetImage(image);
char *outText = chi_api->GetUTF8Text();
std::string re = outText;
//printf("OCR output:\n%s", outText);
std::cout <<re <<std::endl;
gettime();
cv::imwrite("../4444.jpeg",mat2);
标签:std,mat2,mat,--,chi,coc,api,pix2mat,cv
From: https://www.cnblogs.com/yuxiannana/p/17564469.html