16#include <peak_icv_c/types/peak_icv_buffer.h>
22# include <peak_ipl/types/peak_ipl_pixel_format.hpp>
33 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_CreateFromFile(&handle, path.c_str());
42 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_CreateFromFileWithPixelFormat(
50 peak_icv_image_info imageInfo{};
52 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_GetInfo(handle, &imageInfo,
sizeof(imageInfo));
62 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_Create(
74 { size.
GetWidth(), size.
GetHeight() }, bufferSize,
const_cast<uint8_t*
>(buffer) };
75 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_CreateFromImageInfo(&handle, info,
sizeof(info));
82 const auto imageViewSize = imageView.
GetSize();
88 if (lineStartOffset == 0 && validBytesPerLine == imageView.
GetBytesPerLine())
93 Image imageWithoutBlackColumns(imageView.
GetPixelFormat(), imageViewSize);
94 auto imageHandleWithoutBlackColumns = peak::common::detail::BackendAccessor<Image>::BackendHandle(imageWithoutBlackColumns);
97 return PEAK_ICV_C_ABI_PREFIX peak_icv_Buffer_CutBytes(imageView.
GetData(), lineStartOffset, imageView.
GetBytesPerLine(),
98 validBytesPerLine, imageViewSize.GetHeight(), imageHandleWithoutBlackColumns);
101 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_IncreaseUseCount(imageHandleWithoutBlackColumns);
103 return imageHandleWithoutBlackColumns;
114 captureInformationC.region_of_interest.width, captureInformationC.region_of_interest.height });
116 if (captureInformationC.exposure_time != 0)
121 const double* exposureSequenceBegin = &captureInformationC.exposure_time_a;
122 const double* firstZeroExposure = std::find(exposureSequenceBegin, exposureSequenceBegin + 4, 0.0);
123 if (firstZeroExposure != exposureSequenceBegin)
126 std::vector<double>(exposureSequenceBegin, firstZeroExposure));
129 if (captureInformationC.gain != 0)
134 const double* gainSequenceBegin = &captureInformationC.gain_a;
135 const double* firstZeroGain = std::find(gainSequenceBegin, gainSequenceBegin + 4, 0.0);
136 if (firstZeroGain != gainSequenceBegin)
145 : m_imageHandle{ handle }
146 , m_size{ info.size.width, info.size.height }
147 , m_buffer{ info.buffer }
152inline Image::Image(
const peak::ipl::Image& image)
154 static_cast<peak_common_pixel_format>(image.PixelFormat().PixelFormatName())),
155 peak::common::Size{ static_cast<uint32_t>(image.Width()), static_cast<uint32_t>(image.Height()) }, image.Data(),
158 peak_icv_capture_information captureInformationC{};
159 captureInformationC.binning_factor = { 1, 1 };
160 captureInformationC.relative_timestamp = image.Timestamp();
161 detail::ExecuteAndMapReturnCodes([&] {
162 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_SetCaptureInformation(m_imageHandle, captureInformationC,
sizeof(captureInformationC));
165 m_metaData = std::make_unique<peak::common::Metadata>(
172 :
Image(CreateFromImageView(imageView))
179 :
Image{ CreateFromFile(path) }
183 :
Image{ CreateFromFile(path, name) }
187 :
Image{ CreateFromBuffer(pixelFormat, imageSize, buffer, bufferSize),
193 :
Image{ CreateFromSize(pixelFormat, imageSize) }
197 :
Image{ imageHandle, CreateFromHandle(imageHandle) }
201 :
Image{ other.m_imageHandle, CreateFromHandle(other.m_imageHandle) }
203 if (other.m_metaData)
205 m_metaData = std::make_unique<peak::common::Metadata>(*other.m_metaData);
208 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_IncreaseUseCount(other.m_imageHandle);
211 m_image = other.m_image;
216 :
Image{ other.m_imageHandle, CreateFromHandle(other.m_imageHandle) }
218 m_metaData = std::move(other.m_metaData);
220 m_image = std::move(other.m_image);
222 other.m_imageHandle =
nullptr;
227 if (this->m_imageHandle != other.m_imageHandle)
232 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_Destroy(m_imageHandle);
237 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_IncreaseUseCount(other.m_imageHandle);
239 m_imageHandle = other.m_imageHandle;
240 m_size = other.m_size;
241 m_pixelFormatInfo = other.m_pixelFormatInfo;
242 m_buffer = other.m_buffer;
243 m_metaData = std::make_unique<peak::common::Metadata>(other.
GetMetadata());
245 m_image = other.m_image;
254 if (this->m_imageHandle != other.m_imageHandle)
259 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_Destroy(m_imageHandle);
263 m_imageHandle = std::exchange(other.m_imageHandle,
nullptr);
264 m_size = other.m_size;
265 m_pixelFormatInfo = other.m_pixelFormatInfo;
266 m_buffer = std::exchange(other.m_buffer,
nullptr);
267 m_metaData = std::exchange(other.m_metaData,
nullptr);
269 m_image = std::move(other.m_image);
278 if (m_imageHandle !=
nullptr)
280 std::ignore = PEAK_ICV_C_ABI_PREFIX peak_icv_Image_Destroy(m_imageHandle);
290 if (rhs.
GetSize() != this->GetSize())
298 if (rhs.
GetRegion() != this->GetRegion())
304 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_Compare(
305 m_imageHandle, peak::common::detail::BackendAccessor<Image>::BackendHandle(rhs), &isSame);
344 return m_imageHandle;
353inline peak::ipl::Image Image::GetIPLImage()
const
355 if (!m_image.Empty())
360 constexpr std::array<peak::ipl::PixelFormatName, 59> possibleValues{ peak::ipl::PixelFormatName::BayerGR8,
361 peak::ipl::PixelFormatName::BayerGR10, peak::ipl::PixelFormatName::BayerGR12, peak::ipl::PixelFormatName::BayerRG8,
362 peak::ipl::PixelFormatName::BayerRG10, peak::ipl::PixelFormatName::BayerRG12, peak::ipl::PixelFormatName::BayerGB8,
363 peak::ipl::PixelFormatName::BayerGB10, peak::ipl::PixelFormatName::BayerGB12, peak::ipl::PixelFormatName::BayerBG8,
364 peak::ipl::PixelFormatName::BayerBG10, peak::ipl::PixelFormatName::BayerBG12, peak::ipl::PixelFormatName::Mono8,
365 peak::ipl::PixelFormatName::Mono10, peak::ipl::PixelFormatName::Mono12, peak::ipl::PixelFormatName::Mono16,
366 peak::ipl::PixelFormatName::Confidence8, peak::ipl::PixelFormatName::Confidence16,
367 peak::ipl::PixelFormatName::Coord3D_C8, peak::ipl::PixelFormatName::Coord3D_C16,
368 peak::ipl::PixelFormatName::Coord3D_C32f, peak::ipl::PixelFormatName::Coord3D_ABC32f,
369 peak::ipl::PixelFormatName::YUV420_8_YY_UV_SemiplanarIDS, peak::ipl::PixelFormatName::YUV420_8_YY_VU_SemiplanarIDS,
370 peak::ipl::PixelFormatName::YUV422_8_UYVY, peak::ipl::PixelFormatName::RGB8, peak::ipl::PixelFormatName::RGB10,
371 peak::ipl::PixelFormatName::RGB12, peak::ipl::PixelFormatName::BGR8, peak::ipl::PixelFormatName::BGR10,
372 peak::ipl::PixelFormatName::BGR12, peak::ipl::PixelFormatName::RGBa8, peak::ipl::PixelFormatName::RGBa10,
373 peak::ipl::PixelFormatName::RGBa12, peak::ipl::PixelFormatName::BGRa8, peak::ipl::PixelFormatName::BGRa10,
374 peak::ipl::PixelFormatName::BGRa12, peak::ipl::PixelFormatName::BayerBG10p, peak::ipl::PixelFormatName::BayerBG12p,
375 peak::ipl::PixelFormatName::BayerGB10p, peak::ipl::PixelFormatName::BayerGB12p, peak::ipl::PixelFormatName::BayerGR10p,
376 peak::ipl::PixelFormatName::BayerGR12p, peak::ipl::PixelFormatName::BayerRG10p, peak::ipl::PixelFormatName::BayerRG12p,
377 peak::ipl::PixelFormatName::Mono10p, peak::ipl::PixelFormatName::Mono12p, peak::ipl::PixelFormatName::RGB10p32,
378 peak::ipl::PixelFormatName::BGR10p32, peak::ipl::PixelFormatName::BayerRG10g40IDS,
379 peak::ipl::PixelFormatName::BayerGB10g40IDS, peak::ipl::PixelFormatName::BayerGR10g40IDS,
380 peak::ipl::PixelFormatName::BayerBG10g40IDS, peak::ipl::PixelFormatName::BayerRG12g24IDS,
381 peak::ipl::PixelFormatName::BayerGB12g24IDS, peak::ipl::PixelFormatName::BayerGR12g24IDS,
382 peak::ipl::PixelFormatName::BayerBG12g24IDS, peak::ipl::PixelFormatName::Mono10g40IDS,
383 peak::ipl::PixelFormatName::Mono12g24IDS };
385 const auto currentPixelFormat = m_pixelFormatInfo.
GetPixelFormat();
386 const auto foundIt = std::find_if(possibleValues.begin(), possibleValues.end(), [&](
const peak::ipl::PixelFormatName& name) {
387 return static_cast<std::underlying_type<peak::ipl::PixelFormatName>::type>(name)
388 == static_cast<std::underlying_type<peak::ipl::PixelFormatName>::type>(currentPixelFormat);
390 if (foundIt == possibleValues.end())
393 +
" has no equivalent in the ids_peak_ipl. As a result, it cannot be converted to an ids_peak_ipl Image!");
396 m_image = peak::ipl::Image{
static_cast<peak::ipl::PixelFormatName
>(currentPixelFormat), m_buffer,
408 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_GetRegion(
409 m_imageHandle, peak::common::detail::BackendAccessor<Region>::BackendHandleAddress(region));
416 const peak_icv_region_handle regionHandle = peak::common::detail::BackendAccessor<Region>::BackendHandle(region);
419 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_SetRegion(m_imageHandle, regionHandle);
426 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_ResetRegion(m_imageHandle);
433 const auto imageHandle = peak::common::detail::BackendAccessor<Image>::BackendHandle(outputImage);
435 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_ConvertPixelFormat(
444 const auto imageHandle = peak::common::detail::BackendAccessor<Image>::BackendHandle(outputImage);
446 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_ConvertPixelFormatWithFactor(
457 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_SetCaptureInformation(m_imageHandle, captureInformationC,
sizeof(captureInformationC));
460 m_metaData = std::make_unique<peak::common::Metadata>(AddCaptureInformationDataToMetadata(captureInformationC, metadata));
465 peak_icv_capture_information captureInformationC;
467 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_GetCaptureInformation(
468 m_imageHandle, &captureInformationC,
sizeof(captureInformationC));
473 m_metaData = std::make_unique<peak::common::Metadata>(
478 m_metaData = std::make_unique<peak::common::Metadata>(AddCaptureInformationDataToMetadata(captureInformationC, *m_metaData));
490 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_Subtract(GetHandle(), subtrahend.GetHandle(), difference.GetHandle());
507 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_Crop(GetHandle(), croppedImage.GetHandle(),
508 peak::common::detail::BackendAccessor<peak::common::Rectangle>::CreateCType(rect));
517 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_Scale(
518 GetHandle(), scaledImage.GetHandle(),
static_cast<peak_icv_interpolation
>(interpolation));
525 size_t numOutputImages{};
527 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_Deinterleave_GetOutputImageCount(
530 peak_common_pixel_format outputPixelFormat;
532 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_Deinterleave_GetOutputPixelFormat(
535 peak_common_size outputSize{};
538 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_Deinterleave_GetOutputImageSize(
542 std::vector<Image> deinterleavedImages;
543 deinterleavedImages.reserve(numOutputImages);
544 std::vector<peak_icv_image_handle> deinterleavedImageHandles;
545 deinterleavedImages.reserve(numOutputImages);
546 for (
size_t i = 0; i < numOutputImages; ++i)
549 { outputSize.width, outputSize.height } };
550 deinterleavedImageHandles.emplace_back(peak::common::detail::BackendAccessor<Image>::BackendHandle(tmpImage));
551 deinterleavedImages.emplace_back(std::move(tmpImage));
555 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_Deinterleave(
556 GetHandle(), deinterleavedImageHandles.data(), deinterleavedImages.size());
559 return deinterleavedImages;
563inline Image::operator peak::ipl::Image()
const
565 return GetIPLImage();
Interface for viewing image pixel data from arbitrary sources.
virtual peak::common::PixelFormat GetPixelFormat() const =0
Returns the pixel format used by the image.
virtual std::size_t GetLineStartOffset() const =0
Returns the byte offset to the first pixel of a line.
virtual size_t GetBytesPerLine() const =0
Returns the number of bytes in a single image row.
virtual std::size_t GetSizeInBytes() const =0
Returns the total size of the image data in bytes.
virtual std::shared_ptr< peak::common::Metadata > GetMetadata()=0
Returns the metadata object which can be used to retrieve or set metadata belonging to the image.
virtual const uint8_t * GetData() const =0
Returns a pointer to the start of the first line that contains valid image data (read-only).
virtual Size GetSize() const =0
Returns the overall size of the image (width × height).
A generic rectangle defined by a point and a size.
constexpr SizeType GetWidth() const
Returns the width of the rectangle.
constexpr SizeType GetHeight() const
Returns the height of the rectangle.
Represents a two-dimensional size with non-negative width and height.
constexpr T GetWidth() const
Returns the width.
constexpr T GetHeight() const
Returns the height.
For detailed information about the use of ids_peak_icv Image refer to the Image Guide.
peak::common::Size GetSize() const
Provides the size of the image in pixels.
void ResetRegion() const
Resets the region on the image to the complete image.
Image operator-(const Image &subtrahend) const
Subtracts the specified subtrahend image pixelwise from the current image and returns the resulting i...
Image & operator=(const Image &other)
uint8_t * GetData() const
Provides a pointer to the image data buffer.
Image Subtract(const Image &subtrahend) const
Subtracts the specified subtrahend image pixelwise from the current image and returns the resulting i...
Region GetRegion() const
Provides the region of the image.
Image(const peak::common::IImageView &imageView)
Constructs an Image from an IImageView Instance.
peak::common::PixelFormat GetPixelFormat() const
Provides the pixel format of the image.
Image Crop(const peak::common::Rectangle &rect) const
Crops the image to the given rectangle.
peak::common::Metadata GetMetadata() const
Returns the Metadata of an image which contains information about the image capture information.
peak::icv::Image ConvertPixelFormat(peak::common::PixelFormat pixelFormat) const
Converts the image to a different pixel format.
void SetMetadata(const peak::common::Metadata &metadata)
Updates the Metadata of an image which is used to store and manage capture information.
Image Copy() const
Creates a deep copy of the current Image.
peak::icv::Image ConvertPixelFormatWithFactor(peak::common::PixelFormat pixelFormat, const double factor) const
Converts an image into another pixel format with a factor multiplied to every pixel.
Image Scale(const peak::common::Size &targetImageSize, const Interpolation &interpolation=Interpolation::NearestNeighbor) const
Returns an image scaled to the given image size.
size_t GetSizeInBytes() const
Provides the size of the image data in bytes.
std::vector< Image > Deinterleave() const
Splits an image with an interleaved pixel format into individual images.
bool operator==(const Image &rhs) const
size_t GetBytesPerLine() const
Computes the number of bytes required to store one line of pixel data (no padding).
void SetRegion(const Region ®ion) const
Updates the region on the image.
Occurs when a requested operation is not implemented or supported (e.g., exporting to an unsupported ...
Represents a region defined by a set of points in the image plane.
PixelFormat
Enum listing all supported pixel formats and their internal IDs.
constexpr peak_common_pixel_format CppPixelFormatToCPixelFormat(PixelFormat pixelFormat) noexcept
constexpr PixelFormat CPixelFormatToCppPixelFormat(peak_common_pixel_format pixelFormat) noexcept
@ Roi
Region of interest applied to the image.
@ DeviceGain
Device gain the image was captured with.
@ DeviceExposureTime
Device exposure time the image was captured with.
@ BinningHorizontal
Horizontal pixel binning factor.
@ DeviceExposureTimeSequence
Device exposure time sequence the image was captured with.
@ DeviceTimestamp
Device-provided image acquisition timestamp in nanoseconds.
@ DeviceGainSequence
Device gain sequence the image was captured with.
@ BinningVertical
Vertical pixel binning factor.
peak_icv_capture_information CreateCCaptureInformationFromMetadata(const peak::common::Metadata &metadata)
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
peak::common::detail::c_type_of_t< Type > * handle_of_t
peak_icv_image * peak_icv_image_handle