diff --git a/textord/devanagari_processing.cpp b/textord/devanagari_processing.cpp index 320c6ce081..76f05001b3 100644 --- a/textord/devanagari_processing.cpp +++ b/textord/devanagari_processing.cpp @@ -130,7 +130,9 @@ bool ShiroRekhaSplitter::Split(bool split_for_pageseg) { // out the image regions corresponding to these boxes from the original image. // Conditionally run splitting on each of them. Boxa* regions_to_clear = boxaCreate(0); - for (int i = 0; i < pixaGetCount(ccs); ++i) { + int num_ccs = 0; + if (ccs != nullptr) num_ccs = pixaGetCount(ccs); + for (int i = 0; i < num_ccs; ++i) { Box* box = ccs->boxa->box[i]; Pix* word_pix = pixClipRectangle(orig_pix_, box, NULL); ASSERT_HOST(word_pix); diff --git a/textord/imagefind.cpp b/textord/imagefind.cpp index 14442d52ed..6f0714181e 100644 --- a/textord/imagefind.cpp +++ b/textord/imagefind.cpp @@ -151,7 +151,8 @@ void ImageFind::ConnCompAndRectangularize(Pix* pix, Boxa** boxa, Pixa** pixa) { // Rectangularize the individual images. If a sharp edge in vertical and/or // horizontal occupancy can be found, it indicates a probably rectangular // image with unwanted bits merged on, so clip to the approximate rectangle. - int npixes = pixaGetCount(*pixa); + int npixes = 0; + if (*boxa != nullptr && *pixa != nullptr) npixes = pixaGetCount(*pixa); for (int i = 0; i < npixes; ++i) { int x_start, x_end, y_start, y_end; Pix* img_pix = pixaGetPix(*pixa, i, L_CLONE); @@ -1293,7 +1294,8 @@ void ImageFind::FindImagePartitions(Pix* image_pix, Pixa* pixa; ConnCompAndRectangularize(image_pix, &boxa, &pixa); // Iterate the connected components in the image regions mask. - int nboxes = boxaGetCount(boxa); + int nboxes = 0; + if (boxa != nullptr && pixa != nullptr) nboxes = boxaGetCount(boxa); for (int i = 0; i < nboxes; ++i) { l_int32 x, y, width, height; boxaGetBoxGeometry(boxa, i, &x, &y, &width, &height);