tia*_*lva 6 python tesseract python-tesseract
我正在尝试使用python-tesseract包装器设置一些Tesseract参数,但对于Init Only参数,我无法这样做.
我一直在阅读Tesseract文档,似乎我必须使用Init()来设置它们.这些是setVariable文档所说的:
仅适用于非init变量*(init变量应传递给Init()).
所以Init()函数有这个签名:
const char * datapath,
const char * language,
OcrEngineMode oem,
char ** configs,
int configs_size,
const GenericVector< STRING > * vars_vec,
const GenericVector< STRING > * vars_values,
bool set_only_non_debug_params
Run Code Online (Sandbox Code Playgroud)
我的代码如下:
import tesseract
configVec = ['user_words_suffix', 'load_system_dawg', 'load_freq_dawg']
configValues = ['brands', '0', '0']
api = tesseract.TessBaseAPI()
api.Init(".","eng",tesseract.OEM_TESSERACT_ONLY, None, 0, configVec, configValues, False)
api.SetPageSegMode(tesseract.PSM_AUTO_OSD)
api.SetVariable("tessedit_char_whitelist", "€$0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz,.\"-/+%")
Run Code Online (Sandbox Code Playgroud)
问题是我收到以下错误:
NotImplementedError: Wrong number or type of arguments for overloaded function 'TessBaseAPI_Init'.
Possible C/C++ prototypes are:
tesseract::TessBaseAPI::Init(char const *,char const *,tesseract::OcrEngineMode,char **,int,GenericVector< STRING > const *,GenericVector< STRING > const *,bool)
Run Code Online (Sandbox Code Playgroud)
问题与那些GenericVectors有关.如果我使用这一行代替:
api.Init(".","eng",tesseract.OEM_TESSERACT_ONLY, None, 0, None, None, False)
Run Code Online (Sandbox Code Playgroud)
有用.所以问题是那些GenericVectors.如何将正确的参数传递给Init()?
有没有其他方法在代码中设置init only参数?我可以使用这些参数从代码加载配置文件吗?
感谢您的时间,非常感谢任何帮助.
对于直接与 API 交互的场景,我执行了以下操作:
# This should be specified in the cffi.cdef
BOOL TessBaseAPISetVariable(TessBaseAPI *handle, const char *name, const char *value);
# This should be called afterwards, outside the cdef
# baseapi.h - Params (aka variables) must be done after init line above
# tesseractclass.h - Has list of settable variables like tessedit_char_whitelist
foundVariableName = libtess.TessBaseAPISetVariable(api, 'tessedit_char_whitelist'.encode(), 'ABFGJKLMNOPRSTYZ1234567890/.,-+ |\\'.encode())
print(foundVariableName) # returns 1 is successfully found, 0 if variable name not found
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
874 次 |
| 最近记录: |