Beispiel #1
0
jboolean Java_com_googlecode_tesseract_android_PageIterator_nativeNext(JNIEnv *env, jclass clazz,
    jint nativePageIterator, jint level) {
  PageIterator *pageIterator = (PageIterator *) nativePageIterator;
  PageIteratorLevel enumLevel = (PageIteratorLevel) level;

  return pageIterator->Next(enumLevel) ? JNI_TRUE : JNI_FALSE;
}
Beispiel #2
0
/**
 * Returns the bounding rectangle of the current object at the given level in
 * the coordinates of the working image that is pix_binary().
 * See comment on coordinate system above.
 * Returns false if there is no such object at the current position.
 */
bool PageIterator::BoundingBoxInternal(PageIteratorLevel level,
                                       int* left, int* top,
                                       int* right, int* bottom) const {
  if (Empty(level))
    return false;
  TBOX box;
  PARA *para = NULL;
  switch (level) {
    case RIL_BLOCK:
      box = it_->block()->block->bounding_box();
      break;
    case RIL_PARA:
      para = it_->row()->row->para();
      // explicit fall-through.
    case RIL_TEXTLINE:
      box = it_->row()->row->bounding_box();
      break;
    case RIL_WORD:
      box = it_->word()->word->bounding_box();
      break;
    case RIL_SYMBOL:
      if (cblob_it_ == NULL)
        box = it_->word()->box_word->BlobBox(blob_index_);
      else
        box = cblob_it_->data()->bounding_box();
  }
  if (level == RIL_PARA) {
    PageIterator other = *this;
    other.Begin();
    do {
      if (other.it_->block() &&
          other.it_->block()->block == it_->block()->block &&
          other.it_->row() && other.it_->row()->row &&
          other.it_->row()->row->para() == para) {
        box = box.bounding_union(other.it_->row()->row->bounding_box());
      }
    } while (other.Next(RIL_TEXTLINE));
  }
  if (level != RIL_SYMBOL || cblob_it_ != NULL)
    box.rotate(it_->block()->block->re_rotation());
  // Now we have a box in tesseract coordinates relative to the image rectangle,
  // we have to convert the coords to a top-down system.
  const int pix_height = pixGetHeight(tesseract_->pix_binary());
  const int pix_width = pixGetWidth(tesseract_->pix_binary());
  *left = ClipToRange(static_cast<int>(box.left()), 0, pix_width);
  *top = ClipToRange(pix_height - box.top(), 0, pix_height);
  *right = ClipToRange(static_cast<int>(box.right()), *left, pix_width);
  *bottom = ClipToRange(pix_height - box.bottom(), *top, pix_height);
  return true;
}
Beispiel #3
0
jintArray Java_com_googlecode_tesseract_android_PageIterator_nativeBoundingBox(JNIEnv *env,
                                                                               jclass clazz,
                                                                               jlong nativePageIterator,
                                                                               jint level) {
    int size = 4;
    jintArray result = env->NewIntArray(size);

    LOG_ASSERT((result != NULL), "Could not create Java bounding box array!");

    PageIterator *pageIterator = (PageIterator *) nativePageIterator;
    PageIteratorLevel enumLevel = (PageIteratorLevel) level;
    int x1, y1, x2, y2;
    pageIterator->BoundingBox(enumLevel, &x1, &y1, &x2, &y2);

    // fill a temp structure to use to populate the java int array
    jint fill[4];
    fill[0] = x1;
    fill[1] = y1;
    fill[2] = x2;
    fill[3] = y2;

    env->SetIntArrayRegion(result, 0, size, fill);
    return result;
}