44#include <unordered_map>
231 PEAK_COMMON_NO_DISCARD
const char*
GetType()
const override;
510 return m_processingPolicy;
531 PEAK_COMMON_NO_DISCARD std::vector<std::shared_ptr<modules::IModule>> GetModules()
const override;
533 PEAK_COMMON_NO_DISCARD
virtual std::vector<std::shared_ptr<features::IFeature>> GetFeatures()
const;
535 PEAK_COMMON_NO_DISCARD
virtual std::shared_ptr<detail::MonoConversionModule> MonoConversionModule()
const;
537 PEAK_COMMON_NO_DISCARD
virtual std::shared_ptr<detail::PixelFormatConversionModule> FinalConversionModule()
const;
540 static std::string GetCurrentIsoUtcTime();
551 std::shared_ptr<detail::UnpackModule> m_unpack{ std::make_shared<detail::UnpackModule>() };
552 std::shared_ptr<detail::HotpixelCorrectionModule> m_hotpixel{ std::make_shared<detail::HotpixelCorrectionModule>() };
553 std::shared_ptr<detail::DownsamplingModule> m_binning{ std::make_shared<detail::DownsamplingModule>(
555 std::shared_ptr<detail::DownsamplingModule> m_decimation{ std::make_shared<detail::DownsamplingModule>(
557 std::shared_ptr<detail::TransformationModule> m_transformation{ std::make_shared<detail::TransformationModule>() };
558 std::shared_ptr<detail::GainModule> m_gain{ std::make_shared<detail::GainModule>() };
559 std::shared_ptr<detail::DebayerModule> m_debayer{ std::make_shared<detail::DebayerModule>() };
560 std::shared_ptr<detail::ColorMatrixTransformationModule> m_colorCorrection{
561 std::make_shared<detail::ColorMatrixTransformationModule>()
563 std::shared_ptr<detail::MonoConversionModule> m_monoConversion{ std::make_shared<detail::MonoConversionModule>() };
564 std::shared_ptr<detail::SharpeningModule> m_sharpening{ std::make_shared<detail::SharpeningModule>() };
565 std::shared_ptr<detail::ToneCurveCorrectionModule> m_toneCurveCorrection{ std::make_shared<detail::ToneCurveCorrectionModule>() };
566 std::shared_ptr<detail::PixelFormatConversionModule> m_finalConversion{ std::make_shared<detail::PixelFormatConversionModule>() };
568 std::shared_ptr<features::HotpixelCorrectionFeature> m_hotpixelFeature{
new features::HotpixelCorrectionFeature{ *m_hotpixel } };
569 std::shared_ptr<features::BinningFeature> m_binningFeature{
new features::BinningFeature{ *m_binning } };
570 std::shared_ptr<features::DecimationFeature> m_decimationFeature{
new features::DecimationFeature{ *m_decimation } };
571 std::shared_ptr<features::MirrorFeature> m_mirrorFeature{
new features::MirrorFeature{ *m_transformation } };
572 std::shared_ptr<features::RotationFeature> m_rotationFeature{
new features::RotationFeature{ *m_transformation } };
573 std::shared_ptr<features::GainFeature> m_gainFeature{
new features::GainFeature{ *m_gain } };
574 std::shared_ptr<features::ColorCorrectionFeature> m_colorCorrectionFeature{
new features::ColorCorrectionFeature{
575 *m_colorCorrection } };
576 std::shared_ptr<features::SaturationFeature> m_saturationFeature{
new features::SaturationFeature{ *m_colorCorrection } };
577 std::shared_ptr<features::SharpeningFeature> m_sharpeningFeature{
new features::SharpeningFeature{ *m_sharpening } };
578 std::shared_ptr<features::GammaFeature> m_gammaFeature{
new features::GammaFeature{ *m_toneCurveCorrection } };
579 std::shared_ptr<features::DigitalBlackFeature> m_digitalBlackFeature{
new features::DigitalBlackFeature{ *m_toneCurveCorrection } };
580 std::shared_ptr<features::ChromaticAdaptionFeature> m_chromaticAdaptionFeature{
new features::ChromaticAdaptionFeature{
581 *m_colorCorrection } };
583 std::shared_ptr<modules::IAutoFeature> m_autoFeatureModule;
585 constexpr static int pipelineVersion{ 1 };
590 m_monoConversion->SetEnabled(
false);
592 const auto format = m_finalConversion->GetOutputPixelFormat();
595 m_unpack->SetProcessingPolicy(m_processingPolicy);
596 m_unpack->SetTargetBitDepth(bitDepth);
597 m_debayer->SetProcessingPolicy(m_processingPolicy);
598 m_debayer->SetTargetBitDepth(bitDepth);
603 if (m_autoFeatureModule)
605 m_autoFeatureModule->SetGainModule(
nullptr);
611 const auto archive = std::make_shared<peak::icv::Archive>();
613 const auto moduleList = GetModules();
614 std::vector<std::shared_ptr<peak::common::serialization::IArchive>> modules;
615 modules.reserve(moduleList.size());
617 for (
const auto& module : moduleList)
619 if (module ==
nullptr)
623 auto moduleArchive = archive->CreateArchive();
624 moduleArchive->SetString(
"Type", module->GetType());
626 auto moduleDataArchive = moduleArchive->CreateArchive();
627 module->Serialize(*moduleDataArchive);
628 moduleArchive->SetArchive(
"Data", moduleDataArchive);
629 modules.push_back(moduleArchive);
631 archive->SetArchiveArray(
"Modules", modules);
632 archive->SetInt(
"Version", pipelineVersion);
633 archive->SetString(
"Type",
GetType());
634 archive->SetString(
"Creation", GetCurrentIsoUtcTime());
638 std::stringstream ss;
639 serializer.
Write(*archive, ss);
647 std::stringstream ss;
649 const auto archive = deserializer.
Read(ss);
651 const auto version = archive->GetInt(
"Version");
656 "The 'Version' entry " + std::to_string(version) +
" in the settings string is invalid! Must be at least 1.");
659 const auto pipelineType = archive->GetString(
"Type");
663 "The settings for " + pipelineType +
" are not compatible with this pipeline (" +
GetType() +
").");
666 const auto modules = GetModules();
668 std::unordered_map<std::string, std::shared_ptr<peak::common::serialization::IArchive>> archiveMap;
669 auto moduleArchives = archive->GetArchiveArray(
"Modules");
671 for (
const auto& moduleArchive : moduleArchives)
673 const auto moduleType = moduleArchive->GetString(
"Type");
674 const auto data = moduleArchive->GetArchive(
"Data");
675 archiveMap.emplace(moduleType, data);
678 for (
const auto& module : modules)
680 const auto found = archiveMap.find(module->GetType());
681 if (found == archiveMap.end())
683 throw peak::icv::IOException(std::string(
"The settings for module ") + module->GetType() +
" are missing!");
686 module->Deserialize(*found->second);
692 for (
const auto& module : GetModules())
694 module->ResetToDefault();
695 module->SetEnabled(true);
701 for (
const auto& feature : GetFeatures())
703 feature->ResetToDefault();
704 feature->SetEnabled(
true);
706 MonoConversionModule()->SetEnabled(
false);
707 m_processingPolicy = ProcessingPolicy::Fast;
712 return "DefaultPipeline";
717 m_unpack->ReleaseBuffers();
718 m_debayer->ReleaseBuffers();
719 MonoConversionModule()->ReleaseBuffers();
720 FinalConversionModule()->ReleaseBuffers();
725 return *m_mirrorFeature;
730 return *m_rotationFeature;
735 return *m_gainFeature;
740 return *m_colorCorrectionFeature;
745 return *m_saturationFeature;
750 return *m_gammaFeature;
755 return *m_digitalBlackFeature;
760 return *m_sharpeningFeature;
765 return *m_hotpixelFeature;
770 return *m_binningFeature;
775 return *m_decimationFeature;
780 return *m_chromaticAdaptionFeature;
787 for (
const auto& mod : GetModules())
796 data = mod->Process(data);
801 const auto*
const what = e.what();
802 const auto*
const moduleType = mod->GetType();
804 const auto errorText = std::string{
"[" } + moduleType +
"] " + what;
807 case PEAK_ICV_STATUS_LIBRARY_NOT_INITIALIZED:
808 case PEAK_ICV_STATUS_DYNAMIC_DEPENDENCY_MISSING:
810 case PEAK_ICV_STATUS_INVALID_HANDLE:
811 case PEAK_ICV_STATUS_INVALID_BUFFER_SIZE:
812 case PEAK_ICV_STATUS_MISMATCH:
813 case PEAK_ICV_STATUS_NULL_POINTER:
814 case PEAK_ICV_STATUS_NOT_SUPPORTED:
815 case PEAK_ICV_STATUS_NOT_POSSIBLE:
817 case PEAK_ICV_STATUS_CORRUPTED:
819 case PEAK_ICV_STATUS_OUT_OF_RANGE:
821 case PEAK_ICV_STATUS_INTERNAL_ERROR:
858 return FinalConversionModule()->GetOutputPixelFormat();
870 m_debayer->SetConversionPolicy(detail::DebayerConversionPolicy::Bypass);
872 else if (isMonoFormat)
874 m_debayer->SetConversionPolicy(detail::DebayerConversionPolicy::BayerOnly);
875 m_debayer->SetChannelLayout(DebayerChannelLayout::RGB);
879 m_debayer->SetConversionPolicy(detail::DebayerConversionPolicy::BayerAndMono);
884 m_debayer->SetConversionPolicy(detail::DebayerConversionPolicy::BayerAndMono);
890 m_debayer->SetChannelLayout(DebayerChannelLayout::RGB);
895 m_debayer->SetChannelLayout(DebayerChannelLayout::RGBA);
900 m_debayer->SetChannelLayout(DebayerChannelLayout::BGR);
905 m_debayer->SetChannelLayout(DebayerChannelLayout::BGRA);
913 MonoConversionModule()->SetEnabled(isMonoFormat);
915 FinalConversionModule()->SetOutputPixelFormat(format);
918 m_unpack->SetTargetBitDepth(bitDepth);
919 m_debayer->SetTargetBitDepth(bitDepth);
924 m_processingPolicy = policy;
926 m_unpack->SetProcessingPolicy(m_processingPolicy);
927 m_debayer->SetProcessingPolicy(m_processingPolicy);
932 if (m_autoFeatureModule !=
nullptr)
934 m_autoFeatureModule->SetGainModule(
nullptr);
937 m_autoFeatureModule = autoFeatureModule;
939 m_colorCorrection->SetAutoFeatureModule(m_autoFeatureModule);
941 if (m_autoFeatureModule !=
nullptr)
943 m_autoFeatureModule->SetGainModule(m_gain);
947inline std::string DefaultPipeline::GetCurrentIsoUtcTime()
949 const auto now = std::chrono::system_clock::now();
950 const std::time_t nowC = std::chrono::system_clock::to_time_t(now);
953#if defined(_WIN32) || defined(_WIN64)
954 gmtime_s(&tm, &nowC);
956 gmtime_r(&nowC, &tm);
959 std::ostringstream oss;
960 oss << std::put_time(&tm,
"%Y-%m-%dT%H:%M:%SZ");
964inline std::vector<std::shared_ptr<modules::IModule>> DefaultPipeline::GetModules()
const
966 if (m_autoFeatureModule ==
nullptr)
968 return { m_unpack, m_hotpixel, m_binning, m_decimation, m_transformation, m_gain, m_debayer, m_colorCorrection,
969 MonoConversionModule(), m_sharpening, m_toneCurveCorrection, FinalConversionModule() };
972 return { m_unpack, m_hotpixel, m_binning, m_decimation, m_transformation, m_gain, m_debayer, m_colorCorrection, m_autoFeatureModule,
973 MonoConversionModule(), m_sharpening, m_toneCurveCorrection, FinalConversionModule() };
976inline std::vector<std::shared_ptr<features::IFeature>> DefaultPipeline::GetFeatures()
const
978 return { m_hotpixelFeature, m_binningFeature, m_decimationFeature, m_mirrorFeature, m_rotationFeature, m_gainFeature,
979 m_colorCorrectionFeature, m_chromaticAdaptionFeature, m_saturationFeature, m_sharpeningFeature, m_gammaFeature,
980 m_digitalBlackFeature };
983inline std::shared_ptr<detail::MonoConversionModule> DefaultPipeline::MonoConversionModule()
const
985 return m_monoConversion;
988inline std::shared_ptr<detail::PixelFormatConversionModule> DefaultPipeline::FinalConversionModule()
const
990 return m_finalConversion;
IDSImaging.Peak.ICV.Pipeline.Types.ProcessingPolicy ProcessingPolicy
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.
Occurs when reading from a file or stream that is incomplete, damaged, or in an unexpected format.
Deserializer for reading serialized data and converting it into an IArchive object.
std::shared_ptr< peak::common::serialization::IArchive > Read(std::istream &stream) override
Reads serialized data from the specified stream and deserializes it into an archive.
Base class for all exceptions thrown by the IDS peak ICV library.
peak_icv_status GetStatus() const
Occurs when a file operation fails (e.g., missing file, insufficient permissions, or inaccessible dir...
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.
Occurs when a required dependency is missing, the library is not initialized, or a misconfiguration a...
Occurs when a requested operation is not implemented or supported (e.g., exporting to an unsupported ...
Occurs when a provided value falls outside the allowed valid range.
Serializer for writing IArchive objects to an output stream.
void Write(const peak::common::serialization::IArchive &archive, std::ostream &stream) override
Serializes an archive and writes it to a 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 for automatic image adjustments.
peak::icv::Image Process(const peak::icv::Image &image) const
Applies the pipeline to the given 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)
Defines the desired pixel format for processed images.
const char * GetType() const override
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
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.
features::ChromaticAdaptionFeature & ChromaticAdaption() const
Provides access to the chromatic adaption feature for adjusting to lighting conditions.
ProcessingPolicy GetProcessingPolicy() const
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. Also resets their enabled state....
~DefaultPipeline() override
Base class for implementing a custom pipeline.
Binning is used to decrease the image size.
Adjusts to changes in lighting conditions to maintain consistent color perception despite variations ...
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.
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.