// Cut out the requested rectangle of the binary image to the // tesseract global image ready for recognition. void TessBaseAPI::CopyBinaryRect(const unsigned char* imagedata, int bytes_per_line, int left, int top, int width, int height) { // Copy binary image, cutting out the required rectangle. IMAGE image; image.capture(const_cast<unsigned char*>(imagedata), bytes_per_line*8, top + height, 1); page_image.create(width, height, 1); copy_sub_image(&image, left, 0, width, height, &page_image, 0, 0, false); }
int TessDllAPI::BeginPageUpright(uinT32 xsize,uinT32 ysize,unsigned char *buf, uinT8 bpp) { EndPage(); //It looks like Adaptive thresholding is disabled so this must be a 1 bpp image if (page_image.create (xsize+800, ysize+800, 1)==-1) return 0L; //make the image bigger to enclose in whitespace //copy the passed buffer into the center of the image IMAGE tmp; tmp.capture(buf, xsize, ysize, bpp); copy_sub_image(&tmp, 0, 0, 0, 0, &page_image, 400, 400, true); return ProcessPagePass1(); }
// Copy the raw image rectangle, taking all data from the class, to the Pix. void ImageThresholder::RawRectToPix(Pix** pix) const { if (image_bytespp_ < 4) { // Go via a tesseract image structure (doesn't copy the data) // and use ToPix. IMAGE image; int bits_per_pixel = image_bytespp_ * 8; if (image_bytespp_ == 0) bits_per_pixel = 1; image.capture(const_cast<uinT8*>(image_data_), image_width_, rect_top_ + rect_height_, bits_per_pixel); if (IsFullImage()) { *pix = image.ToPix(); } else { IMAGE rect; rect.create(rect_width_, rect_height_, bits_per_pixel); // The capture chopped the image off at top+height, so copy // the rectangle with y = 0 to get a rectangle of height // starting at the bottom, since copy_sub_image uses bottom-up coords. copy_sub_image(&image, rect_left_, 0, rect_width_, rect_height_, &rect, 0, 0, true); *pix = rect.ToPix(); } } else { *pix = pixCreate(rect_width_, rect_height_, 32); uinT32* data = pixGetData(*pix); int wpl = pixGetWpl(*pix); const uinT8* imagedata = image_data_ + rect_top_ * image_bytespl_ + rect_left_ * image_bytespp_; for (int y = 0; y < rect_height_; ++y) { const uinT8* linedata = imagedata; uinT32* line = data + y * wpl; for (int x = 0; x < rect_width_; ++x) { line[x] = (linedata[0] << 24) | (linedata[1] << 16) | (linedata[2] << 8) | linedata[3]; linedata += 4; } imagedata += image_bytespl_; } } }