Skip to content

Commit

Permalink
Add initializer that supports OEM
Browse files Browse the repository at this point in the history
This is a requirement of both tesseract-rs and leptess.

houqp/leptess#33
antimatter15/tesseract-rs#25
  • Loading branch information
ccouzens committed Apr 18, 2021
1 parent 8ab5238 commit 3315a76
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/tess_base_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ extern crate thiserror;
use self::tesseract_sys::{
TessBaseAPICreate, TessBaseAPIDelete, TessBaseAPIGetAltoText, TessBaseAPIGetHOCRText,
TessBaseAPIGetInputImage, TessBaseAPIGetLSTMBoxText, TessBaseAPIGetSourceYResolution,
TessBaseAPIGetTsvText, TessBaseAPIGetUTF8Text, TessBaseAPIGetWordStrBoxText, TessBaseAPIInit3,
TessBaseAPIMeanTextConf, TessBaseAPIRecognize, TessBaseAPISetImage, TessBaseAPISetImage2,
TessBaseAPISetRectangle, TessBaseAPISetSourceResolution, TessBaseAPISetVariable,
TessBaseAPIGetTsvText, TessBaseAPIGetUTF8Text, TessBaseAPIGetWordStrBoxText, TessBaseAPIInit2,
TessBaseAPIInit3, TessBaseAPIMeanTextConf, TessBaseAPIRecognize, TessBaseAPISetImage,
TessBaseAPISetImage2, TessBaseAPISetRectangle, TessBaseAPISetSourceResolution,
TessBaseAPISetVariable, TessOcrEngineMode,
};
use self::thiserror::Error;
use crate::Text;
Expand Down Expand Up @@ -105,6 +106,28 @@ impl TessBaseAPI {
}
}

/// Wrapper for [`Init-4`](https://tesseract-ocr.github.io/tessapi/5.x/a02438.html#a6d0956a66158ead4e3a86c7f50dad56e)
pub fn init_4(
&mut self,
datapath: Option<&CStr>,
language: Option<&CStr>,
oem: TessOcrEngineMode,
) -> Result<(), TessBaseAPIInitError> {
let ret = unsafe {
TessBaseAPIInit2(
self.0,
datapath.map(CStr::as_ptr).unwrap_or_else(ptr::null),
language.map(CStr::as_ptr).unwrap_or_else(ptr::null),
oem,
)
};
if ret == 0 {
Ok(())
} else {
Err(TessBaseAPIInitError {})
}
}

/// Wrapper for [`SetImage-2`](https://tesseract-ocr.github.io/tessapi/5.x/a02438.html#a0c4c7f05fd58b3665b123232a05545ad)
pub fn set_image_2(&mut self, pix: &Pix) {
unsafe {
Expand Down

0 comments on commit 3315a76

Please sign in to comment.