ccmain/api.cpp

Go to the documentation of this file.
00001 // Threshold the given grey or color image into the tesseract global
00002 // image ready for recognition. Requires thresholds and hi_value
00003 // produced by OtsuThreshold above.
00004 void TessBaseAPI::ThresholdRect(const UINT8* imagedata,
00005                                 int bytes_per_pixel,
00006                                 int bytes_per_line,
00007                                 int left, int top,
00008                                 int width, int height,
00009                                 const int* thresholds,
00010                                 const int* hi_values) {
00011   IMAGELINE line;
00012   page_image.create(width, height, 1);
00013   line.init(width);
00014   // For each line in the image, fill the IMAGELINE class and put it into the
00015   // Tesseract global page_image. Note that Tesseract stores images with the
00016   // bottom at y=0 and 0 is black, so we need 2 kinds of inversion.
00017   //fmg: unless told otherwise, I'll assume that UNIT8* is == char*
00018 
00019 
00020   const UINT8* data = imagedata + top*bytes_per_line + left*bytes_per_pixel;
00021   for (int y = height - 1 ; y >= 0; --y) {
00022     const UINT8* pix = data;
00023     for (int x = 0; x < width; ++x, pix += bytes_per_pixel) {
00024       line.pixels[x] = 1;
00025       for (int ch = 0; ch < bytes_per_pixel; ++ch) {
00026         if (hi_values[ch] >= 0 && (pix[ch] > thresholds[ch]) == (hi_values[ch] == 0)) {
00027           line.pixels[x] = 0;
00028           break;
00029         }//if
00030       }//for bytes in each pixel
00031     }//for x
00032     page_image.put_line(0, y, width, &line, 0);
00033     data += bytes_per_line;
00034   }//for y
00035 }//TessBaseAPI::ThresholdRect
00036 

Generated on Wed Feb 28 19:49:07 2007 for Tesseract by  doxygen 1.5.1