43#include <unordered_map>
566 return m_processingPolicy;
585 static std::string GetCurrentIsoUtcTime();
594 std::shared_ptr<detail::UnpackModule> m_unpack{ std::make_shared<detail::UnpackModule>() };
595 std::shared_ptr<detail::HotpixelCorrectionModule> m_hotpixel{ std::make_shared<detail::HotpixelCorrectionModule>() };
596 std::shared_ptr<detail::DownsamplingModule> m_binning{ std::make_shared<detail::DownsamplingModule>(
598 std::shared_ptr<detail::DownsamplingModule> m_decimation{ std::make_shared<detail::DownsamplingModule>(
600 std::shared_ptr<detail::TransformationModule> m_transformation{ std::make_shared<detail::TransformationModule>() };
601 std::shared_ptr<detail::GainModule> m_gain{ std::make_shared<detail::GainModule>() };
602 std::shared_ptr<detail::DebayerModule> m_debayer{ std::make_shared<detail::DebayerModule>() };
603 std::shared_ptr<detail::ColorMatrixTransformationModule> m_colorCorrection{
604 std::make_shared<detail::ColorMatrixTransformationModule>()
606 std::shared_ptr<detail::MonoConversionModule> m_monoConversion{ std::make_shared<detail::MonoConversionModule>() };
607 std::shared_ptr<detail::SharpeningModule> m_sharpening{ std::make_shared<detail::SharpeningModule>() };
608 std::shared_ptr<detail::ToneCurveCorrectionModule> m_toneCurveCorrection{ std::make_shared<detail::ToneCurveCorrectionModule>() };
609 std::shared_ptr<detail::PixelFormatConversionModule> m_finalConversion{ std::make_shared<detail::PixelFormatConversionModule>() };
611 std::shared_ptr<features::HotpixelCorrectionFeature> m_hotpixelFeature{
new features::HotpixelCorrectionFeature{ *m_hotpixel } };
612 std::shared_ptr<features::BinningFeature> m_binningFeature{
new features::BinningFeature{ *m_binning } };
613 std::shared_ptr<features::DecimationFeature> m_decimationFeature{
new features::DecimationFeature{ *m_decimation } };
614 std::shared_ptr<features::MirrorFeature> m_mirrorFeature{
new features::MirrorFeature{ *m_transformation } };
615 std::shared_ptr<features::RotationFeature> m_rotationFeature{
new features::RotationFeature{ *m_transformation } };
616 std::shared_ptr<features::GainFeature> m_gainFeature{
new features::GainFeature{ *m_gain } };
617 std::shared_ptr<features::ColorCorrectionFeature> m_colorCorrectionFeature{
new features::ColorCorrectionFeature{
618 *m_colorCorrection } };
619 std::shared_ptr<features::SaturationFeature> m_saturationFeature{
new features::SaturationFeature{ *m_colorCorrection } };
620 std::shared_ptr<features::SharpeningFeature> m_sharpeningFeature{
new features::SharpeningFeature{ *m_sharpening } };
621 std::shared_ptr<features::GammaFeature> m_gammaFeature{
new features::GammaFeature{ *m_toneCurveCorrection } };
622 std::shared_ptr<features::DigitalBlackFeature> m_digitalBlackFeature{
new features::DigitalBlackFeature{ *m_toneCurveCorrection } };
624 std::shared_ptr<modules::IAutoFeature> m_autoFeatureModule;
626 constexpr static int pipelineVersion{ 1 };
631 m_monoConversion->SetEnabled(
false);
633 const auto format = m_finalConversion->GetOutputPixelFormat();
636 m_unpack->SetProcessingPolicy(m_processingPolicy);
637 m_unpack->SetTargetBitDepth(bitDepth);
638 m_debayer->SetProcessingPolicy(m_processingPolicy);
639 m_debayer->SetTargetBitDepth(bitDepth);
644 if (m_autoFeatureModule)
646 m_autoFeatureModule->SetGainModule(
nullptr);
652 const auto archive = std::make_shared<peak::icv::Archive>();
654 const auto moduleList = GetModules();
655 std::vector<std::shared_ptr<peak::common::serialization::IArchive>> modules;
656 modules.reserve(moduleList.size());
658 for (
const auto& module : moduleList)
660 if (module ==
nullptr)
664 auto moduleArchive = archive->CreateArchive();
665 moduleArchive->SetString(
"Type", module->GetType());
667 auto moduleDataArchive = moduleArchive->CreateArchive();
668 module->Serialize(*moduleDataArchive);
669 moduleArchive->SetArchive(
"Data", moduleDataArchive);
670 modules.push_back(moduleArchive);
672 archive->SetArchiveArray(
"Modules", modules);
673 archive->SetInt(
"Version", pipelineVersion);
674 archive->SetString(
"Type",
GetType());
675 archive->SetString(
"Creation", GetCurrentIsoUtcTime());
679 std::stringstream ss;
680 serializer.
Write(*archive, ss);
688 std::stringstream ss;
690 const auto archive = deserializer.
Read(ss);
692 const auto version = archive->GetInt(
"Version");
697 "The 'Version' entry " + std::to_string(version) +
" in the settings string is invalid! Must be at least 1.");
700 const auto pipelineType = archive->GetString(
"Type");
704 "The settings for " + pipelineType +
" are not compatible with this pipeline (" +
GetType() +
").");
707 std::vector<std::shared_ptr<modules::IModule>> modules;
708 if (m_autoFeatureModule ==
nullptr)
710 modules = { m_unpack, m_hotpixel, m_binning, m_decimation, m_transformation, m_gain, m_debayer, m_colorCorrection, m_monoConversion,
711 m_sharpening, m_toneCurveCorrection, m_finalConversion };
715 modules = { m_unpack, m_hotpixel, m_binning, m_decimation, m_transformation, m_gain, m_debayer, m_colorCorrection,
716 m_autoFeatureModule, m_monoConversion, m_sharpening, m_toneCurveCorrection, m_finalConversion };
719 std::unordered_map<std::string, std::shared_ptr<peak::common::serialization::IArchive>> archiveMap;
720 auto moduleArchives = archive->GetArchiveArray(
"Modules");
722 for (
const auto& moduleArchive : moduleArchives)
724 const auto moduleType = moduleArchive->GetString(
"Type");
725 const auto data = moduleArchive->GetArchive(
"Data");
726 archiveMap.emplace(moduleType, data);
729 for (
const auto& module : modules)
731 const auto found = archiveMap.find(module->GetType());
732 if (found == archiveMap.end())
737 module->Deserialize(*found->second);
743 for (
const auto& module : GetModules())
745 module->ResetToDefault();
746 module->SetEnabled(true);
748 for (
const auto& feature : GetFeatures())
750 feature->ResetToDefault();
751 feature->SetEnabled(
true);
753 m_monoConversion->SetEnabled(
false);
758 return "DefaultPipeline";
763 m_unpack->ReleaseBuffers();
764 m_debayer->ReleaseBuffers();
765 m_monoConversion->ReleaseBuffers();
766 m_finalConversion->ReleaseBuffers();
771 return *m_mirrorFeature;
776 return *m_rotationFeature;
781 return *m_gainFeature;
786 return *m_colorCorrectionFeature;
791 return *m_saturationFeature;
796 return *m_gammaFeature;
801 return *m_digitalBlackFeature;
806 return *m_sharpeningFeature;
811 return *m_hotpixelFeature;
816 return *m_binningFeature;
821 return *m_decimationFeature;
828 for (
const auto& mod : GetModules())
837 data = mod->Process(data);
841 const auto errorCode = e.GetStatus();
842 const auto*
const what = e.what();
843 const auto*
const moduleType = mod->GetType();
845 const auto errorText = std::string{
"[" } + moduleType +
"] " + what;
848 case PEAK_ICV_STATUS_LIBRARY_NOT_INITIALIZED:
849 case PEAK_ICV_STATUS_DYNAMIC_DEPENDENCY_MISSING:
851 case PEAK_ICV_STATUS_INVALID_HANDLE:
852 case PEAK_ICV_STATUS_INVALID_BUFFER_SIZE:
853 case PEAK_ICV_STATUS_MISMATCH:
854 case PEAK_ICV_STATUS_NULL_POINTER:
855 case PEAK_ICV_STATUS_NOT_SUPPORTED:
856 case PEAK_ICV_STATUS_NOT_POSSIBLE:
858 case PEAK_ICV_STATUS_CORRUPTED:
860 case PEAK_ICV_STATUS_OUT_OF_RANGE:
862 case PEAK_ICV_STATUS_INTERNAL_ERROR:
899 return m_finalConversion->GetOutputPixelFormat();
913 else if (isMonoFormat)
954 m_monoConversion->SetEnabled(isMonoFormat);
956 m_finalConversion->SetOutputPixelFormat(format);
959 m_unpack->SetProcessingPolicy(m_processingPolicy);
960 m_unpack->SetTargetBitDepth(bitDepth);
961 m_debayer->SetProcessingPolicy(m_processingPolicy);
962 m_debayer->SetTargetBitDepth(bitDepth);
967 m_processingPolicy = policy;
969 m_unpack->SetProcessingPolicy(m_processingPolicy);
970 m_debayer->SetProcessingPolicy(m_processingPolicy);
973 m_unpack->SetTargetBitDepth(bitDepth);
974 m_debayer->SetTargetBitDepth(bitDepth);
979 if (m_autoFeatureModule !=
nullptr)
981 m_autoFeatureModule->SetGainModule(
nullptr);
984 m_autoFeatureModule = autoFeatureModule;
986 m_colorCorrection->SetAutoFeatureModule(m_autoFeatureModule);
988 if (m_autoFeatureModule !=
nullptr)
990 m_autoFeatureModule->SetGainModule(m_gain);
994inline std::string DefaultPipeline::GetCurrentIsoUtcTime()
996 const auto now = std::chrono::system_clock::now();
997 const std::time_t nowC = std::chrono::system_clock::to_time_t(now);
1000#if defined(_WIN32) || defined(_WIN64)
1001 gmtime_s(&tm, &nowC);
1003 gmtime_r(&nowC, &tm);
1006 std::ostringstream oss;
1007 oss << std::put_time(&tm,
"%Y-%m-%dT%H:%M:%SZ");
1011inline std::vector<std::shared_ptr<modules::IModule>> DefaultPipeline::GetModules()
const
1013 if (m_autoFeatureModule ==
nullptr)
1015 return { m_unpack, m_hotpixel, m_binning, m_decimation, m_transformation, m_gain, m_debayer, m_colorCorrection, m_monoConversion,
1016 m_sharpening, m_toneCurveCorrection, m_finalConversion };
1019 return { m_unpack, m_hotpixel, m_binning, m_decimation, m_transformation, m_gain, m_debayer, m_colorCorrection, m_autoFeatureModule,
1020 m_monoConversion, m_sharpening, m_toneCurveCorrection, m_finalConversion };
1023inline std::vector<std::shared_ptr<features::IFeature>> DefaultPipeline::GetFeatures()
const
1025 return { m_hotpixelFeature, m_binningFeature, m_decimationFeature, m_mirrorFeature, m_rotationFeature, m_gainFeature,
1026 m_colorCorrectionFeature, m_saturationFeature, m_sharpeningFeature, m_gammaFeature, m_digitalBlackFeature };
A type-erased container for any copyable value.
T & AnyCast()
Casts the stored value to the specified type.
Interface for viewing image pixel data from arbitrary sources.
Thrown when an input, output, file or device communication error occurs.
Thrown when input data or a file is malformed, unreadable, or otherwise corrupted.
A deserializer that reads serialized data and converts it to IArchive objects.
std::shared_ptr< peak::common::serialization::IArchive > Read(std::istream &stream) override
Reads and deserializes data from an input stream.
The base class for all exceptions thrown by the IDS peak ICV library.
For detailed information about the use of ids_peak_icv Image refer to the Image Guide.
uint8_t * GetData() const
Provides a pointer to the image data buffer.
Image Copy() const
Creates a deep copy of the current Image.
Thrown when the library configuration is invalid.
Thrown when a requested operation is not implemented or supported.
Thrown when a value is outside the allowed range.
A serializer that serializes IArchive objects.
void Write(const peak::common::serialization::IArchive &archive, std::ostream &stream) override
Writes the serialized archive data to an output stream.
Image processing pipeline for sequential transformation of raw image frames.
features::MirrorFeature & Mirror() const
Provides access to the mirror feature for image mirroring operations.
void SetAutoFeatureModule(const std::shared_ptr< modules::IAutoFeature > &autoFeatureModule)
Sets an auto feature module used in the pipeline.
peak::icv::Image Process(const peak::icv::Image &image) const
Processes the input image and returns the result as a new image.
peak::icv::Image operator<<(const peak::icv::Image &image) const
Convenience operator for processing input using the pipeline.
features::SharpeningFeature & Sharpening() const
Provides access to the sharpening feature for image detail enhancement.
void SetOutputPixelFormat(peak::common::PixelFormat format)
Configures the pipeline for output format.
const char * GetType() const override
Returns the type of the module for serialization purposes.
features::DecimationFeature & Decimation() const
Provides access to the decimation feature for resolution reduction by pixel skipping.
void ImportSettingsFromString(const std::string &settings) override
Restores pipeline settings from a previously serialized string.
features::BinningFeature & Binning() const
Provides access to the binning feature for resolution reduction and noise improvement.
features::DigitalBlackFeature & DigitalBlack() const
Provides access to the digital black feature for sensor offset correction.
void ReleaseBuffers() const
Frees unused internal buffers.
features::SaturationFeature & Saturation() const
Provides access to the saturation feature for color intensity adjustments.
peak::common::PixelFormat GetOutputPixelFormat() const
Retrieves the output pixel format of the pipeline.
features::ColorCorrectionFeature & ColorCorrection() const
Provides access to the color correction feature for color space transformations.
features::HotpixelCorrectionFeature & HotpixelCorrection() const
Provides access to the hot pixel correction feature for defective pixel repair.
features::GammaFeature & Gamma() const
Provides access to the gamma feature for brightness and contrast adjustments.
ProcessingPolicy GetProcessingPolicy() const
Retrieves the current processing policy of the image processing pipeline.
DefaultPipeline()
Creates a DefaultPipeline with default module settings.
features::GainFeature & Gain() const
Provides access to the gain feature for brightness and white balance adjustments.
std::string ExportSettingsToString() const override
Converts the current pipeline settings into a string format.
void SetProcessingPolicy(ProcessingPolicy policy)
Sets the processing policy for the image processing pipeline.
features::RotationFeature & Rotation() const
Provides access to the rotation feature for image rotation operations.
void ResetToDefault() override
Resets all modules in the pipeline to their default state.
~DefaultPipeline() override
Base class for implementing a custom pipeline.
Binning is used to decrease the image size.
Color correction applies a 3x3 ColorCorrectionMatrix to the image.
Decimation is used to decrease the image size.
Digital black applies digital black correction to an image.
The GainFeature applies gain to the image.
Gamma applies an inverse gamma transformation to an image.
HotpixelCorrection detects and corrects hot pixels in camera images.
Mirror provides functionality to flip the image left-right or up-down.
Rotation provides fixed-angle rotation functionality.
Adjusts the saturation of an image by modifying a 3x3 ColorCorrectionMatrix.
Sharpening applies a sharpening filter to enhance image detail.
#define PEAK_COMMON_NO_DISCARD
Compatability macro for the nodiscard attribute.
PixelFormat
Enum listing all supported pixel formats and their internal IDs.
@ RGBa10
RGBA 10-Bit pixel format.
@ RGB8
RGB 8-Bit pixel format.
@ RGBa8
RGBA 8-Bit pixel format.
@ RGBa12
RGBA 12-Bit pixel format.
@ BGRa12
BGRA 12-Bit pixel format.
@ BGR12
BGR 12-Bit pixel format.
@ RGB10
RGB 10-Bit pixel format.
@ BGR10
BGR 10-Bit pixel format.
@ RGB12
RGB 12-Bit pixel format.
@ BGRa8
BGRA 8-Bit pixel format.
@ BGRa10
BGRA 10-Bit pixel format.
@ BGR8
BGR 8-Bit pixel format.
@ BinningAverage
The averaged pixel values of neighboring rows and/or columns are computed during binning.
@ Decimation
The additional pixel values of neighboring rows and/or columns are skipped during decimation.
ProcessingPolicy
Specifies the processing policy.
@ BGR
Blue-Green-Red format with 3 channels.
@ BGRA
Blue-Green-Red-Alpha format with 4 channels.
@ RGB
Red-Green-Blue format with 3 channels.
@ RGBA
Red-Green-Blue-Alpha format with 4 channels.
@ Bypass
Do not convert images.
@ BayerOnly
Convert only Bayer-pattern images.
@ BayerAndMono
Convert both Bayer-pattern and monochrome images.