HGbase 使用动态调用方式
This commit is contained in:
parent
18464bcc18
commit
c5615fcb7f
|
@ -1913,6 +1913,7 @@ int hg_scanner::setting_text_direction(int sn, void* data)
|
|||
}
|
||||
else if (image_prc_param_.bits.text_direction != TEXT_DIRECTION_AUTO && ImagePrc_pHandle_)
|
||||
{
|
||||
printf("77777777777777777777777777777777\r\n");
|
||||
hg_imgproc::free_auto_txt_hanld(ImagePrc_pHandle_);
|
||||
}
|
||||
return ret;
|
||||
|
|
|
@ -70,13 +70,31 @@ using namespace std;
|
|||
#define IMAGE_DATA_BUF_CVMAT (void*)MAKE_INT('M', 'T', 'R', 'X')
|
||||
#define IMAGE_DATA_BUF_CHAR (void*)MAKE_INT('C', 'H', 'A', 'R')
|
||||
|
||||
//动态打开库的命名
|
||||
#ifdef OEM_HANWANG
|
||||
#define IMGPRC_LIBNANE_WIN L"HWImgProc.dll"
|
||||
|
||||
#ifdef WIN32
|
||||
#define IMGPRC_LIBNANE L"HWImgProc.dll"
|
||||
#define HGBASE_LIBNAME L"HWBase.dll"
|
||||
#else
|
||||
#define IMGPRC_LIBNANE "libHWImgProc.so"
|
||||
#define HGBASE_LIBNAME "libHWBase.so"
|
||||
#endif
|
||||
#elif defined(OEM_LISICHENG)
|
||||
#define IMGPRC_LIBNANE_WIN L"LSCImgProc.dll"
|
||||
#ifdef WIN32
|
||||
#define IMGPRC_LIBNANE L"LSCImgProc.dll"
|
||||
#define HGBASE_LIBNAME L"LSCBase.dll"
|
||||
#else
|
||||
#define IMGPRC_LIBNANE "libLSCImgProc.so"
|
||||
#define HGBASE_LIBNAME "libLSCBase.so"
|
||||
#endif
|
||||
#else
|
||||
#define IMGPRC_LIBNANE_WIN L"HGImgProc.dll"
|
||||
#ifdef WIN32
|
||||
#define IMGPRC_LIBNANE L"HGImgProc.dll"
|
||||
#define HGBASE_LIBNAME L"HGBase.dll""
|
||||
#else
|
||||
#define IMGPRC_LIBNANE "libHGImgProc.so"
|
||||
#define HGBASE_LIBNAME "libHGBase.so"
|
||||
#endif
|
||||
#endif
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// functional ...
|
||||
|
@ -134,9 +152,12 @@ namespace hg_imgproc
|
|||
}
|
||||
};
|
||||
|
||||
typedef unsigned int (*SDKInitialize_)(unsigned int ocrtype, void** pstOcrHandle);
|
||||
typedef unsigned int (*SDKExit_)(void* pstOcrHandle);
|
||||
typedef unsigned int (*SDKGetFileDirectImage_)(void* pstOcrHandle, void* image, unsigned int* pDirect);
|
||||
typedef unsigned int (*SDKHGImgProc_InitOCR_)(unsigned int ocrtype, void** pstOcrHandle);
|
||||
typedef unsigned int (*SDKHGImgProc_FreeImage_)(void* pstOcrHandle);
|
||||
typedef unsigned int (*SDKHGImgProc_GetTextDir_)(void* pstOcrHandle, void* image, unsigned int* pDirect);
|
||||
|
||||
typedef unsigned int (*SDKHGBase_CreateImage_)(void* data, void* imageinfo, void* image);
|
||||
typedef unsigned int (*SDKHGBase_FreeImage_)(void* image);
|
||||
class imgproc
|
||||
{
|
||||
std::string my_path_;
|
||||
|
@ -149,15 +170,20 @@ namespace hg_imgproc
|
|||
Device::PaperSize papersize_;
|
||||
SANE_Image_Statu img_statu_;
|
||||
|
||||
SDKInitialize_ ocrinit_ = NULL;
|
||||
SDKGetFileDirectImage_ ocrgetdirectimage_ = NULL;
|
||||
SDKExit_ ocrexit_ = NULL;
|
||||
SDKHGImgProc_InitOCR_ ocrinit_ = NULL;
|
||||
SDKHGImgProc_GetTextDir_ ocrgetdirectimage_ = NULL;
|
||||
SDKHGImgProc_FreeImage_ ocrexit_ = NULL;
|
||||
|
||||
SDKHGBase_CreateImage_ HGBase_CreatImg = NULL;
|
||||
SDKHGBase_FreeImage_ HGBase_FreeImg = NULL;
|
||||
|
||||
void* Auto_Txt_pHanld = NULL;
|
||||
#ifndef WIN32
|
||||
void *Dynamicopen_pHandle_;
|
||||
void *Dynamicopen_HGBase_pHandle_;
|
||||
void *Dynamicopen_HGImageprc_pHandle_;
|
||||
#else
|
||||
HINSTANCE Dynamicopen_pHandle_;
|
||||
HINSTANCE Dynamicopen_HGBase_pHandle_;
|
||||
HINSTANCE Dynamicopen_HGImageprc_pHandle_;
|
||||
#endif
|
||||
|
||||
void swap_rgb(cv::Mat& mat)
|
||||
|
@ -186,7 +212,9 @@ namespace hg_imgproc
|
|||
my_path_ = hg_log::pe_path();
|
||||
}
|
||||
~imgproc()
|
||||
{}
|
||||
{
|
||||
free_auto_txt_hanld();
|
||||
}
|
||||
|
||||
// load data
|
||||
public:
|
||||
|
@ -266,30 +294,45 @@ namespace hg_imgproc
|
|||
return SCANNER_ERR_OUT_OF_RANGE;
|
||||
}
|
||||
scanner_path = scanner_path.substr(0, scanner_path.size() - libname.size());
|
||||
scanner_path += "libhwocrdetect.so";
|
||||
printf("hwlib path:%s\r\n", scanner_path.c_str());
|
||||
|
||||
if (access(scanner_path.c_str(), F_OK) != 0)
|
||||
string HGImagePrclib_path = scanner_path + IMGPRC_LIBNANE;
|
||||
string HGBaselib_path = scanner_path + HGBASE_LIBNAME;
|
||||
|
||||
printf("get auto txt path is:%s\r\n", scanner_path.c_str());
|
||||
|
||||
if (access(HGBaselib_path.c_str(), F_OK) != 0 && access(HGImagePrclib_path.c_str(), F_OK) != 0)
|
||||
{
|
||||
printf("111111111111111111111111111\r\n");
|
||||
return SCANNER_ERR_OUT_OF_RANGE;
|
||||
}
|
||||
printf("HGBaselib_path:%s HGImagePrclib_path:%s\r\n",HGBaselib_path.c_str(),HGImagePrclib_path.c_str());
|
||||
|
||||
Dynamicopen_HGImageprc_pHandle_ = dlopen(HGImagePrclib_path.c_str(), RTLD_LAZY);
|
||||
Dynamicopen_HGBase_pHandle_ = dlopen(HGBaselib_path.c_str(), RTLD_LAZY);
|
||||
|
||||
if (!Dynamicopen_HGBase_pHandle_ && !Dynamicopen_HGImageprc_pHandle_)
|
||||
{
|
||||
return SCANNER_ERR_OUT_OF_RANGE;
|
||||
}
|
||||
|
||||
Dynamicopen_pHandle_ = dlopen(scanner_path.c_str(), RTLD_LAZY);
|
||||
if (!Dynamicopen_pHandle_)
|
||||
{
|
||||
return SCANNER_ERR_OUT_OF_RANGE;
|
||||
}
|
||||
ocrinit_ = (SDKInitialize_)dlsym(Dynamicopen_pHandle_, "HGImgProc_CreateOCRMgr");
|
||||
ocrgetdirectimage_ = (SDKGetFileDirectImage_)dlsym(Dynamicopen_pHandle_, "HGImgProc_ImageTextDirectOCR");
|
||||
ocrexit_ = (SDKExit_)dlsym(Dynamicopen_pHandle_, "HGImgProc_DestroyOCRMgr");
|
||||
ocrinit_ = (SDKHGImgProc_InitOCR_)dlsym(Dynamicopen_HGImageprc_pHandle_, "HGImgProc_CreateOCRMgr");
|
||||
ocrgetdirectimage_ = (SDKHGImgProc_GetTextDir_)dlsym(Dynamicopen_HGImageprc_pHandle_, "HGImgProc_ImageTextDirectOCR");
|
||||
ocrexit_ = (SDKHGImgProc_FreeImage_)dlsym(Dynamicopen_HGImageprc_pHandle_, "HGImgProc_DestroyOCRMgr");
|
||||
|
||||
HGBase_CreatImg = (SDKHGBase_CreateImage_)dlsym(Dynamicopen_HGBase_pHandle_,"HGBase_CreateImageWithData");
|
||||
HGBase_FreeImg = (SDKHGBase_FreeImage_)dlsym(Dynamicopen_HGBase_pHandle_,"HGBase_DestroyImage");
|
||||
|
||||
#else
|
||||
Dynamicopen_pHandle_ = LoadLibrary(IMGPRC_LIBNANE);
|
||||
if (Dynamicopen_pHandle_)
|
||||
Dynamicopen_HGImageprc_pHandle_ = LoadLibrary(IMGPRC_LIBNANE);
|
||||
Dynamicopen_HGBase_pHandle_ = LoadLibrary(HGBASE_LIBNAME);
|
||||
if (Dynamicopen_HGImageprc_pHandle_ && Dynamicopen_HGBase_pHandle_)
|
||||
{
|
||||
ocrinit_ = (SDKInitialize_)GetProcAddress(Dynamicopen_pHandle_, "HGImgProc_CreateOCRMgr");
|
||||
ocrgetdirectimage_ = (SDKGetFileDirectImage_)GetProcAddress(Dynamicopen_pHandle_, "HGImgProc_ImageTextDirectOCR");
|
||||
ocrexit_ = (SDKExit_)GetProcAddress(Dynamicopen_pHandle_, "HGImgProc_DestroyOCRMgr");
|
||||
ocrinit_ = (SDKHGImgProc_InitOCR_)GetProcAddress(Dynamicopen_HGImageprc_pHandle_, "HGImgProc_CreateOCRMgr");
|
||||
ocrgetdirectimage_ = (SDKGetFileDirectImage_)GetProcAddress(Dynamicopen_HGImageprc_pHandle_, "HGImgProc_ImageTextDirectOCR");
|
||||
ocrexit_ = (SDKHGImgProc_FreeImage_)GetProcAddress(Dynamicopen_HGImageprc_pHandle_, "HGImgProc_DestroyOCRMgr");
|
||||
|
||||
HGBase_CreatImg = (SDKHGBase_CreateImage_)GetProcAddress(Dynamicopen_HGBase_pHandle_,"HGBase_CreateImageWithData");
|
||||
HGBase_FreeImg = (SDKHGBase_FreeImage_)GetProcAddress(Dynamicopen_HGBase_pHandle_,"HGBase_DestroyImage");
|
||||
}
|
||||
#endif
|
||||
ret = ocrinit_(HGIMGPROC_OCRALGO_TESSERACT, &Auto_Txt_pHanld);
|
||||
|
@ -298,15 +341,26 @@ namespace hg_imgproc
|
|||
}
|
||||
int free_auto_txt_hanld()
|
||||
{
|
||||
printf("11111111111111111111111111111----释放hanld\r\n");
|
||||
int ret = 0;
|
||||
if (Dynamicopen_pHandle_ != NULL)
|
||||
if (Dynamicopen_HGImageprc_pHandle_ != NULL)
|
||||
{
|
||||
#if (!defined WIN32)
|
||||
ret = dlclose(Dynamicopen_pHandle_);
|
||||
ret = dlclose(Dynamicopen_HGImageprc_pHandle_);
|
||||
#else
|
||||
ret = FreeLibrary(Dynamicopen_pHandle_);
|
||||
ret = FreeLibrary(Dynamicopen_HGImageprc_pHandle_);
|
||||
#endif
|
||||
Dynamicopen_pHandle_ = NULL;
|
||||
Dynamicopen_HGImageprc_pHandle_ = NULL;
|
||||
}
|
||||
|
||||
if (Dynamicopen_HGBase_pHandle_ != NULL)
|
||||
{
|
||||
#if (!defined WIN32)
|
||||
ret = dlclose(Dynamicopen_HGBase_pHandle_);
|
||||
#else
|
||||
ret = FreeLibrary(Dynamicopen_HGBase_pHandle_);
|
||||
#endif
|
||||
Dynamicopen_HGBase_pHandle_ = NULL;
|
||||
}
|
||||
|
||||
if (Auto_Txt_pHanld != NULL)
|
||||
|
@ -421,7 +475,7 @@ namespace hg_imgproc
|
|||
std::vector<cv::Mat> mats(mats_);
|
||||
mats_.clear();
|
||||
|
||||
int colormode = 1; //默认1
|
||||
int colormode = 1; //Ĭ<EFBFBD><EFBFBD>1
|
||||
if (img_conf_.filter == 3)
|
||||
colormode = img_conf_.pixtype;
|
||||
|
||||
|
@ -1149,20 +1203,22 @@ namespace hg_imgproc
|
|||
{
|
||||
HGImage b = opencv_to_hgbase_image(mats[i]);
|
||||
ret = ocrgetdirectimage_(Auto_Txt_pHanld, b, &pDirect);
|
||||
HGBase_DestroyImage(b);
|
||||
HGBase_FreeImg(b);
|
||||
//HGBase_DestroyImage(b);
|
||||
|
||||
switch (pDirect)
|
||||
{
|
||||
case HGIMGPROC_OCRTEXTDIRECT_ORI:
|
||||
pDirect = (int)CImageApplyRotation::RotationType::Invalid;
|
||||
pDirect = (unsigned int)CImageApplyRotation::RotationType::Invalid;
|
||||
break;
|
||||
case HGIMGPROC_OCRTEXTDIRECT_RIGHT:
|
||||
pDirect = (int)CImageApplyRotation::RotationType::Rotate_90_anti_clockwise;
|
||||
pDirect = (unsigned int)CImageApplyRotation::RotationType::Rotate_90_anti_clockwise;
|
||||
break;
|
||||
case HGIMGPROC_OCRTEXTDIRECT_LEFT:
|
||||
pDirect = (int)CImageApplyRotation::RotationType::Rotate_90_clockwise;
|
||||
pDirect = (unsigned int)CImageApplyRotation::RotationType::Rotate_90_clockwise;
|
||||
break;
|
||||
case HGIMGPROC_OCRTEXTDIRECT_180:
|
||||
pDirect = (int)CImageApplyRotation::RotationType::Rotate_180;
|
||||
pDirect = (unsigned int)CImageApplyRotation::RotationType::Rotate_180;
|
||||
break;
|
||||
default:
|
||||
pDirect = (int)CImageApplyRotation::RotationType::Invalid;
|
||||
|
@ -1197,36 +1253,34 @@ namespace hg_imgproc
|
|||
|
||||
}
|
||||
|
||||
HGImage opencv_to_hgbase_image(const cv::Mat& mats)
|
||||
HGImage opencv_to_hgbase_image(const cv::Mat& mats)
|
||||
{
|
||||
if (mats.empty())
|
||||
{
|
||||
//return SCANNER_ERR_NO_DATA;
|
||||
}
|
||||
HGImage image;
|
||||
HGImageInfo info;
|
||||
info.height = mats.rows;
|
||||
info.width = mats.cols;
|
||||
info.origin = 1L;
|
||||
int bits = mats.channels() == 8 ? 8 : 24;
|
||||
info.widthStep = mats.step; //opencv 原始值 无需计算对齐
|
||||
info.origin = HGBASE_IMGORIGIN_TOP;
|
||||
int bits = mats.channels() == 1 ? 8 : 24;
|
||||
info.widthStep = mats.step; //opencv原始值
|
||||
info.type = mats.channels() == 1 ? HGBASE_IMGTYPE_GRAY : HGBASE_IMGTYPE_BGR;
|
||||
int ret = HGBase_CreateImageWithData(const_cast<uchar*>(mats.data), &info, &image);
|
||||
|
||||
int ret = HGBase_CreatImg(const_cast<uchar*>(mats.data), &info, &image);
|
||||
|
||||
//int ret = HGBase_CreateImageWithData(const_cast<uchar*>(mats.data), &info, &image);
|
||||
|
||||
return image;
|
||||
//return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 8位图转1位图
|
||||
/// </summary>
|
||||
/// <param name="image">8bit图</param>
|
||||
/// <param name="threshold">阈值,建议默认127</param>
|
||||
/// <param name="reverse">true为反色,即黑0白1;反之亦然</param>
|
||||
/// <param name="align">true为四字节对齐</param>
|
||||
/// <returns>1位图</returns>
|
||||
///
|
||||
|
||||
/// <summary>
|
||||
/// 8位图转1位图
|
||||
/// </summary>
|
||||
/// <param name="image">8bit图</param>
|
||||
/// <param name="threshold">阈值,建议默认127</param>
|
||||
/// <param name="reverse">true为反色,即黑0白1;反之亦然</param>
|
||||
/// <param name="align">true为四字节对齐</param>
|
||||
/// <returns>1位图</returns>
|
||||
///
|
||||
static cv::Mat convert_8bit_2_1bit(const cv::Mat& image, uchar threshold, bool reverse, bool align)
|
||||
{
|
||||
if (image.channels() != 1)
|
||||
|
|
Loading…
Reference in New Issue