コード例 #1
0
int TessDllAPI::BeginPage(uinT32 xsize,uinT32 ysize,unsigned char *buf,uinT8 bpp) {
  inT16 c;

  EndPage();

  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.create(xsize, ysize, bpp);

  for (c=0;c<ysize;c++)
    CopyMemory(tmp.get_buffer ()+(c)*((xsize*bpp + 7)/8),
               buf+((ysize-1)-c)*((xsize*bpp + 7)/8),((xsize*bpp + 7)/8));


  copy_sub_image(&tmp, 0, 0, 0, 0, &page_image, 400, 400, false);




  return ProcessPagePass1();
}
コード例 #2
0
CHAR_SAMPLE *clip_sample(              //lines of the image
                         PIXROW *pixrow,
                         IMAGELINE *imlines,
                         TBOX pix_box,  //box of imlines extent
                         BOOL8 white_on_black,
                         char c) {
  TBOX b_box = pixrow->bounding_box ();
  float baseline_pos = 0;
  inT32 resolution = page_image.get_res ();

  if (!b_box.null_box ()) {
    ASSERT_HOST (b_box.width () < page_image.get_xsize () &&
      b_box.height () < page_image.get_ysize ());

    if (b_box.width () > resolution || b_box.height () > resolution) {
      tprintf ("clip sample: sample too big (%d x %d)\n",
        b_box.width (), b_box.height ());

      return NULL;
    }

    IMAGE *image = new (IMAGE);
    if (image->create (b_box.width (), b_box.height (), 1) == -1) {
      tprintf ("clip sample: create image failed (%d x %d)\n",
        b_box.width (), b_box.height ());

      delete image;
      return NULL;
    }

    if (!white_on_black)
      invert_image(image);  // Set background to white
    pixrow->char_clip_image (imlines, pix_box, NULL, *image, baseline_pos);
    if (white_on_black)
      invert_image(image);  //invert white on black for scaling &NN
    return new CHAR_SAMPLE (image, c);
  }
  else
    return NULL;
}
コード例 #3
0
ファイル: thresholder.cpp プロジェクト: ErfanHasmin/scope-ocr
// 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_;
    }
  }
}
コード例 #4
0
IMAGE *CHAR_PROTO::make_image() { 
  IMAGE *image;
  IMAGELINE imline_p;
  INT32 x;
  INT32 y;

  ASSERT_HOST (nsamples != 0);

  image = new (IMAGE);
  image->create (xsize, ysize, 8);

  for (y = 0; y < ysize; y++) {
    image->fast_get_line (0, y, xsize, &imline_p);

    for (x = 0; x < xsize; x++) {
      imline_p.pixels[x] = 128 +
        (UINT8) ((proto[x][y] * 128.0) / (0.00001 + nsamples));
    }

    image->fast_put_line (0, y, xsize, &imline_p);
  }
  return image;
}
コード例 #5
0
////////////DEBAYAN//Deskew begins//////////////////////
void deskew(float angle,int srcheight, int srcwidth)
{
  //angle=4;        //45° for example 
  IMAGE tempimage;
  
  
  IMAGELINE line;
  //Convert degrees to radians 
  float radians=(2*3.1416*angle)/360; 
  
  float cosine=(float)cos(radians); 
  float sine=(float)sin(radians); 
  
  float Point1x=(srcheight*sine); 
  float Point1y=(srcheight*cosine); 
  float Point2x=(srcwidth*cosine-srcheight*sine); 
  float Point2y=(srcheight*cosine+srcwidth*sine); 
  float Point3x=(srcwidth*cosine); 
  float Point3y=(srcwidth*sine); 
  
  float minx=min(0,min(Point1x,min(Point2x,Point3x))); 
  float miny=min(0,min(Point1y,min(Point2y,Point3y))); 
  float maxx=max(Point1x,max(Point2x,Point3x)); 
  float maxy=max(Point1y,max(Point2y,Point3y)); 
  
  int DestWidth=(int)ceil(fabs(maxx)-minx); 
  int DestHeight=(int)ceil(fabs(maxy)-miny); 
  
  tempimage.create(DestWidth,DestHeight,1);
  line.init(DestWidth);
  
  for(int i=0;i<DestWidth;i++){ //A white line of length=DestWidth
	line.pixels[i]=1;
  }
  
  for(int y=0;y<DestHeight;y++){ //Fill the Destination image with white, else clipmatra wont work
	tempimage.put_line(0,y,DestWidth,&line,0);
  }
  line.init(DestWidth);
  
  
  
  for(int y=0;y<DestHeight;y++) //Start filling the destination image pixels with corresponding source image pixels
  { 
	for(int x=0;x<DestWidth;x++) 
	{ 
	  int Srcx=(int)((x+minx)*cosine+(y+miny)*sine); 
	  int Srcy=(int)((y+miny)*cosine-(x+minx)*sine); 
	  if(Srcx>=0&&Srcx<srcwidth&&Srcy>=0&& 
		 Srcy<srcheight) 
	  { 
		line.pixels[x]= 
		  page_image.pixel(Srcx,Srcy); 
	  } 
	} 
	tempimage.put_line(0,y,DestWidth,&line,0);	
  } 
  
  //tempimage.write("tempimage.tif");
  page_image=tempimage;//Copy deskewed image to global page image, so it can be worked on further
	tempimage.destroy(); 
  //page_image.write("page_image.tif");
  
}