16#include <opencv2/opencv.hpp>
40 img = cv::imdecode(req.
imageBytes, cv::IMREAD_GRAYSCALE);
41 label = std::string(
"<bytes>");
46 if (!std::filesystem::exists(p))
return res;
47 img = cv::imread(p.string(), cv::IMREAD_GRAYSCALE);
50 if (img.empty())
return res;
54 if (!blocks.empty()) {
57 for (
const auto &b : blocks) {
67 if (!tables.empty()) {
68 res.
table = tables[0];
72 if (debugger && debugger->enabled()) debugger->writeText(
"opencv/error.txt",
"OpenCvDocumentImageProcessorAdapter::detect failed");
83 img = cv::imdecode(req.
imageBytes, cv::IMREAD_COLOR);
88 if (!std::filesystem::exists(p))
return res;
89 img = cv::imread(p.string(), cv::IMREAD_COLOR);
91 if (img.empty())
return res;
93 std::vector<core::ports::document_image_processing::Rect> rects; rects.push_back(req.
bbox);
105 if (debugger && debugger->enabled()) debugger->writeText(
"opencv/error.txt",
"OpenCvDocumentImageProcessorAdapter::crop failed");
111 std::shared_ptr<core::ports::diagnostics::IDiagnostics> debugger;
115 return std::make_shared<OpenCvDocumentImageProcessorAdapter>(std::move(debugger));
Declares the OpenCV crop adapter used by the import workflow.
Declares the OpenCV denoise adapter used by the import workflow.
Declares the OpenCV detection adapter used by the import workflow.
Request types for document image processing operations.
Result types for document image processing operations.
Declares the diagnostics artifact writing port.
Document image processing port for import workflows.
Declares the OpenCV masking adapter used by the import workflow.
std::shared_ptr< core::ports::document_image_processing::IDocumentImageProcessor > createDocumentImageProcessorAdapter(std::shared_ptr< core::ports::diagnostics::IDiagnostics > debugger)
core::ports::document_image_processing::DenoiseResult denoise(const core::ports::document_image_processing::DenoiseRequest &req) const override
Removes noise from an image.
OpenCvDocumentImageProcessorAdapter(std::shared_ptr< core::ports::diagnostics::IDiagnostics > dbg=nullptr)
core::ports::document_image_processing::DetectResult detect(const core::ports::document_image_processing::DetectRequest &req) const override
Detects table or text regions in an image.
core::ports::document_image_processing::CropResult crop(const core::ports::document_image_processing::CropRequest &req) const override
Crops an image into one or more regions.
core::ports::document_image_processing::MaskResult mask(const core::ports::document_image_processing::MaskRequest &req) const override
Applies a mask to an image.
Processes document images for the import pipeline.
static std::vector< std::filesystem::path > cropImages(const std::string &imagePath, const std::vector< ports::Rect > &rects, const std::filesystem::path &outputDir, ports::CropRequest::OutputFormat fmt, int jpegQuality=92, std::shared_ptr< core::ports::diagnostics::IDiagnostics > debugger=nullptr, const std::string &filePrefix="")
Crops multiple rectangles from an image file and writes the results to disk.
static ports::DenoiseResult denoise(const ports::DenoiseRequest &req, std::shared_ptr< core::ports::diagnostics::IDiagnostics > debugger=nullptr)
Applies the configured denoise operation to the input image.
static std::vector< cv::Rect > detectTextBlocks(const cv::Mat &img, std::shared_ptr< core::ports::diagnostics::IDiagnostics > debugger=nullptr)
Detects text blocks in a source image.
static std::vector< ports::Table > detectTables(const cv::Mat &img, const std::string &imagePath, std::shared_ptr< core::ports::diagnostics::IDiagnostics > debugger=nullptr)
Detects table structures in a source image.
static ports::MaskResult mask(const ports::MaskRequest &req, std::shared_ptr< core::ports::diagnostics::IDiagnostics > debugger=nullptr)
Builds a whiteout mask for the requested image region.
Precompiled header for the document-image-processing infrastructure module.
std::shared_ptr< std::atomic< bool > > cancelFlag
enum core::ports::document_image_processing::CropRequest::OutputFormat outputFormat
std::filesystem::path imagePath
std::vector< uint8_t > imageBytes
std::filesystem::path outputDir
std::vector< std::filesystem::path > croppedImagePaths
std::vector< std::vector< uint8_t > > croppedImageBytes
std::shared_ptr< std::atomic< bool > > cancelFlag
std::vector< uint8_t > imageBytes
enum core::ports::document_image_processing::DetectRequest::DetectKind kind
std::shared_ptr< std::atomic< bool > > cancelFlag
std::filesystem::path imagePath
std::vector< Rect > textBlocks
std::shared_ptr< std::atomic< bool > > cancelFlag