aboutsummaryrefslogtreecommitdiff
path: root/cpp/image.cpp
blob: 63f0a082359cfaa6eec24ba9b1fa47596ba1e5ae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <leptonica/allheaders.h>
#include <tesseract/baseapi.h>

#include "../include/image.h"

namespace image {
void preprocessImage(Pix **image) {
  Pix *temp;

  // Scale
  if (scaleFactor != 1) {
    INLINE_IMAGE_PROC(pixScale(*image, scaleFactor, scaleFactor));
  }

  // Grayscale
  if (pixGetDepth(*image) > 8) {
    INLINE_IMAGE_PROC(pixConvertRGBToGray(
        *image, grayscaleWeightRed, grayscaleWeightGreen, grayscaleWeightBlue));
  }

  // Contrast
  pixContrastTRC(*image, *image, contrast);

  // Sharpness
  // INLINE_IMAGE_PROC(pixUnsharpMaskingGrayFast(*image, 1, sharpness, 1));
  INLINE_IMAGE_PROC(pixUnsharpMasking(*image, 1, sharpness));
}

Pix *loadImage(const char *imagePath) {
  Pix *image = pixRead(imagePath);
  if (!image) {
    std::cerr << "Could not load image " << imagePath << std::endl;
    return nullptr;
  }

  preprocessImage(&image);

  return image;
}
} // namespace image