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]
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 steady_clock / time.monotonic

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)None
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)None

Specifies frame height

Parameter height:

frame height

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

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

Parameter instance:

Instance number

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

Specifies sequence number

Parameter seq:

Sequence number

setSize(*args, **kwargs)

Overloaded function.

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

Specifies frame size

Parameter height:

frame height

Parameter width:

frame width

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

Specifies frame size

Parameter size:

frame size

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

Specifies current timestamp, related to steady_clock / time.monotonic

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

Specifies frame type, RGB, BGR, …

Parameter type:

Type of image

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

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 steady_clock / time.monotonic

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

unsigned int 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

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

Specifies current timestamp, related to steady_clock / time.monotonic

void setInstanceNum(unsigned int instance)

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

Parameters
  • instance: Instance number

void setCategory(unsigned int category)

Parameters
  • category: Image category

void setSequenceNum(unsigned int seq)

Specifies sequence number

Parameters
  • seq: Sequence number

void setWidth(unsigned int width)

Specifies frame width

Parameters
  • width: frame width

void setHeight(unsigned int height)

Specifies frame height

Parameters
  • height: frame height

void setSize(unsigned int width, unsigned int height)

Specifies frame size

Parameters
  • height: frame height

  • width: frame width

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

Specifies frame size

Parameters
  • size: frame size

void setType(Type type)

Specifies frame type, RGB, BGR, …

Parameters
  • type: Type of image

void 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.