ImgFrame

These are all the images (regardless of their encoding/format), as well as the depth/disparity “image”. ColorCamera and MonoCamera are the source of the image frame messages.

Examples of functionality

Reference

class depthai.ImgFrame

ImgFrame message. Carries image data and metadata.

class Type

Members:

YUV422i

YUV444p

YUV420p

YUV422p

YUV400p

RGBA8888

RGB161616

RGB888p

BGR888p

RGB888i

BGR888i

RGBF16F16F16p

BGRF16F16F16p

RGBF16F16F16i

BGRF16F16F16i

GRAY8

GRAYF16

LUT2

LUT4

LUT16

RAW16

RAW14

RAW12

RAW10

RAW8

PACK10

PACK12

YUV444i

NV12

NV21

BITSTREAM

HDR

NONE

property name
getCategory(self: depthai.ImgFrame)int

Retrieves image category

getCvFrame(self: object)object

Returns BGR or grayscale frame compatible with use in other opencv functions

getData(self: object) → numpy.ndarray[numpy.uint8]

Get non-owning reference to internal buffer

Returns

Reference to internal buffer

getFrame(self: object, copy: bool = False) → numpy.ndarray

Returns numpy array with shape as specified by width, height and type

getHeight(self: depthai.ImgFrame)int

Retrieves image height in pixels

getInstanceNum(self: depthai.ImgFrame)int

Retrieves instance number

getRaw(self: depthai.ADatatype)depthai.RawBuffer
getSequenceNum(self: depthai.ImgFrame)int

Retrieves image sequence number

getTimestamp(self: depthai.ImgFrame)datetime.timedelta

Retrieves image timestamp related to dai::Clock::now()

getTimestampDevice(self: depthai.ImgFrame)datetime.timedelta

Retrieves image timestamp directly captured from device’s monotonic clock, not synchronized to host time. Used mostly for debugging

getType(self: depthai.ImgFrame)depthai.RawImgFrame.Type

Retrieves image type

getWidth(self: depthai.ImgFrame)int

Retrieves image width in pixels

setCategory(self: depthai.ImgFrame, category: int)depthai.ImgFrame
Parameter category:

Image category

setData(*args, **kwargs)

Overloaded function.

  1. setData(self: depthai.Buffer, arg0: List[int]) -> None

Parameter data:

Copies data to internal buffer

  1. setData(self: depthai.Buffer, arg0: numpy.ndarray[numpy.uint8]) -> None

Parameter data:

Copies data to internal buffer

setFrame(self: depthai.ImgFrame, array: numpy.ndarray)None

Copies array bytes to ImgFrame buffer

setHeight(self: depthai.ImgFrame, height: int)depthai.ImgFrame

Specifies frame height

Parameter height:

frame height

setInstanceNum(self: depthai.ImgFrame, instance: int)depthai.ImgFrame

Instance number relates to the origin of the frame (which camera)

Parameter instance:

Instance number

setSequenceNum(self: depthai.ImgFrame, seq: int)depthai.ImgFrame

Specifies sequence number

Parameter seq:

Sequence number

setSize(*args, **kwargs)

Overloaded function.

  1. setSize(self: depthai.ImgFrame, width: int, height: int) -> depthai.ImgFrame

Specifies frame size

Parameter height:

frame height

Parameter width:

frame width

  1. setSize(self: depthai.ImgFrame, sizer: Tuple[int, int]) -> depthai.ImgFrame

Specifies frame size

Parameter size:

frame size

setTimestamp(self: depthai.ImgFrame, timestamp: datetime.timedelta)depthai.ImgFrame

Retrieves image timestamp related to dai::Clock::now()

setTimestampDevice(self: depthai.ImgFrame, arg0: datetime.timedelta)depthai.ImgFrame

Sets image timestamp related to dai::Clock::now()

setType(self: depthai.ImgFrame, type: depthai.RawImgFrame.Type)depthai.ImgFrame

Specifies frame type, RGB, BGR, …

Parameter type:

Type of image

setWidth(self: depthai.ImgFrame, width: int)depthai.ImgFrame

Specifies frame width

Parameter width:

frame width

class dai::ImgFrame : public dai::Buffer

ImgFrame message. Carries image data and metadata.

Public Types

using Type = RawImgFrame::Type
using Specs = RawImgFrame::Specs

Public Functions

ImgFrame()

Construct ImgFrame message. Timestamp is set to now

ImgFrame(std::shared_ptr<RawImgFrame> ptr)
~ImgFrame() = default
std::chrono::time_point<std::chrono::steady_clock, std::chrono::steady_clock::duration> getTimestamp() const

Retrieves image timestamp related to dai::Clock::now()

std::chrono::time_point<std::chrono::steady_clock, std::chrono::steady_clock::duration> getTimestampDevice() const

Retrieves image timestamp directly captured from device’s monotonic clock, not synchronized to host time. Used mostly for debugging

unsigned int getInstanceNum() const

Retrieves instance number

unsigned int getCategory() const

Retrieves image category

int64_t getSequenceNum() const

Retrieves image sequence number

unsigned int getWidth() const

Retrieves image width in pixels

unsigned int getHeight() const

Retrieves image height in pixels

Type getType() const

Retrieves image type

ImgFrame &setTimestamp(std::chrono::time_point<std::chrono::steady_clock, std::chrono::steady_clock::duration> timestamp)

Retrieves image timestamp related to dai::Clock::now()

ImgFrame &setTimestampDevice(std::chrono::time_point<std::chrono::steady_clock, std::chrono::steady_clock::duration> timestamp)

Sets image timestamp related to dai::Clock::now()

ImgFrame &setInstanceNum(unsigned int instance)

Instance number relates to the origin of the frame (which camera)

Parameters
  • instance: Instance number

ImgFrame &setCategory(unsigned int category)

Parameters
  • category: Image category

ImgFrame &setSequenceNum(int64_t seq)

Specifies sequence number

Parameters
  • seq: Sequence number

ImgFrame &setWidth(unsigned int width)

Specifies frame width

Parameters
  • width: frame width

ImgFrame &setHeight(unsigned int height)

Specifies frame height

Parameters
  • height: frame height

ImgFrame &setSize(unsigned int width, unsigned int height)

Specifies frame size

Parameters
  • height: frame height

  • width: frame width

ImgFrame &setSize(std::tuple<unsigned int, unsigned int> size)

Specifies frame size

Parameters
  • size: frame size

ImgFrame &setType(Type type)

Specifies frame type, RGB, BGR, …

Parameters
  • type: Type of image

ImgFrame &setFrame(cv::Mat frame)

Copies cv::Mat data to

ImgFrame buffer
Note

This API only available if OpenCV support is enabled

Parameters
  • frame: Input cv::Mat frame from which to copy the data

cv::Mat getFrame(bool copy = false)

Retrieves data as cv::Mat with specified width, height and type

Note

This API only available if OpenCV support is enabled

Return

cv::Mat with corresponding to ImgFrame parameters

Parameters
  • copy: If false only a reference to data is made, otherwise a copy

cv::Mat getCvFrame()

Retrieves cv::Mat suitable for use in common opencv functions.

ImgFrame is converted to color BGR interleaved or grayscale depending on type.
Note

This API only available if OpenCV support is enabled

A copy is always made

Return

cv::Mat for use in opencv functions

Private Functions

std::shared_ptr<RawBuffer> serialize() const override

Private Members

RawImgFrame &img

Got questions?

We’re always happy to help with code or other questions you might have.