43#include <unordered_map>
318 PEAK_COMMON_NO_DISCARD
const char*
GetType()
const override;
581 return m_processingPolicy;
603 static std::string GetCurrentIsoUtcTime();
605 PEAK_COMMON_NO_DISCARD std::vector<std::shared_ptr<modules::IModule>> GetModules()
const override;
606 PEAK_COMMON_NO_DISCARD std::vector<std::shared_ptr<features::IFeature>> GetFeatures()
const;
617 std::shared_ptr<detail::UnpackModule> m_unpack{ std::make_shared<detail::UnpackModule>() };
618 std::shared_ptr<detail::HotpixelCorrectionModule> m_hotpixel{ std::make_shared<detail::HotpixelCorrectionModule>() };
619 std::shared_ptr<detail::DownsamplingModule> m_binning{ std::make_shared<detail::DownsamplingModule>(
621 std::shared_ptr<detail::DownsamplingModule> m_decimation{ std::make_shared<detail::DownsamplingModule>(
623 std::shared_ptr<detail::TransformationModule> m_transformation{ std::make_shared<detail::TransformationModule>() };
624 std::shared_ptr<detail::GainModule> m_gain{ std::make_shared<detail::GainModule>() };
625 std::shared_ptr<detail::DebayerModule> m_debayer{ std::make_shared<detail::DebayerModule>() };
626 std::shared_ptr<detail::ColorMatrixTransformationModule> m_colorCorrection{
627 std::make_shared<detail::ColorMatrixTransformationModule>()
629 std::shared_ptr<detail::MonoConversionModule> m_monoConversion{ std::make_shared<detail::MonoConversionModule>() };
630 std::shared_ptr<detail::SharpeningModule> m_sharpening{ std::make_shared<detail::SharpeningModule>() };
631 std::shared_ptr<detail::ToneCurveCorrectionModule> m_toneCurveCorrection{ std::make_shared<detail::ToneCurveCorrectionModule>() };
632 std::shared_ptr<detail::PixelFormatConversionModule> m_finalConversion{ std::make_shared<detail::PixelFormatConversionModule>() };
634 std::shared_ptr<features::HotpixelCorrectionFeature> m_hotpixelFeature{
new features::HotpixelCorrectionFeature{ *m_hotpixel } };
635 std::shared_ptr<features::BinningFeature> m_binningFeature{
new features::BinningFeature{ *m_binning } };
636 std::shared_ptr<features::DecimationFeature> m_decimationFeature{
new features::DecimationFeature{ *m_decimation } };
637 std::shared_ptr<features::MirrorFeature> m_mirrorFeature{
new features::MirrorFeature{ *m_transformation } };
638 std::shared_ptr<features::RotationFeature> m_rotationFeature{
new features::RotationFeature{ *m_transformation } };
639 std::shared_ptr<features::GainFeature> m_gainFeature{
new features::GainFeature{ *m_gain } };
640 std::shared_ptr<features::ColorCorrectionFeature> m_colorCorrectionFeature{
new features::ColorCorrectionFeature{
641 *m_colorCorrection } };
642 std::shared_ptr<features::SaturationFeature> m_saturationFeature{
new features::SaturationFeature{ *m_colorCorrection } };
643 std::shared_ptr<features::SharpeningFeature> m_sharpeningFeature{
new features::SharpeningFeature{ *m_sharpening } };
644 std::shared_ptr<features::GammaFeature> m_gammaFeature{
new features::GammaFeature{ *m_toneCurveCorrection } };
645 std::shared_ptr<features::DigitalBlackFeature> m_digitalBlackFeature{
new features::DigitalBlackFeature{ *m_toneCurveCorrection } };
647 std::shared_ptr<modules::IAutoFeature> m_autoFeatureModule;
649 constexpr static int pipelineVersion{ 1 };
654 m_monoConversion->SetEnabled(
false);
656 const auto format = m_finalConversion->GetOutputPixelFormat();
659 m_unpack->SetProcessingPolicy(m_processingPolicy);
660 m_unpack->SetTargetBitDepth(bitDepth);
661 m_debayer->SetProcessingPolicy(m_processingPolicy);
662 m_debayer->SetTargetBitDepth(bitDepth);
667 if (m_autoFeatureModule)
669 m_autoFeatureModule->SetGainModule(
nullptr);
675 const auto archive = std::make_shared<peak::icv::Archive>();
677 const auto moduleList = GetModules();
678 std::vector<std::shared_ptr<peak::common::serialization::IArchive>> modules;
679 modules.reserve(moduleList.size());
681 for (
const auto& module : moduleList)
683 if (module ==
nullptr)
687 auto moduleArchive = archive->CreateArchive();
688 moduleArchive->SetString(
"Type", module->GetType());
690 auto moduleDataArchive = moduleArchive->CreateArchive();
691 module->Serialize(*moduleDataArchive);
692 moduleArchive->SetArchive(
"Data", moduleDataArchive);
693 modules.push_back(moduleArchive);
695 archive->SetArchiveArray(
"Modules", modules);
696 archive->SetInt(
"Version", pipelineVersion);
697 archive->SetString(
"Type",
GetType());
698 archive->SetString(
"Creation", GetCurrentIsoUtcTime());
702 std::stringstream ss;
703 serializer.
Write(*archive, ss);
711 std::stringstream ss;
713 const auto archive = deserializer.
Read(ss);
715 const auto version = archive->GetInt(
"Version");
720 "The 'Version' entry " + std::to_string(version) +
" in the settings string is invalid! Must be at least 1.");
723 const auto pipelineType = archive->GetString(
"Type");
727 "The settings for " + pipelineType +
" are not compatible with this pipeline (" +
GetType() +
").");
730 std::vector<std::shared_ptr<modules::IModule>> modules;
731 if (m_autoFeatureModule ==
nullptr)
733 modules = { m_unpack, m_hotpixel, m_binning, m_decimation, m_transformation, m_gain, m_debayer, m_colorCorrection, m_monoConversion,
734 m_sharpening, m_toneCurveCorrection, m_finalConversion };
738 modules = { m_unpack, m_hotpixel, m_binning, m_decimation, m_transformation, m_gain, m_debayer, m_colorCorrection,
739 m_autoFeatureModule, m_monoConversion, m_sharpening, m_toneCurveCorrection, m_finalConversion };
742 std::unordered_map<std::string, std::shared_ptr<peak::common::serialization::IArchive>> archiveMap;
743 auto moduleArchives = archive->GetArchiveArray(
"Modules");
745 for (
const auto& moduleArchive : moduleArchives)
747 const auto moduleType = moduleArchive->GetString(
"Type");
748 const auto data = moduleArchive->GetArchive(
"Data");
749 archiveMap.emplace(moduleType, data);
752 for (
const auto& module : modules)
754 const auto found = archiveMap.find(module->GetType());
755 if (found == archiveMap.end())
757 throw peak::icv::IOException(std::string(
"The settings for module ") + module->GetType() +
" are missing!");
760 module->Deserialize(*found->second);
766 for (
const auto& module : GetModules())
768 module->ResetToDefault();
769 module->SetEnabled(true);
771 for (
const auto& feature : GetFeatures())
773 feature->ResetToDefault();
774 feature->SetEnabled(
true);
776 m_monoConversion->SetEnabled(
false);
781 return "DefaultPipeline";
786 m_unpack->ReleaseBuffers();
787 m_debayer->ReleaseBuffers();
788 m_monoConversion->ReleaseBuffers();
789 m_finalConversion->ReleaseBuffers();
794 return *m_mirrorFeature;
799 return *m_rotationFeature;
804 return *m_gainFeature;
809 return *m_colorCorrectionFeature;
814 return *m_saturationFeature;
819 return *m_gammaFeature;
824 return *m_digitalBlackFeature;
829 return *m_sharpeningFeature;
834 return *m_hotpixelFeature;
839 return *m_binningFeature;
844 return *m_decimationFeature;
851 for (
const auto& mod : GetModules())
860 data = mod->Process(data);
864 const auto errorCode = e.GetStatus();
865 const auto*
const what = e.what();
866 const auto*
const moduleType = mod->GetType();
868 const auto errorText = std::string{
"[" } + moduleType +
"] " + what;
871 case PEAK_ICV_STATUS_LIBRARY_NOT_INITIALIZED:
872 case PEAK_ICV_STATUS_DYNAMIC_DEPENDENCY_MISSING:
874 case PEAK_ICV_STATUS_INVALID_HANDLE:
875 case PEAK_ICV_STATUS_INVALID_BUFFER_SIZE:
876 case PEAK_ICV_STATUS_MISMATCH:
877 case PEAK_ICV_STATUS_NULL_POINTER:
878 case PEAK_ICV_STATUS_NOT_SUPPORTED:
879 case PEAK_ICV_STATUS_NOT_POSSIBLE:
881 case PEAK_ICV_STATUS_CORRUPTED:
883 case PEAK_ICV_STATUS_OUT_OF_RANGE:
885 case PEAK_ICV_STATUS_INTERNAL_ERROR:
922 return m_finalConversion->GetOutputPixelFormat();
936 else if (isMonoFormat)
977 m_monoConversion->SetEnabled(isMonoFormat);
979 m_finalConversion->SetOutputPixelFormat(format);
982 m_unpack->SetTargetBitDepth(bitDepth);
983 m_debayer->SetTargetBitDepth(bitDepth);
988 m_processingPolicy = policy;
990 m_unpack->SetProcessingPolicy(m_processingPolicy);
991 m_debayer->SetProcessingPolicy(m_processingPolicy);
996 if (m_autoFeatureModule !=
nullptr)
998 m_autoFeatureModule->SetGainModule(
nullptr);
1001 m_autoFeatureModule = autoFeatureModule;
1003 m_colorCorrection->SetAutoFeatureModule(m_autoFeatureModule);
1005 if (m_autoFeatureModule !=
nullptr)
1007 m_autoFeatureModule->SetGainModule(m_gain);
1011inline std::string DefaultPipeline::GetCurrentIsoUtcTime()
1013 const auto now = std::chrono::system_clock::now();
1014 const std::time_t nowC = std::chrono::system_clock::to_time_t(now);
1017#if defined(_WIN32) || defined(_WIN64)
1018 gmtime_s(&tm, &nowC);
1020 gmtime_r(&nowC, &tm);
1023 std::ostringstream oss;
1024 oss << std::put_time(&tm,
"%Y-%m-%dT%H:%M:%SZ");
1028inline std::vector<std::shared_ptr<modules::IModule>> DefaultPipeline::GetModules()
const
1030 if (m_autoFeatureModule ==
nullptr)
1032 return { m_unpack, m_hotpixel, m_binning, m_decimation, m_transformation, m_gain, m_debayer, m_colorCorrection, m_monoConversion,
1033 m_sharpening, m_toneCurveCorrection, m_finalConversion };
1036 return { m_unpack, m_hotpixel, m_binning, m_decimation, m_transformation, m_gain, m_debayer, m_colorCorrection, m_autoFeatureModule,
1037 m_monoConversion, m_sharpening, m_toneCurveCorrection, m_finalConversion };
1040inline std::vector<std::shared_ptr<features::IFeature>> DefaultPipeline::GetFeatures()
const
1042 return { m_hotpixelFeature, m_binningFeature, m_decimationFeature, m_mirrorFeature, m_rotationFeature, m_gainFeature,
1043 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 input data or a file is malformed, unreadable, or otherwise corrupted.
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.
The base class for all exceptions thrown by the IDS peak ICV library.
Thrown when a file input/output operation fails.
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.
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.
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.
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.
@ Bypass
Do not convert images.
@ BayerOnly
Convert only Bayer-pattern images.
@ BayerAndMono
Convert both Bayer-pattern and monochrome images.
@ 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.