diff --git a/src/api/baseapi.cpp b/src/api/baseapi.cpp index 4b97840c..9dcfcd10 100644 --- a/src/api/baseapi.cpp +++ b/src/api/baseapi.cpp @@ -707,24 +707,23 @@ Boxa* TessBaseAPI::GetComponentImages(PageIteratorLevel level, int component_count = 0; int left, top, right, bottom; - TessResultCallback* get_bbox = nullptr; if (raw_image) { // Get bounding box in original raw image with padding. - get_bbox = NewPermanentTessCallback(page_it, &PageIterator::BoundingBox, - level, raw_padding, - &left, &top, &right, &bottom); + do { + if (page_it->BoundingBox(level, raw_padding, + &left, &top, &right, &bottom) && + (!text_only || PTIsTextType(page_it->BlockType()))) + ++component_count; + } while (page_it->Next(level)); } else { // Get bounding box from binarized imaged. Note that this could be // differently scaled from the original image. - get_bbox = NewPermanentTessCallback(page_it, - &PageIterator::BoundingBoxInternal, - level, &left, &top, &right, &bottom); + do { + if (page_it->BoundingBoxInternal(level, &left, &top, &right, &bottom) && + (!text_only || PTIsTextType(page_it->BlockType()))) + ++component_count; + } while (page_it->Next(level)); } - do { - if (get_bbox->Run() && - (!text_only || PTIsTextType(page_it->BlockType()))) - ++component_count; - } while (page_it->Next(level)); Boxa* boxa = boxaCreate(component_count); if (pixa != nullptr) @@ -739,7 +738,15 @@ Boxa* TessBaseAPI::GetComponentImages(PageIteratorLevel level, int component_index = 0; page_it->Begin(); do { - if (get_bbox->Run() && + bool got_bounding_box; + if (raw_image) { + got_bounding_box = + page_it->BoundingBox(level, raw_padding, &left, &top, &right, &bottom); + } else { + got_bounding_box = + page_it->BoundingBoxInternal(level, &left, &top, &right, &bottom); + } + if (got_bounding_box && (!text_only || PTIsTextType(page_it->BlockType()))) { Box* lbox = boxCreate(left, top, right - left, bottom - top); boxaAddBox(boxa, lbox, L_INSERT); @@ -770,7 +777,6 @@ Boxa* TessBaseAPI::GetComponentImages(PageIteratorLevel level, } } while (page_it->Next(level)); delete page_it; - delete get_bbox; return boxa; } diff --git a/src/ccutil/tesscallback.h b/src/ccutil/tesscallback.h index 03e77974..f986fd1c 100644 --- a/src/ccutil/tesscallback.h +++ b/src/ccutil/tesscallback.h @@ -169,207 +169,6 @@ struct Identity { using type = T; }; -template -class _ConstTessMemberResultCallback_5_0 : public TessResultCallback { - public: - using base = TessResultCallback; - using MemberSignature = R (T::*)(P1, P2, P3, P4, P5) const; - - private: - const T* object_; - MemberSignature member_; - typename remove_reference::type p1_; - typename remove_reference::type p2_; - typename remove_reference::type p3_; - typename remove_reference::type p4_; - typename remove_reference::type p5_; - - public: - inline _ConstTessMemberResultCallback_5_0(const T* object, - MemberSignature member, P1 p1, - P2 p2, P3 p3, P4 p4, P5 p5) - : object_(object), - member_(member), - p1_(p1), - p2_(p2), - p3_(p3), - p4_(p4), - p5_(p5) {} - - R Run() override { - if (!del) { - R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_); - return result; - } - R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_); - // zero out the pointer to ensure segfault if used again - member_ = nullptr; - delete this; - return result; - } -}; - -template -class _ConstTessMemberResultCallback_5_0 - : public TessClosure { - public: - using base = TessClosure; - using MemberSignature = void (T::*)(P1, P2, P3, P4, P5) const; - - private: - const T* object_; - MemberSignature member_; - typename remove_reference::type p1_; - typename remove_reference::type p2_; - typename remove_reference::type p3_; - typename remove_reference::type p4_; - typename remove_reference::type p5_; - - public: - inline _ConstTessMemberResultCallback_5_0(const T* object, - MemberSignature member, P1 p1, - P2 p2, P3 p3, P4 p4, P5 p5) - : object_(object), - member_(member), - p1_(p1), - p2_(p2), - p3_(p3), - p4_(p4), - p5_(p5) {} - - void Run() override { - if (!del) { - (object_->*member_)(p1_, p2_, p3_, p4_, p5_); - } else { - (object_->*member_)(p1_, p2_, p3_, p4_, p5_); - // zero out the pointer to ensure segfault if used again - member_ = nullptr; - delete this; - } - } -}; - -#ifndef SWIG -template -inline typename _ConstTessMemberResultCallback_5_0::base* -NewPermanentTessCallback(const T1* obj, - R (T2::*member)(P1, P2, P3, P4, P5) const, - typename Identity::type p1, - typename Identity::type p2, - typename Identity::type p3, - typename Identity::type p4, - typename Identity::type p5) { - return new _ConstTessMemberResultCallback_5_0(obj, member, p1, p2, p3, p4, - p5); -} -#endif - -template -class _ConstTessMemberResultCallback_6_0 : public TessResultCallback { - public: - using base = TessResultCallback; - using MemberSignature = R (T::*)(P1, P2, P3, P4, P5, P6) const; - - private: - const T* object_; - MemberSignature member_; - typename remove_reference::type p1_; - typename remove_reference::type p2_; - typename remove_reference::type p3_; - typename remove_reference::type p4_; - typename remove_reference::type p5_; - typename remove_reference::type p6_; - - public: - inline _ConstTessMemberResultCallback_6_0(const T* object, - MemberSignature member, P1 p1, - P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) - : object_(object), - member_(member), - p1_(p1), - p2_(p2), - p3_(p3), - p4_(p4), - p5_(p5), - p6_(p6) {} - - R Run() override { - if (!del) { - R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_); - return result; - } - R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_); - // zero out the pointer to ensure segfault if used again - member_ = nullptr; - delete this; - return result; - } -}; - -template -class _ConstTessMemberResultCallback_6_0 - : public TessClosure { - public: - using base = TessClosure; - using MemberSignature = void (T::*)(P1, P2, P3, P4, P5, P6) const; - - private: - const T* object_; - MemberSignature member_; - typename remove_reference::type p1_; - typename remove_reference::type p2_; - typename remove_reference::type p3_; - typename remove_reference::type p4_; - typename remove_reference::type p5_; - typename remove_reference::type p6_; - - public: - inline _ConstTessMemberResultCallback_6_0(const T* object, - MemberSignature member, P1 p1, - P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) - : object_(object), - member_(member), - p1_(p1), - p2_(p2), - p3_(p3), - p4_(p4), - p5_(p5), - p6_(p6) {} - - void Run() override { - if (!del) { - (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_); - } else { - (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_); - // zero out the pointer to ensure segfault if used again - member_ = nullptr; - delete this; - } - } -}; - -#ifndef SWIG -template -inline typename _ConstTessMemberResultCallback_6_0::base* -NewPermanentTessCallback( - const T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, P6) const, - typename Identity::type p1, typename Identity::type p2, - typename Identity::type p3, typename Identity::type p4, - typename Identity::type p5, typename Identity::type p6) { - return new _ConstTessMemberResultCallback_6_0(obj, member, p1, p2, p3, - p4, p5, p6); -} -#endif - template class TessCallback1 { public: