diff --git a/src/api/baseapi.cpp b/src/api/baseapi.cpp index 513225493..2a71576bf 100644 --- a/src/api/baseapi.cpp +++ b/src/api/baseapi.cpp @@ -701,9 +701,9 @@ Boxa *TessBaseAPI::GetConnectedComponents(Pixa **pixa) { Boxa *TessBaseAPI::GetComponentImages(PageIteratorLevel level, bool text_only, bool raw_image, const int raw_padding, Pixa **pixa, int **blockids, int **paraids) { - PageIterator *page_it = GetIterator(); + /*non-const*/ std::unique_ptr page_it(GetIterator()); if (page_it == nullptr) { - page_it = AnalyseLayout(); + page_it.reset(AnalyseLayout()); } if (page_it == nullptr) { return nullptr; // Failed. @@ -783,7 +783,6 @@ Boxa *TessBaseAPI::GetComponentImages(PageIteratorLevel level, bool text_only, b ++component_index; } } while (page_it->Next(level)); - delete page_it; return boxa; } @@ -1236,12 +1235,8 @@ bool TessBaseAPI::ProcessPage(Pix *pix, int page_index, const char *filename, if (tesseract_->tessedit_pageseg_mode == PSM_AUTO_ONLY) { // Disabled character recognition - PageIterator *it = AnalyseLayout(); - - if (it == nullptr) { + if (! std::unique_ptr(AnalyseLayout())) { failed = true; - } else { - delete it; } } else if (tesseract_->tessedit_pageseg_mode == PSM_OSD_ONLY) { failed = FindLines() != 0; @@ -1991,7 +1986,7 @@ bool TessBaseAPI::IsValidCharacter(const char *utf8_character) { // TODO(rays) Obsolete this function and replace with a more aptly named // function that returns image coordinates rather than tesseract coordinates. bool TessBaseAPI::GetTextDirection(int *out_offset, float *out_slope) { - PageIterator *it = AnalyseLayout(); + const std::unique_ptr it(AnalyseLayout()); if (it == nullptr) { return false; } @@ -2008,7 +2003,6 @@ bool TessBaseAPI::GetTextDirection(int *out_offset, float *out_slope) { // textline's bounding box. int left, top, right, bottom; if (!it->BoundingBox(RIL_TEXTLINE, &left, &top, &right, &bottom)) { - delete it; return false; } int left_y = IntCastRounded(*out_slope * left + *out_offset); @@ -2021,7 +2015,6 @@ bool TessBaseAPI::GetTextDirection(int *out_offset, float *out_slope) { // the slope and height - offset for the offset. *out_slope = -*out_slope; *out_offset = rect_height_ - *out_offset; - delete it; return true; } diff --git a/src/api/tesseractmain.cpp b/src/api/tesseractmain.cpp index 7cc33e0f5..3339d89e0 100644 --- a/src/api/tesseractmain.cpp +++ b/src/api/tesseractmain.cpp @@ -27,6 +27,7 @@ #endif #include // for std::getenv #include +#include // std::unique_ptr #include #include @@ -706,7 +707,7 @@ int main(int argc, char **argv) { tesseract::TextlineOrder order; float deskew_angle; - const tesseract::PageIterator *it = api.AnalyseLayout(); + const std::unique_ptr it(api.AnalyseLayout()); if (it) { // TODO: Implement output of page segmentation, see documentation // ("Automatic page segmentation, but no OSD, or OCR"). @@ -719,8 +720,6 @@ int main(int argc, char **argv) { ret_val = EXIT_FAILURE; } - delete it; - pixDestroy(&pixs); return ret_val; }