Data Package#

class DataPack#

DataPack handles the operations of a data package.

Public Functions

explicit DataPack(const std::string &path, bool create_if_not_exist = false, bool read_only = false)#

Open a data package at the given path. If create_if_not_exist is set, will create a new data package if the file does not exist.

Parameters:
  • path – path to the data package. Must ends with “.vfpack”.

  • create_if_not_exist – if set, will create a new data package when file does not exist, otherwise exception will be thrown

  • read_only – if set, datapack will be opened in read-only mode. All modifications to a read-only datapack throws. Closing a read-only datapack will be faster.

Throws:
void close(util::IProgressCallback *progress_callback = nullptr)#

close the data package, store all changes to disk

Attention

after close, all actions on this data package will throw

Parameters:

progress_callback – a callback to report the progress of the operation, nullptr if not needed

int64_t create_time() const#

get the time of creation of the data package

Returns:

int64_t the time of creation

const std::string &sdk_version() const#

get the SDK version used to create the data package

Returns:

const std::string& the SDK version

const std::string &remark() const#

get the remark of the data package

Returns:

const std::string& the remark

DataPack &set_remark(std::string remark)#

Set the remark of this data package.

Parameters:

remark – new remark

Returns:

DataPack& reference to this data package

const std::map<std::string, std::string> &extra_fields() const#

get the extra fields map of the data package.

the content of the map is up to user to maintenance. DataPack class does nothing with it.

Returns:

const std::map<std::string, std::string>& the extra fields map

std::map<std::string, std::string> &extra_fields()#

get the extra fields map of the data package.

the content of the map is up to user to maintenance. DataPack class does nothing with it.

Returns:

std::map<std::string, std::string>& the extra fields map

const std::set<std::string> &label_column_ids() const#

get the columns’ name of all label columns in this data package

Returns:

const std::set<std::string>& all ids of label

const std::set<std::string> &view_column_ids() const#

get the columns’ name of all view columns in this data package

Returns:

const std::set<std::string>& all ids of view

std::vector<uint32_t> sample_ids() const#

get the sample ids in this data package

Returns:

std::vector<uint32_t> all sample ids

const std::map<uint32_t, std::string> &fingerprint_map() const#

get a map of sample id to corresponding image fingerprint

Returns:

const std::map<uint32_t, std::string>& the map

uint32_t find_fingerprint(const std::string &fingerprint) const#

find given fingerprint in datapack.

Parameters:

fingerprint – fingerprint to find

Returns:

0 if fingerprint does not exist in datapack, otherwise the corresponding sample id

uint32_t create_sample(const ImageInfo &image_info)#

create a new sample with given image info

Parameters:

image_info – image info of the new sample, must have a non-empty and unique fingerprint

Throws:

excepts::InvalidParameter – if new ImageInfo has a empty or duplicate fingerprint

Returns:

uint32_t the id of the new sample

void erase_sample(uint32_t sample_id)#

delete sample and all related labels/views/image with given id

nothing will happen if the sample id does not exist

Parameters:

sample_id – sample id to delete

LabelColumn label_column(const std::string &column_id)#

get the label column handler of the specified label property

Parameters:

column_id – id of the label column

Returns:

LabelColumn the label column handler

ViewColumn view_column(const std::string &column_id)#

get the view column handler of the specified view property

Parameters:

column_id – id of the view column

Returns:

ViewColumn the view column handler

bool has_image(uint32_t sample_id) const#

test if the given sample has image in the data package

Parameters:

sample_id – sample id

Returns:

bool true if specified data exists, false otherwise

Image get_image(uint32_t sample_id) const#

get the image of the given sample

Parameters:

sample_id – sample id

Throws:

excepts::DataNotFound – if required data does not exist

Returns:

Image the image

void set_image(uint32_t sample_id, const Image &image)#

set the image of the given sample

Parameters:
  • sample_id – sample id

  • image – new Image to save

void set_image(uint32_t sample_id, const Buffer &image_bin)#

set the image of the given sample

Warning

user should generate the image_bin is valid encoded image data of format PNG/BMP/TIF

Parameters:
  • sample_id – sample id

  • image_bin – binary data of the new image to set

ImageInfo get_image_info(uint32_t sample_id) const#

get the image info of the given sample

Parameters:

sample_id – sample id

Throws:

excepts::DataNotFound – if required data does not exist

Returns:

ImageInfo the image info

class LabelColumn#

LabelColumn handles operations on one label in a data package.

Public Functions

bool has(uint32_t sample_id) const#

checks if the specified sample has an entry of this property.

Parameters:

sample_id – id of sample in data package

Returns:

bool true if the entry exists, false otherwise

Label get(uint32_t sample_id) const#

get the stored property of the specified sample.

Parameters:

sample_id – id of sample in data package

Returns:

Label stored property

LabelColumn &set(uint32_t sample_id, const Label &entry)#

store property of the sample into the data package.

Parameters:
  • sample_id – id of sample in data package

  • entry – property to store

Returns:

LabelColumn& reference to self

LabelColumn &erase(uint32_t sample_id)#

erase the entry of the specified sample.

Parameters:

sample_id – id of sample in data package

Returns:

LabelColumn& reference to self

class ViewColumn#

LabelColumn handles operations on one view in a data package.

Public Functions

bool has(uint32_t sample_id) const#

checks if the specified sample has an entry of this property.

Parameters:

sample_id – id of sample in data package

Returns:

bool true if the entry exists, false otherwise

ViewList get(uint32_t sample_id) const#

get the stored property of the specified sample.

Parameters:

sample_id – id of sample in data package

Returns:

T stored property

ViewColumn &set(uint32_t sample_id, const ViewList &entry)#

store property of the sample into the data package.

Parameters:
  • sample_id – id of sample in data package

  • entry – property to store

Returns:

ViewColumn& reference to self

ViewColumn &erase(uint32_t sample_id)#

erase the entry of the specified sample.

Parameters:

sample_id – id of sample in data package

Returns:

ViewColumn& reference to self

class ImageInfo#

ImageInfo is a record of the image’s information with user-defined additional data.

Public Functions

const std::string &file_path() const#

get original file path of the image

Returns:

const std::string& file path, or camera id if from_camera() is true

ImageInfo &set_file_path(const std::string &file_path)#

Set the file path of the ImageInfo record.

Parameters:

file_path – new file path to set

Returns:

ImageInfo& reference to this object, for chaining

const geometry::Size2f &image_size() const#

get the size of the image

Returns:

const geometry::Size2f& the size of the image

ImageInfo &set_image_size(geometry::Size2f image_size)#

Set the image size of the ImageInfo record.

Parameters:

image_size – new image size to set

Returns:

ImageInfo& reference to this object, for chaining

size_t visual_size() const#

get the visual size of the image

Returns:

the visual size of the image

const std::vector<uint32_t> &channels() const#

get the channels of the image

Returns:

std::vector<uint32_t> channels

const std::vector<img::Image::Depth> &depth() const#

get the depths of the image

Returns:

std::vector<img::Image::Depth> depth of the image.

ImageInfo &set_channels_and_depth(const std::vector<uint32_t> &channels, const std::vector<visionflow::img::Image::Depth> &depth)#

Set the channels of the ImageInfo record.

Parameters:
  • channels – new channels to set

  • depth – new depth to set

Returns:

ImageInfo& reference to this object, for chaining

const std::string &image_fingerprint() const#

get the fingerprint of the image

Returns:

const std::string& the fingerprint of the image

ImageInfo &set_image_fingerprint(std::string image_fingerprint)#

Set the image fingerprint of this ImageInfo record.

Parameters:

image_fingerprint – new fingerprint to set

Returns:

ImageInfo& reference to this object, for chaining

bool from_camera() const#

get whether the image is from camera

Returns:

bool true if the image is from camera, false if is from file

ImageInfo &set_from_camera(bool from_camera)#

Set the from camera flag of this ImageInfo record.

Parameters:

from_camera – new flag to set

Returns:

ImageInfo& reference to this object, for chaining

int64_t import_time() const#

get the import timestamp of the image

Returns:

int64_t import timestamp of the image

ImageInfo &set_import_time(int64_t import_time)#

Set the import timestamp of this ImageInfo record.

Parameters:

import_time – new timestamp to set

Returns:

ImageInfo& reference to this object, for chaining

const Tags &tags() const#

get the tags of the image

Returns:

const Tags& tags of the image

ImageInfo &set_tags(Tags tags)#

Set the tags of this ImageInfo record.

Parameters:

tags – new tags to set

Returns:

ImageInfo& reference to this object, for chaining

const Tags &descriptor_tags() const#

get the tags from the sample descriptor

Returns:

const Tag& tags from the sample descriptor

ImageInfo &set_descriptor_tags(Tags tags)#

Set the tags from sample descriptor.

Parameters:

tags – from sample descriptor

Returns:

ImageInfo& reference to this object, for chaining

const visionflow::Image &thumbnail_image() const#

get the thumbnail image

Returns:

const visionflow::Image& thumbnail of the image

ImageInfo &set_thumbnail_image(visionflow::Image thumbnail_image)#

Set the thumbnail image of this ImageInfo record.

Parameters:

thumbnail_image – new thumbnail image to set

Returns:

ImageInfo& reference to this object, for chaining

Buffer dump() const#

dump this into binary data

Returns:

Buffer carrying binary data

ImageInfo &load(const Buffer &ctx)#

load from binary data

Parameters:

ctxBuffer carrying binary data

Returns:

ImageInfo& reference to this ImageInfo, loaded with data from ctx

class Label#

Label represents those properties which is a label or can be used as a label. It contains a string representing the type of the label, and a std::map<string, LabelRegion> storing each region in the label.

Public Types

using Iterator = std::map<std::string, LabelRegion>::iterator#

Label iterator.

using ConstIterator = std::map<std::string, LabelRegion>::const_iterator#

Label const iterator.

Public Functions

const std::string &type() const#

Get the type of this Label.

Returns:

std::string type of this Label.

void set_type(std::string type)#

Set the type of this Label.

Parameters:

type – new type to set.

size_t size() const#

Get the number of visionflow::datapack::LabelRegion in this Label.

Returns:

size_t number of LabelRegion in this Label

bool empty() const#

Check if this Label is empty of visionflow::datapack::LabelRegion.

Returns:

bool true if empty, false otherwise.

std::vector<std::string> keys() const#

Get all visionflow::datapack::LabelRegion keys in this Label.

Returns:

std::vector<std::string> all keys in this Label.

const LabelRegion &at(const std::string &key) const#

Get the visionflow::datapack::LabelRegion at the given key.

Parameters:

key – The key of the visionflow::datapack::LabelRegion.

Returns:

const LabelRegion& The visionflow::datapack::LabelRegion reference at the given key

LabelRegion &at(const std::string &key)#

Get the visionflow::datapack::LabelRegion at the given key.

Parameters:

key – The key of the visionflow::datapack::LabelRegion.

Returns:

LabelRegion& The visionflow::datapack::LabelRegion reference at the given key

bool contains(const std::string &key) const#

Check whether the visionflow::datapack::LabelRegion with the given key exists in this Label.

Parameters:

key – The key of the visionflow::datapack::LabelRegion.

Returns:

bool true if exists, false otherwise.

std::string add(const LabelRegion &region)#

Add a new visionflow::datapack::LabelRegion instance with a new generated key into the Label.

Parameters:

region – The visionflow::datapack::LabelRegion to be added into the Label.

Returns:

std::string The new generated key of the added visionflow::datapack::LabelRegion.

void erase(const std::string &key)#

Erase the visionflow::datapack::LabelRegion with the given key from the Label. Nothing will be done if the key not exists.

Parameters:

key – The key of the visionflow::datapack::LabelRegion.

void update(const std::string &key, const LabelRegion &region)#

Update the visionflow::datapack::LabelRegion specified by given key. If the key does not exists, a new instance will be added with the key.

Parameters:
Iterator begin()#

Get an iterator pointing to the first visionflow::datapack::LabelRegion in this Label.

Note

If the Label is empty, the behavior is same as end().

Returns:

Iterator iterator pointing to the first element

ConstIterator begin() const#

Get an iterator pointing to the first visionflow::datapack::LabelRegion in this Label.

Note

If the Label is empty, the behavior is same as end().

Returns:

ConstIterator iterator pointing to the first element

Iterator end()#

Get an iterator pointing to the position after the last visionflow::datapack::LabelRegion in this Label.

Returns:

Iterator pointing to the position after the last element

ConstIterator end() const#

Get an iterator pointing to the position after the last visionflow::datapack::LabelRegion in this Label.

Returns:

ConstIterator pointing to the position after the last element

Iterator find(const std::string &key)#

Get an iterator pointing to the visionflow::datapack::LabelRegion with given key.

Parameters:

key – The key to the visionflow::datapack::LabelRegion.

Returns:

valid Iterator if key exists, otherwise end().

ConstIterator find(const std::string &key) const#

Get an iterator pointing to the visionflow::datapack::LabelRegion with given key.

Parameters:

key – The key to the visionflow::datapack::LabelRegion.

Returns:

valid Iterator if key exists, otherwise end().

Buffer dump() const#

dump this into binary data

Returns:

Buffer carrying binary data

Label &load(const Buffer &ctx)#

load from binary data

Parameters:

ctxBuffer carrying binary data

Returns:

Label& reference to this Label, loaded with data from ctx

class LabelRegion#

LabelRegion is a single region in a label.

A LabelRegion contains a geometry::Polygon2f representing the region’s area, a geometry::Radian representing the region’s angle, a string representing the region’s name, a float representing the region’s score, and a std::map storing extra fields.

Public Functions

const geometry::Polygon2f &polygon() const#

get the polygon of the LabelRegion

Returns:

NO_DISCARD geometry::Polygon2f

LabelRegion &set_polygon(geometry::Polygon2f polygon)#

set the polygon of the LabelRegion

Parameters:

polygon – the new polygon

Returns:

reference to this LabelRegion, can be chained

bool is_rotate_rect() const#

check if the LabelRegion’s polygon’s outer ring is a rotate rect

Returns:

bool true if the outer ring is a rectangle, false otherwise

geometry::RotateRect2f as_rotate_rect() const#

convert the LabelRegion’s polygon to a rotate rect.

If the LabelRegion was set using set_from_rotate_rect, this function will return the same rotate rect. Otherwise, it will return the min_area_rect of the polygon.

Returns:

geometry::RotateRect2f converted from the polygon

LabelRegion &set_from_rotate_rect(const geometry::RotateRect2f &rect)#

set the LabelRegion’s polygon and angle using a rotate rect.

The polygon will be set to the rectangle, and the angle will be the rotation angle of the rectangle.

Parameters:

rect – the rotate rect to set

const geometry::Radian &angle() const#

get the angle of the LabelRegion

Returns:

geometry::Radian the angle of the LabelRegion

LabelRegion &set_angle(geometry::Radian angle)#

set the angle of the LabelRegion

Parameters:

angle – new angle to set

const std::string &name() const#

get the name of the LabelRegion, might be empty

Returns:

std::string the name of the LabelRegion

LabelRegion &set_name(std::string name)#

set the name of the LabelRegion

Parameters:

name – new name to set

float score() const#

get the score of the LabelRegion

Returns:

float the score of the LabelRegion

LabelRegion &set_score(float score)#

set the score of the LabelRegion

Parameters:

score – new score to set

const std::map<std::string, std::string> &extra_fields() const#

get the extra fields of the LabelRegion

Returns:

std::map<std::string, std::string> the extra fields. the keys are field names, the values are field values serialized as JSON strings.

LabelRegion &set_extra_fields(std::map<std::string, std::string> extra_fields)#

set the extra fields of the LabelRegion

Parameters:

extra_fields – std::map<std::string, std::string> to be set. The keys are field names, the values are field values serialized as JSON strings.

Returns:

The reference of this LabelRegion, can be chained.

LabelRegion &set_extra_field(const std::string &key, const std::string &value)#

Set a extra field key and value of the LabelRegion, the old value will be replaced if it exist.

Parameters:
  • key – the key of the extra field

  • value – the value of the extra field

Returns:

The reference of this LabelRegion, can be chained.

LabelRegion &remove_extra_field(const std::string &key)#

Remove a extra field of the LabelRegion. Nothing will happen if the key is not exist in this view’s extra fields.

Parameters:

key – the key of the extra field to be removed.

Returns:

The reference of this LabelRegion, can be chained.

class ViewList#

ViewList represents a list of views, each after its own matrix transformation and has its own masks. It contains a string representing the type of the view, and a std::map<string, View> storing the view items.

Public Types

using Iterator = std::map<std::string, View>::iterator#

ViewList iterator.

using ConstIterator = std::map<std::string, View>::const_iterator#

ViewList const iterator.

Public Functions

size_t size() const#

Get the number of visionflow::datapack::View in this ViewList.

Returns:

size_t number of View in this ViewList

bool empty() const#

Check if this ViewList is empty of visionflow::datapack::View.

Returns:

bool true if empty, false otherwise.

std::vector<std::string> keys() const#

Get all visionflow::datapack::View keys in this ViewList.

Returns:

std::vector<std::string> all keys in this ViewList.

const View &at(const std::string &key) const#

Get the visionflow::datapack::View at the given key.

Parameters:

key – The key of the visionflow::datapack::View.

Returns:

const View& The visionflow::datapack::View reference at the given key

View &at(const std::string &key)#

Get the visionflow::datapack::View at the given key.

Parameters:

key – The key of the visionflow::datapack::View.

Returns:

View& The visionflow::datapack::View reference at the given key

bool contains(const std::string &key) const#

Check whether the visionflow::datapack::View with the given key exists in this ViewList.

Parameters:

key – The key of the visionflow::datapack::View.

Returns:

bool true if exists, false otherwise.

std::string add(const View &view)#

Add a new visionflow::datapack::View instance with a new generated key into the ViewList.

Parameters:

view – The visionflow::datapack::View to be added into the ViewList.

Returns:

std::string The new generated key of the added visionflow::datapack::View.

void erase(const std::string &key)#

Erase the visionflow::datapack::View with the given key from the ViewList. Nothing will be done if the key not exists.

Parameters:

key – The key of the visionflow::datapack::View.

void update(const std::string &key, const View &view)#

Update the visionflow::datapack::View specified by given key. If the key does not exists, a new instance will be added with the key.

Parameters:
Iterator begin()#

Get an iterator pointing to the first visionflow::datapack::View in this ViewList.

Note

If the ViewList is empty, the behavior is same as end().

Returns:

Iterator iterator pointing to the first element

ConstIterator begin() const#

Get an iterator pointing to the first visionflow::datapack::View in this ViewList.

Note

If the ViewList is empty, the behavior is same as end().

Returns:

ConstIterator iterator pointing to the first element

Iterator end()#

Get an iterator pointing to the position after the last visionflow::datapack::View in this ViewList.

Returns:

Iterator pointing to the position after the last element

ConstIterator end() const#

Get an iterator pointing to the position after the last visionflow::datapack::View in this ViewList.

Returns:

ConstIterator pointing to the position after the last element

Iterator find(const std::string &key)#

Get an iterator pointing to the visionflow::datapack::View with given key.

Parameters:

key – The key to the visionflow::datapack::View.

Returns:

valid Iterator if key exists, otherwise end().

ConstIterator find(const std::string &key) const#

Get an iterator pointing to the visionflow::datapack::View with given key.

Parameters:

key – The key to the visionflow::datapack::View.

Returns:

valid ConstIterator if key exists, otherwise end().

Buffer dump() const#

dump this into binary data

Returns:

Buffer carrying binary data

ViewList &load(const Buffer &ctx)#

load from binary data

Parameters:

ctxBuffer carrying binary data

Returns:

ViewList& reference to this ViewList, loaded with data from ctx

class View#

View is a single view item in a ViewList.

A View contains a geometry::Matrix3f representing the transform matrix, a geometry::Size2f representing the transformed view size, a geometry::MultiPolygon2f representing the masks, a string representing the region’s name, a float representing the region’s score, and a std::map storing extra fields.

Public Functions

const geometry::Matrix3f &transform_matrix() const#

get the transform matrix of the View

Returns:

the transform matrix

View &set_transform_matrix(geometry::Matrix3f matrix)#

Set the transform matrix of the View.

Parameters:

matrix – the new transform matrix

Returns:

View& reference to this View, can be chained

const geometry::Size2f &size() const#

get the transformed size of the View

Returns:

the transformed size

View &set_size(geometry::Size2f size)#

Set the transformed size of the View.

Parameters:

size – new transformed size

Returns:

View& reference to this View, can be chained

const geometry::MultiPolygon2f &masks() const#

get the view masks of the View

Returns:

the view masks

View &set_masks(geometry::MultiPolygon2f masks)#

Set the masks of the View.

Parameters:

masks – new view mask to set

Returns:

View& reference to this View, can be chained

const std::string &name() const#

get the name of the View

Returns:

the name of the View

View &set_name(std::string name)#

set the name of the View

Parameters:

name – new name to set

float score() const#

get the score of the View

Returns:

the score of the View

View &set_score(float score)#

set the score of the View

Parameters:

score – new score to set

const std::map<std::string, std::string> &extra_fields() const#

get the extra fields of the View

Returns:

std::map<std::string, std::string> the extra fields. the keys are field names, the values are field values serialized as JSON strings.

View &set_extra_fields(std::map<std::string, std::string> extra_fields)#

set the extra fields of the View

Parameters:

extra_fields – std::map<std::string, std::string> to be set. The keys are field names, the values are field values serialized as JSON strings.

Returns:

The reference of this View, can be chained.

View &set_extra_field(const std::string &key, const std::string &value)#

Set a extra field key and value of the View, the old value will be replaced if it exist.

Parameters:
  • key – the key of the extra field

  • value – the value of the extra field

Returns:

The reference of this View, can be chained.

View &remove_extra_field(const std::string &key)#

Remove a extra field of the View. Nothing will happen if the key is not exist in this view’s extra fields.

Parameters:

key – the key of the extra field to be removed.

Returns:

The reference of this View, can be chained.