From 83e2570d3c8da9920d66a00c4bdf5650fe1b3336 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Wed, 25 Dec 2024 22:33:03 +0530 Subject: Parallel ocr evaluation for sections of screen + many refactorings --- cpp/image.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 cpp/image.cpp (limited to 'cpp/image.cpp') diff --git a/cpp/image.cpp b/cpp/image.cpp new file mode 100644 index 0000000..63f0a08 --- /dev/null +++ b/cpp/image.cpp @@ -0,0 +1,41 @@ +#include +#include +#include + +#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 -- cgit v1.3.1