RAII: *::GetHOCRText()

This commit is contained in:
Raf Schietekat 2017-05-10 12:56:20 +02:00
parent 986970d6ca
commit a1fff874b4
3 changed files with 6 additions and 3 deletions

View File

@ -1393,6 +1393,7 @@ static void AddBoxToTSV(const PageIterator* it, PageIteratorLevel level,
* Image name/input_file_ can be set by SetInputName before calling
* GetHOCRText
* STL removed from original patch submission and refactored by rays.
* Returned string must be freed with the delete [] operator.
*/
char* TessBaseAPI::GetHOCRText(int page_number) {
return GetHOCRText(NULL, page_number);
@ -1405,6 +1406,7 @@ char* TessBaseAPI::GetHOCRText(int page_number) {
* Image name/input_file_ can be set by SetInputName before calling
* GetHOCRText
* STL removed from original patch submission and refactored by rays.
* Returned string must be freed with the delete [] operator.
*/
char* TessBaseAPI::GetHOCRText(ETEXT_DESC* monitor, int page_number) {
if (tesseract_ == NULL || (page_res_ == NULL && Recognize(monitor) < 0))

View File

@ -591,6 +591,7 @@ class TESS_API TessBaseAPI {
* monitor can be used to
* cancel the recognition
* receive progress callbacks
* Returned string must be freed with the delete [] operator.
*/
char* GetHOCRText(ETEXT_DESC* monitor, int page_number);
@ -598,6 +599,7 @@ class TESS_API TessBaseAPI {
* Make a HTML-formatted string with hOCR markup from the internal
* data structures.
* page_number is 0-based but will appear in the output as 1-based.
* Returned string must be freed with the delete [] operator.
*/
char* GetHOCRText(int page_number);

View File

@ -186,11 +186,10 @@ bool TessHOcrRenderer::EndDocumentHandler() {
}
bool TessHOcrRenderer::AddImageHandler(TessBaseAPI* api) {
char* hocr = api->GetHOCRText(imagenum());
const std::unique_ptr<const char[]> hocr(api->GetHOCRText(imagenum()));
if (hocr == NULL) return false;
AppendString(hocr);
delete[] hocr;
AppendString(hocr.get());
return true;
}