tesseract  5.0.0-alpha-619-ge9db
debugpixa.h
Go to the documentation of this file.
1 #ifndef TESSERACT_CCSTRUCT_DEBUGPIXA_H_
2 #define TESSERACT_CCSTRUCT_DEBUGPIXA_H_
3 
4 #include "allheaders.h"
5 
6 namespace tesseract {
7 
8 // Class to hold a Pixa collection of debug images with captions and save them
9 // to a PDF file.
10 class DebugPixa {
11  public:
12  // TODO(rays) add another constructor with size control.
14  pixa_ = pixaCreate(0);
15  fonts_ = bmfCreate(nullptr, 14);
16  }
17  // If the filename_ has been set and there are any debug images, they are
18  // written to the set filename_.
20  pixaDestroy(&pixa_);
21  bmfDestroy(&fonts_);
22  }
23 
24  // Adds the given pix to the set of pages in the PDF file, with the given
25  // caption added to the top.
26  void AddPix(const Pix* pix, const char* caption) {
27  int depth = pixGetDepth(const_cast<Pix*>(pix));
28  int color = depth < 8 ? 1 : (depth > 8 ? 0x00ff0000 : 0x80);
29  Pix* pix_debug = pixAddSingleTextblock(
30  const_cast<Pix*>(pix), fonts_, caption, color, L_ADD_BELOW, nullptr);
31  pixaAddPix(pixa_, pix_debug, L_INSERT);
32  }
33 
34  // Sets the destination filename and enables images to be written to a PDF
35  // on destruction.
36  void WritePDF(const char* filename) {
37  if (pixaGetCount(pixa_) > 0) {
38  pixaConvertToPdf(pixa_, 300, 1.0f, 0, 0, "AllDebugImages", filename);
39  pixaClear(pixa_);
40  }
41  }
42 
43  private:
44  // The collection of images to put in the PDF.
45  Pixa* pixa_;
46  // The fonts used to draw text captions.
47  L_Bmf* fonts_;
48 };
49 
50 } // namespace tesseract
51 
52 #endif // TESSERACT_CCSTRUCT_DEBUGPIXA_H_
tesseract::DebugPixa::WritePDF
void WritePDF(const char *filename)
Definition: debugpixa.h:36
tesseract::DebugPixa::~DebugPixa
~DebugPixa()
Definition: debugpixa.h:19
tesseract::DebugPixa::AddPix
void AddPix(const Pix *pix, const char *caption)
Definition: debugpixa.h:26
tesseract
Definition: baseapi.h:65
tesseract::DebugPixa
Definition: debugpixa.h:10
tesseract::DebugPixa::DebugPixa
DebugPixa()
Definition: debugpixa.h:13