coc仓库--ocr相关
include "fastdeploy/vision.h"
include
include
include
include
include <unistd.h>
include <tesseract/baseapi.h>
include <leptonica/allheaders.h>
include "opencv2/opencv.hpp"
int homeAttackMapX = 977;
int homeAttackMapY = 1769; // 家乡搜索坐标
int homeLookforX = 666;
int homeLookforY = 394; // 搜索地图
int attackNextX = 782;
int attackNextY = 165; // NEXT
set(FASTDEPLOY_INSTALL_DIR "/home/yuxian/study/cccc/c++pro/FastDeploy/build/compiled_fastdeploy_sdk")
set(FASTDEPLOY_INCS "/home/yuxian/study/cccc/c++pro/FastDeploy/build/compiled_fastdeploy_sdk/include")
set(FASTDEPLOY_LIBS "/home/yuxian/study/cccc/c++pro/FastDeploy/build/compiled_fastdeploy_sdk/lib")
include("/home/yuxian/study/cccc/c++pro/FastDeploy/build/compiled_fastdeploy_sdk/FastDeploy.cmake")
INCLUDE_DIRECTORIES(${FASTDEPLOY_INCS})
set(Tesseract_LIBS "/home/yuxian/study/cccc/c++pro/studyPro/mylib/libtesseract.so")
set(Leptonica_LIBS "/home/yuxian/study/cccc/c++pro/studyPro/mylib/libleptonica.so")
add_executable(studyPro main.cpp basicFunc.cpp ultraFunc.cpp)
target_link_libraries(studyPro PUBLIC ${FASTDEPLOY_LIBS} PRIVATE ${Tesseract_LIBS} PRIVATE ${Leptonica_LIBS})
void mat2black(cv::Mat *matp)
{
for (size_t i = 0; i < (*matp).rows; i++)
{
cv::Vec3b *p = (*matp).ptr<cv::Vec3b>(i);
for (size_t j = 0; j < (*matp).cols; j++)
{
if (253 - p[j][0] > 30 || 233 - p[j][1] > 30 || 255 - p[j][2] > 30)
{
(*matp).at<cv::Vec3b>(i, j) = cv::Vec3b(0, 0, 0);
}
}
}
cv::cvtColor((*matp), (*matp), cv::COLOR_BGR2GRAY);
}
void mat2black2(cv::Mat *matp)
{
for (size_t i = 0; i < (*matp).rows; i++)
{
cv::Vec3b *p = (*matp).ptr<cv::Vec3b>(i);
for (size_t j = 0; j < (*matp).cols; j++)
{
if (207 - p[j][0] > 30 || 250 - p[j][1] > 30 || 255 - p[j][2] > 30)
{
(*matp).at<cv::Vec3b>(i, j) = cv::Vec3b(0, 0, 0);
}
}
}
cv::cvtColor((*matp), (*matp), cv::COLOR_BGR2GRAY);
}
int analyzeOcrChars(char *outText)
{
size_t i = 0;
size_t tmpindex = 0;
char tmp[15];
for (; i < 15; i++)
{
if (outText[i] == '\0')
{
tmp[tmpindex] = outText[i];
if (i == 0)
return -1;
// std::cout << "i == " << i << std::endl;
break;
}
else if (outText[i] == '\n')
{
// std::cout << "i \\n== " << i << std::endl;
}
else if (outText[i] == ' ')
{
// std::cout << "i == " << i << std::endl;
}
else
{
tmp[tmpindex] = outText[i];
tmpindex++;
}
}
return atoi(tmp);
}
void ocr_myjinbi(tesseract::TessBaseAPI *chi_api, cv::Mat *mat_srcp, int *myjinbi)
{
cv::Mat mat2(*mat_srcp, cv::Rect(1600, 37, 240, 60));
mat2black(&mat2);
Pix *image = mat8ToPix(&mat2);
chi_api->SetImage(image);
char *outText = chi_api->GetUTF8Text();
cv::imwrite("../44440.jpeg", mat2);
*myjinbi = analyzeOcrChars(outText);
mat2.release();
delete[] outText;
pixDestroy(&image);
}
void ocr_myshengshui(tesseract::TessBaseAPI *chi_api, cv::Mat *mat_srcp, int *myshengshui)
{
cv::Mat mat2(*mat_srcp, cv::Rect(1600, 137, 240, 60));
mat2black(&mat2);
Pix *image = mat8ToPix(&mat2);
chi_api->SetImage(image);
char *outText = chi_api->GetUTF8Text();
cv::imwrite("../44441.jpeg", mat2);
*myshengshui = analyzeOcrChars(outText);
mat2.release();
delete[] outText;
pixDestroy(&image);
}
void ocr_myheishui(tesseract::TessBaseAPI *chi_api, cv::Mat *mat_srcp, int *myheishui)
{
cv::Mat mat2(*mat_srcp, cv::Rect(1657, 237, 160, 60));
mat2black(&mat2);
Pix *image = mat8ToPix(&mat2);
chi_api->SetImage(image);
char *outText = chi_api->GetUTF8Text();
cv::imwrite("../4444.jpeg", mat2);
*myheishui = analyzeOcrChars(outText);
mat2.release();
delete[] outText;
pixDestroy(&image);
}
void ocr_enemyjinbi(tesseract::TessBaseAPI *chi_api, cv::Mat *mat_srcp, int *enemyjinbi)
{
cv::Mat mat2(*mat_srcp, cv::Rect(80, 130, 220, 50));
mat2black2(&mat2);
Pix *image = mat8ToPix(&mat2);
chi_api->SetImage(image);
char *outText = chi_api->GetUTF8Text();
cv::imwrite("../44444.jpeg", mat2);
*enemyjinbi = analyzeOcrChars(outText);
mat2.release();
delete[] outText;
pixDestroy(&image);
}
void ocr_enemyshengshui(tesseract::TessBaseAPI *chi_api, cv::Mat *mat_srcp, int *ocr_enemyshengshui)
{
cv::Mat mat2(*mat_srcp, cv::Rect(80,170,220,72));
mat2black(&mat2);
Pix *image = mat8ToPix(&mat2);
chi_api->SetImage(image);
char *outText = chi_api->GetUTF8Text();
cv::imwrite("../44443.jpeg", mat2);
*ocr_enemyshengshui = analyzeOcrChars(outText);
mat2.release();
delete[] outText;
pixDestroy(&image);
}
void ocr_enemyheishui(tesseract::TessBaseAPI *chi_api, cv::Mat *mat_srcp, int *enemyheishui)
{
cv::Mat mat2(*mat_srcp, cv::Rect(93, 248, 127, 44));
mat2black(&mat2);
Pix *image = mat8ToPix(&mat2);
chi_api->SetImage(image);
char *outText = chi_api->GetUTF8Text();
cv::imwrite("../4444.jpeg", mat2);
*enemyheishui = analyzeOcrChars(outText);
mat2.release();
delete[] outText;
pixDestroy(&image);
}
void checkIsSIYU(cv::Mat *mat_srcp)
{
int count = 0;
cv::Mat mat2(*mat_srcp, cv::Rect(45, 45, 30, 30));
for (size_t i = 0; i < mat2.rows; i++)
{
cv::Vec3b *p = mat2.ptr<cv::Vec3b>(i);
for (size_t j = 0; j < mat2.cols; j++)
{
if (p[j][0] <100 && p[j][1] <100 && p[j][2]<100)
{
count++;
}
}
}
std::cout<<"count = "<<count<<std::endl;
}
int myjinbi = 0;
ocr_myjinbi(chi_api, &mat, &myjinbi);