Skip to content

Commit

Permalink
Added GetGradient, removed GetAngle
Browse files Browse the repository at this point in the history
  • Loading branch information
Balearica committed Apr 30, 2023
1 parent eb056f3 commit db6951f
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 34 deletions.
42 changes: 21 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -595,27 +595,27 @@ if(DOTPRODUCT_FLAGS)
set_source_files_properties(src/arch/dotproduct.cpp
PROPERTIES COMPILE_FLAGS ${DOTPRODUCT_FLAGS})
endif(DOTPRODUCT_FLAGS)
if(HAVE_AVX)
list(APPEND arch_files_opt src/arch/dotproductavx.cpp)
set_source_files_properties(src/arch/dotproductavx.cpp
PROPERTIES COMPILE_FLAGS ${AVX_COMPILE_FLAGS})
endif(HAVE_AVX)
if(HAVE_AVX2)
list(APPEND arch_files_opt src/arch/intsimdmatrixavx2.cpp
src/arch/dotproductavx.cpp)
set_source_files_properties(src/arch/intsimdmatrixavx2.cpp
PROPERTIES COMPILE_FLAGS ${AVX2_COMPILE_FLAGS})
endif(HAVE_AVX2)
if(HAVE_AVX512F)
list(APPEND arch_files_opt src/arch/dotproductavx512.cpp)
set_source_files_properties(src/arch/dotproductavx512.cpp
PROPERTIES COMPILE_FLAGS ${AVX512F_COMPILE_FLAGS})
endif(HAVE_AVX512F)
if(HAVE_FMA)
list(APPEND arch_files_opt src/arch/dotproductfma.cpp)
set_source_files_properties(src/arch/dotproductfma.cpp
PROPERTIES COMPILE_FLAGS ${FMA_COMPILE_FLAGS})
endif(HAVE_FMA)
# if(HAVE_AVX)
# list(APPEND arch_files_opt src/arch/dotproductavx.cpp)
# set_source_files_properties(src/arch/dotproductavx.cpp
# PROPERTIES COMPILE_FLAGS ${AVX_COMPILE_FLAGS})
# endif(HAVE_AVX)
# if(HAVE_AVX2)
# list(APPEND arch_files_opt src/arch/intsimdmatrixavx2.cpp
# src/arch/dotproductavx.cpp)
# set_source_files_properties(src/arch/intsimdmatrixavx2.cpp
# PROPERTIES COMPILE_FLAGS ${AVX2_COMPILE_FLAGS})
# endif(HAVE_AVX2)
# if(HAVE_AVX512F)
# list(APPEND arch_files_opt src/arch/dotproductavx512.cpp)
# set_source_files_properties(src/arch/dotproductavx512.cpp
# PROPERTIES COMPILE_FLAGS ${AVX512F_COMPILE_FLAGS})
# endif(HAVE_AVX512F)
# if(HAVE_FMA)
# list(APPEND arch_files_opt src/arch/dotproductfma.cpp)
# set_source_files_properties(src/arch/dotproductfma.cpp
# PROPERTIES COMPILE_FLAGS ${FMA_COMPILE_FLAGS})
# endif(HAVE_FMA)
if(HAVE_SSE4_1)
list(APPEND arch_files_opt src/arch_sse/dotproductsse.cpp src/arch_sse/simddetect.cpp src/arch_sse/intsimdmatrix.cpp src/arch_sse/intsimdmatrixsse.cpp src/arch_sse/dotproduct.cpp)
set_source_files_properties(src/arch_sse/dotproductsse.cpp src/arch_sse/simddetect.cpp src/arch_sse/intsimdmatrix.cpp src/arch_sse/intsimdmatrixsse.cpp src/arch_sse/dotproduct.cpp PROPERTIES COMPILE_FLAGS "-DSSE4_1 -msimd128 -msse -msse2 -msse3 -msse4 -msse4.1 -msse4.2 -Wno-argument-outside-range")
Expand Down
4 changes: 2 additions & 2 deletions include/tesseract/baseapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,9 @@ class TESS_API TessBaseAPI {
void WriteImage(const int type);

/** Function added by Tesseract.js.
* Return angle of page.
* Return gradient of page.
*/
float GetAngle();
float GetGradient();

/**
* Get the result of page layout analysis as a leptonica-style
Expand Down
6 changes: 3 additions & 3 deletions src/api/baseapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2277,10 +2277,10 @@ int TessBaseAPI::FindLines() {
}

/** Function added by Tesseract.js.
* Return angle of page.
* Return gradient of page.
*/
float TessBaseAPI::GetAngle() {
return tesseract_->reskew().angle();
float TessBaseAPI::GetGradient() {
return tesseract_->gradient();
}

/** Delete the pageres and clear the block list ready for a new page. */
Expand Down
2 changes: 1 addition & 1 deletion src/ccmain/pagesegmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ int Tesseract::SegmentPage(const char *input_file, BLOCK_LIST *blocks, Tesseract
bool cjk_mode = textord_use_cjk_fp_model;

textord_.TextordPage(pageseg_mode, reskew_, width, height, pix_binary_, pix_thresholds_,
pix_grey_, splitting || cjk_mode, &diacritic_blobs, blocks, &to_blocks);
pix_grey_, splitting || cjk_mode, &diacritic_blobs, blocks, &to_blocks, &gradient_);
return auto_page_seg_ret_val;
}

Expand Down
6 changes: 6 additions & 0 deletions src/ccmain/tesseractclass.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ class TESS_API Tesseract : public Wordrec {
const FCOORD &reskew() const {
return reskew_;
}

float gradient() const {
return gradient_;
}

// Destroy any existing pix and return a pointer to the pointer.
Image *mutable_pix_binary() {
pix_binary_.destroy();
Expand Down Expand Up @@ -1001,6 +1006,7 @@ class TESS_API Tesseract : public Wordrec {
int scaled_factor_;
FCOORD deskew_;
FCOORD reskew_;
float gradient_;
TesseractStats stats_;
// Sub-languages to be tried in addition to this.
std::vector<Tesseract *> sub_langs_;
Expand Down
11 changes: 5 additions & 6 deletions src/textord/textord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ Textord::Textord(CCStruct *ccstruct)
void Textord::TextordPage(PageSegMode pageseg_mode, const FCOORD &reskew, int width, int height,
Image binary_pix, Image thresholds_pix, Image grey_pix, bool use_box_bottoms,
BLOBNBOX_LIST *diacritic_blobs, BLOCK_LIST *blocks,
TO_BLOCK_LIST *to_blocks) {
TO_BLOCK_LIST *to_blocks, float *gradient) {
page_tr_.set_x(width);
page_tr_.set_y(height);
if (to_blocks->empty()) {
Expand Down Expand Up @@ -219,15 +219,14 @@ void Textord::TextordPage(PageSegMode pageseg_mode, const FCOORD &reskew, int wi
TO_BLOCK_IT to_block_it(to_blocks);
TO_BLOCK *to_block = to_block_it.data();
// Make the rows in the block.
float gradient;
// Do it the old fashioned way.
if (PSM_LINE_FIND_ENABLED(pageseg_mode)) {
gradient = make_rows(page_tr_, to_blocks);
*gradient = make_rows(page_tr_, to_blocks);
} else if (!PSM_SPARSE(pageseg_mode)) {
// RAW_LINE, SINGLE_LINE, SINGLE_WORD and SINGLE_CHAR all need a single row.
gradient = make_single_row(page_tr_, pageseg_mode != PSM_RAW_LINE, to_block, to_blocks);
*gradient = make_single_row(page_tr_, pageseg_mode != PSM_RAW_LINE, to_block, to_blocks);
} else {
gradient = 0.0f;
*gradient = 0.0f;
}
BaselineDetect baseline_detector(textord_baseline_debug, reskew, to_blocks);
baseline_detector.ComputeStraightBaselines(use_box_bottoms);
Expand All @@ -236,7 +235,7 @@ void Textord::TextordPage(PageSegMode pageseg_mode, const FCOORD &reskew, int wi
// Now make the words in the lines.
if (PSM_WORD_FIND_ENABLED(pageseg_mode)) {
// SINGLE_LINE uses the old word maker on the single line.
make_words(this, page_tr_, gradient, blocks, to_blocks);
make_words(this, page_tr_, *gradient, blocks, to_blocks);
} else {
// SINGLE_WORD and SINGLE_CHAR cram all the blobs into a
// single word, and in SINGLE_CHAR mode, all the outlines
Expand Down
3 changes: 2 additions & 1 deletion src/textord/textord.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ class Textord {
// to the appropriate word(s) in case they are really diacritics.
void TextordPage(PageSegMode pageseg_mode, const FCOORD &reskew, int width, int height,
Image binary_pix, Image thresholds_pix, Image grey_pix, bool use_box_bottoms,
BLOBNBOX_LIST *diacritic_blobs, BLOCK_LIST *blocks, TO_BLOCK_LIST *to_blocks);
BLOBNBOX_LIST *diacritic_blobs, BLOCK_LIST *blocks, TO_BLOCK_LIST *to_blocks,
float *gradient);

// If we were supposed to return only a single textline, and there is more
// than one, clean up and leave only the best.
Expand Down

0 comments on commit db6951f

Please sign in to comment.