Skip to content

Commit

Permalink
Fixed issue 1108
Browse files Browse the repository at this point in the history
git-svn-id: https://tesseract-ocr.googlecode.com/svn/trunk@1072 d0cd1f9f-072b-0410-8dd7-cf729c803f20
  • Loading branch information
theraysmith@gmail.com committed Apr 24, 2014
1 parent 9fad031 commit 0dd47a2
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions cube/cube_line_segmenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ Pixa *CubeLineSegmenter::VerticalClosing(Pix *pix,
return pixac;
}

// Helper cleans up after CrackLine.
static void CleanupCrackLine(int line_cnt, Pixa **lines_pixa,
Boxa **line_con_comps,
Pixa **line_con_comps_pix) {
for (int line = 0; line < line_cnt; line++) {
if (lines_pixa[line] != NULL) {
pixaDestroy(&lines_pixa[line]);
}
}

delete []lines_pixa;
boxaDestroy(line_con_comps);
pixaDestroy(line_con_comps_pix);
}

// do a desperate attempt at cracking lines
Pixa *CubeLineSegmenter::CrackLine(Pix *cracked_line_pix,
Box *cracked_line_box, int line_cnt) {
Expand Down Expand Up @@ -139,19 +154,18 @@ Pixa *CubeLineSegmenter::CrackLine(Pix *cracked_line_pix,
if (lines_pixa[line_idx] == NULL) {
lines_pixa[line_idx] = pixaCreate(line_con_comps->n);
if (lines_pixa[line_idx] == NULL) {
delete []lines_pixa;
boxaDestroy(&line_con_comps);
pixaDestroy(&line_con_comps_pix);
CleanupCrackLine(line_cnt, lines_pixa, &line_con_comps,
&line_con_comps_pix);
return NULL;
}
}

// add the concomp to the line
if (pixaAddPix(lines_pixa[line_idx], con_pix, L_CLONE) != 0 ||
pixaAddBox(lines_pixa[line_idx], con_box, L_CLONE)) {
delete []lines_pixa;
boxaDestroy(&line_con_comps);
pixaDestroy(&line_con_comps_pix);
CleanupCrackLine(line_cnt, lines_pixa, &line_con_comps,
&line_con_comps_pix);
return NULL;
}
}

Expand Down Expand Up @@ -192,15 +206,8 @@ Pixa *CubeLineSegmenter::CrackLine(Pix *cracked_line_pix,
}

// cleanup
for (int line = 0; line < line_cnt; line++) {
if (lines_pixa[line] != NULL) {
pixaDestroy(&lines_pixa[line]);
}
}

delete []lines_pixa;
boxaDestroy(&line_con_comps);
pixaDestroy(&line_con_comps_pix);
CleanupCrackLine(line_cnt, lines_pixa, &line_con_comps,
&line_con_comps_pix);

if (success == false) {
pixaDestroy(&lines);
Expand Down

0 comments on commit 0dd47a2

Please sign in to comment.