我试图在python中使用带有ctypes和cv2的Tesseract 3.02.Tesseract提供了一组暴露的C风格API,其中一个如下:
TESS_API void TESS_CALL TessBaseAPISetImage(TessBaseAPI* handle, const unsigned char* imagedata, int width, int height, int bytes_per_pixel, int bytes_per_line);
Run Code Online (Sandbox Code Playgroud)
到目前为止,我的代码如下:
tesseract = ctypes.cdll.LoadLibrary('libtesseract302.dll')
api = tesseract.TessBaseAPICreate()
tesseract.TessBaseAPIInit3(api, '', 'eng')
imcv = cv2.imread('test.bmp')
w, h, d = imcv.shape
ret = tesseract.TessBaseAPISetImage(api, ctypes.c_char_p(str(imcv.data)), w, h, d, w * d)
#ret = 44 here
Run Code Online (Sandbox Code Playgroud)
最后一行返回错误代码44,我在Tesseract提供的errcode.h中找不到任何地方.我不确定我在这里做错了什么.
我发现了类似的问题如何使用ctypes和tesseract 3.0.2识别数据而不是文件名?但问题仍未解决.我也知道https://code.google.com/p/python-tesseract/,我深入研究了这个项目的源代码,但无法找到我需要的信息.
我可以通过调用来确认test.bmp中的图像是否合法且可读cv2.imshow.同样的图像可以通过命令行上的Tesseract进行OCR.
在下面的代码示例中,我想不通为什么FinalType是{ test: { test_inner: any } }.我不知道any它来自哪里(并且string丢失了).同时,test有正确的回归类型{ test_inner: string }
interface IAction {
type: string;
}
type Reducer<S> = (state: S, action: IAction) => S
function combineReducers<S>(reducers: { [K in keyof S]: Reducer<S[K]> }): Reducer<S> {
const dummy = {} as S;
return () => dummy;
}
const test_inner = (test: string, action: IAction) => {
return 'dummy';
}
const test = combineReducers({
test_inner
});
const test_outer = combineReducers({ …Run Code Online (Sandbox Code Playgroud)