21# include <peak_ipl/types/peak_ipl_pixel_format.hpp>
32 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_CreateFromFile(&handle, path.c_str());
41 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_CreateFromFileWithPixelFormat(
49 peak_icv_image_info imageInfo{};
51 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_GetInfo(handle, &imageInfo,
sizeof(imageInfo));
61 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_Create(
73 { size.
GetWidth(), size.
GetHeight() }, bufferSize,
const_cast<uint8_t*
>(buffer) };
74 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_CreateFromImageInfo(&handle, info,
sizeof(info));
87 captureInformationC.region_of_interest.width, captureInformationC.region_of_interest.height });
93 : m_imageHandle{ handle }
94 , m_size{ info.size.width, info.size.height }
95 , m_buffer{ info.buffer }
100inline Image::Image(
const peak::ipl::Image& image)
102 static_cast<peak_common_pixel_format>(image.PixelFormat().PixelFormatName())),
103 peak::common::Size{ static_cast<uint32_t>(image.Width()), static_cast<uint32_t>(image.Height()) }, image.Data(),
106 peak_icv_capture_information captureInformationC{ { 1, 1 }, image.Timestamp(), {}, {}, {} };
107 detail::ExecuteAndMapReturnCodes([&] {
108 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_SetCaptureInformation(m_imageHandle, captureInformationC,
sizeof(captureInformationC));
111 m_metaData = std::make_unique<peak::common::Metadata>(
118 :
Image(CreateFromBuffer(imageView.GetPixelFormat(), imageView.GetSize(), imageView.GetData(), imageView.GetSizeInBytes()))
125 :
Image{ CreateFromFile(path) }
129 :
Image{ CreateFromFile(path, name) }
133 :
Image{ CreateFromBuffer(pixelFormat, imageSize, buffer, bufferSize),
139 :
Image{ CreateFromSize(pixelFormat, imageSize) }
143 :
Image{ imageHandle, CreateFromHandle(imageHandle) }
147 :
Image{ other.m_imageHandle, CreateFromHandle(other.m_imageHandle) }
149 if (other.m_metaData)
151 m_metaData = std::make_unique<peak::common::Metadata>(*other.m_metaData);
154 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_IncreaseUseCount(other.m_imageHandle);
157 m_image = other.m_image;
162 :
Image{ other.m_imageHandle, CreateFromHandle(other.m_imageHandle) }
164 m_metaData = std::move(other.m_metaData);
166 m_image = std::move(other.m_image);
168 other.m_imageHandle =
nullptr;
173 if (this->m_imageHandle != other.m_imageHandle)
178 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_Destroy(m_imageHandle);
183 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_IncreaseUseCount(other.m_imageHandle);
185 m_imageHandle = other.m_imageHandle;
186 m_size = other.m_size;
187 m_pixelFormatInfo = other.m_pixelFormatInfo;
188 m_buffer = other.m_buffer;
189 m_metaData = std::make_unique<peak::common::Metadata>(other.
GetMetadata());
191 m_image = other.m_image;
200 if (this->m_imageHandle != other.m_imageHandle)
205 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_Destroy(m_imageHandle);
209 m_imageHandle = std::exchange(other.m_imageHandle,
nullptr);
210 m_size = other.m_size;
211 m_pixelFormatInfo = other.m_pixelFormatInfo;
212 m_buffer = std::exchange(other.m_buffer,
nullptr);
213 m_metaData = std::exchange(other.m_metaData,
nullptr);
215 m_image = std::move(other.m_image);
224 if (m_imageHandle !=
nullptr)
226 std::ignore = PEAK_ICV_C_ABI_PREFIX peak_icv_Image_Destroy(m_imageHandle);
236 if (rhs.
GetSize() != this->GetSize())
244 if (rhs.
GetRegion() != this->GetRegion())
250 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_Compare(
251 m_imageHandle, peak::common::detail::BackendAccessor<Image>::BackendHandle(rhs), &isSame);
290 return m_imageHandle;
299inline peak::ipl::Image Image::GetIPLImage()
const
301 if (!m_image.Empty())
306 constexpr std::array<peak::ipl::PixelFormatName, 59> possibleValues{ peak::ipl::PixelFormatName::BayerGR8,
307 peak::ipl::PixelFormatName::BayerGR10, peak::ipl::PixelFormatName::BayerGR12, peak::ipl::PixelFormatName::BayerRG8,
308 peak::ipl::PixelFormatName::BayerRG10, peak::ipl::PixelFormatName::BayerRG12, peak::ipl::PixelFormatName::BayerGB8,
309 peak::ipl::PixelFormatName::BayerGB10, peak::ipl::PixelFormatName::BayerGB12, peak::ipl::PixelFormatName::BayerBG8,
310 peak::ipl::PixelFormatName::BayerBG10, peak::ipl::PixelFormatName::BayerBG12, peak::ipl::PixelFormatName::Mono8,
311 peak::ipl::PixelFormatName::Mono10, peak::ipl::PixelFormatName::Mono12, peak::ipl::PixelFormatName::Mono16,
312 peak::ipl::PixelFormatName::Confidence8, peak::ipl::PixelFormatName::Confidence16,
313 peak::ipl::PixelFormatName::Coord3D_C8, peak::ipl::PixelFormatName::Coord3D_C16,
314 peak::ipl::PixelFormatName::Coord3D_C32f, peak::ipl::PixelFormatName::Coord3D_ABC32f,
315 peak::ipl::PixelFormatName::YUV420_8_YY_UV_SemiplanarIDS, peak::ipl::PixelFormatName::YUV420_8_YY_VU_SemiplanarIDS,
316 peak::ipl::PixelFormatName::YUV422_8_UYVY, peak::ipl::PixelFormatName::RGB8, peak::ipl::PixelFormatName::RGB10,
317 peak::ipl::PixelFormatName::RGB12, peak::ipl::PixelFormatName::BGR8, peak::ipl::PixelFormatName::BGR10,
318 peak::ipl::PixelFormatName::BGR12, peak::ipl::PixelFormatName::RGBa8, peak::ipl::PixelFormatName::RGBa10,
319 peak::ipl::PixelFormatName::RGBa12, peak::ipl::PixelFormatName::BGRa8, peak::ipl::PixelFormatName::BGRa10,
320 peak::ipl::PixelFormatName::BGRa12, peak::ipl::PixelFormatName::BayerBG10p, peak::ipl::PixelFormatName::BayerBG12p,
321 peak::ipl::PixelFormatName::BayerGB10p, peak::ipl::PixelFormatName::BayerGB12p, peak::ipl::PixelFormatName::BayerGR10p,
322 peak::ipl::PixelFormatName::BayerGR12p, peak::ipl::PixelFormatName::BayerRG10p, peak::ipl::PixelFormatName::BayerRG12p,
323 peak::ipl::PixelFormatName::Mono10p, peak::ipl::PixelFormatName::Mono12p, peak::ipl::PixelFormatName::RGB10p32,
324 peak::ipl::PixelFormatName::BGR10p32, peak::ipl::PixelFormatName::BayerRG10g40IDS,
325 peak::ipl::PixelFormatName::BayerGB10g40IDS, peak::ipl::PixelFormatName::BayerGR10g40IDS,
326 peak::ipl::PixelFormatName::BayerBG10g40IDS, peak::ipl::PixelFormatName::BayerRG12g24IDS,
327 peak::ipl::PixelFormatName::BayerGB12g24IDS, peak::ipl::PixelFormatName::BayerGR12g24IDS,
328 peak::ipl::PixelFormatName::BayerBG12g24IDS, peak::ipl::PixelFormatName::Mono10g40IDS,
329 peak::ipl::PixelFormatName::Mono12g24IDS };
331 const auto currentPixelFormat = m_pixelFormatInfo.
GetPixelFormat();
332 const auto foundIt = std::find_if(possibleValues.begin(), possibleValues.end(), [&](
const peak::ipl::PixelFormatName& name) {
333 return static_cast<std::underlying_type<peak::ipl::PixelFormatName>::type>(name)
334 == static_cast<std::underlying_type<peak::ipl::PixelFormatName>::type>(currentPixelFormat);
336 if (foundIt == possibleValues.end())
339 +
" has no equivalent in the ids_peak_ipl. As a result, it cannot be converted to an ids_peak_ipl Image!");
342 m_image = peak::ipl::Image{
static_cast<peak::ipl::PixelFormatName
>(currentPixelFormat), m_buffer,
354 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_GetRegion(
355 m_imageHandle, peak::common::detail::BackendAccessor<Region>::BackendHandleAddress(region));
362 const peak_icv_region_handle regionHandle = peak::common::detail::BackendAccessor<Region>::BackendHandle(region);
365 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_SetRegion(m_imageHandle, regionHandle);
372 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_ResetRegion(m_imageHandle);
379 const auto imageHandle = peak::common::detail::BackendAccessor<Image>::BackendHandle(outputImage);
381 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_ConvertPixelFormat(
390 const auto imageHandle = peak::common::detail::BackendAccessor<Image>::BackendHandle(outputImage);
392 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_ConvertPixelFormatWithFactor(
403 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_SetCaptureInformation(m_imageHandle, captureInformationC,
sizeof(captureInformationC));
406 m_metaData = std::make_unique<peak::common::Metadata>(AddCaptureInformationDataToMetadata(captureInformationC, metadata));
411 peak_icv_capture_information captureInformationC;
413 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_GetCaptureInformation(
414 m_imageHandle, &captureInformationC,
sizeof(captureInformationC));
419 m_metaData = std::make_unique<peak::common::Metadata>(
424 m_metaData = std::make_unique<peak::common::Metadata>(AddCaptureInformationDataToMetadata(captureInformationC, *m_metaData));
436 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_Subtract(GetHandle(), subtrahend.GetHandle(), difference.GetHandle());
453 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_Crop(GetHandle(), croppedImage.GetHandle(),
454 peak::common::detail::BackendAccessor<peak::common::Rectangle>::CreateCType(rect));
463 return PEAK_ICV_C_ABI_PREFIX peak_icv_Image_Scale(
464 GetHandle(), scaledImage.GetHandle(),
static_cast<peak_icv_interpolation
>(interpolation));
470inline Image::operator peak::ipl::Image()
const
472 return GetIPLImage();
Interface for viewing image pixel data from arbitrary sources.
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.
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.
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.
Thrown when a requested operation is not implemented or supported.
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.
@ DeviceExposureTime
Device exposure time the image was captured with.
@ BinningHorizontal
Horizontal pixel binning factor.
@ DeviceTimestamp
Device-provided image acquisition timestamp in nanoseconds.
@ 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