rle#

RleRegion Class#

class RleRegion#

Region represented by run length encoding. The range of RleRegion is [-32768, 32766], all operators which may exceed the range will throw excepts::InvalidArgument.

Public Functions

RleRegion() = default#

Generate an empty RleRegion.

RleRegion(const RleRegion &rhs) = default#

Copy constructor.

Parameters:

rhs – Other RleRegion.

RleRegion(RleRegion &&rhs) noexcept = default#

Move constructor.

Parameters:

rhs – Other rvalue RleRegion.

explicit RleRegion(const Image &img, int low = 128, int high = 255, bool invert = false)#

Create a RleRegion from an Image, all regions whose pixel value in range are seen as a single region.

Parameters:
  • img – Source single channel image in kDepthU8, only the first image page is considered, maximum size is limit to 32766.

  • low – Low threshold (inclusive).

  • high – High threshold (inclusive).

  • invert – If invert, the pixel whose value lower than ‘low’ or higher than ‘high’ is considered.

Throws:

excepts::InvalidArgument – if img is empty / img is not in kDepthU8 / threshold is not vaild / img exceeds RleRegion’s range.

RleRegion(const Image &img, const visionflow::geometry::IGeometry &roi, int low = 128, int high = 255, bool invert = false)#

Create a RleRegion from an Image with roi.

Parameters:
  • img – Source single channel image in kDepthU8, only the first image page is considered, maximum size is limit to 32766.

  • roi – Roi in geometry type, support type : kRing2f / kRing2i / kPolygon2f / kPolygon2i / kMultiRleRegion / kMultiPolygon2i / kRect2f / kRect2i / kRotateRect2f / kRotateRect2i / kCircle2f / kCircle2i / kEllipse2f. Other type will create an empty RleRegion.

  • low – Low threshold (inclusive).

  • high – High threshold (inclusive).

  • invert – If invert, the pixel whose value lower than ‘low’ or higher than ‘high’ is considered.

Throws:

excepts::InvalidArgument – if img is empty / img is not in kDepthU8 / roi is not intersect with img / threshold is not vaild / img or roi exceeds RleRegion’s range.

explicit RleRegion(const visionflow::geometry::IGeometry &geom)#

Create a filled RleRegion from geometry type.

Note

Create an empty RleRegion if ‘geom’ is smaller than one pixel, or its type is not supported.

Parameters:

geomInput geometry, support type : kRing2f / kRing2i / kPolygon2f / kPolygon2i / kMultiRleRegion / kMultiPolygon2i / kRect2f / kRect2i / kRotateRect2f / kRotateRect2i / kCircle2f / kCircle2i / kEllipse2f.

Throws:

excepts::InvalidArgument – if ‘geom’ exceeds RleRegion’s range.

explicit RleRegion(const std::vector<int16_t> &runs, bool check = true)#

Create a RleRegion from a runlength encoding.

Parameters:
  • runsInput runlength. Its size should be 3 * n, which n means number of runlength. It should be organized by row, start_col, end_col of the first runlength, then the second one, and so on. Row should be sorted by ascending order. For each runlength, end_col should larger than start_col and shouldn’t overlap between other runlength. For all runlength, start_col is inclusive and end_col is exclusive.

  • check – Whether check legality of runlength. Usually you should check, if you can guarantee the runlength is right, you can skip check for speed up.

Throws:

excepts::InvalidArgument – if runlength is illegal.

bool empty() const#

Whether the RleRegion is empty. If the RleRegion contains at least one pixel, it’s non-empty, otherwise, it’s empty.

size_t num_runs() const#

Number of runlength in RleRegion.

const std::vector<int16_t> &data() const#

Access the runlength data of RleRegion. There are 3 * number of runlength int16_t data in the vector. The order is row, start_col, end_col of the first runlength, then the second one, and so on. For all runlength, start_col is inclusive and end_col is exclusive.

double area() const#

Area of the RleRegion. The area indicates how many pixels the RleRegion contains.

geometry::Point2f mass_center() const#

Mass center of RleRegion. The mass center is the mean location of a distribution of mass in RleRegion.

geometry::Point2f geom_center() const#

Geometry center of RleRegion. The geometry center is the center of bounding box.

double x_second_moment() const#

RleRegion’s secondary moment in x axis direction. Moments are usually defined with respect to a fixed reference point and refer to physical quantities located some distance from the reference point.

double y_second_moment() const#

RleRegion’s secondary moment in y axis direction. Moments are usually defined with respect to a fixed reference point and refer to physical quantities located some distance from the reference point.

geometry::Radian orientation() const#

RleRegion’s orientation. The orientation indicates the direction with minimum secondary moment. The range is [-pi, pi).

double circularity() const#

RleRegion’s circularity. The circularity is the measure of how closely the RleRegion approaches a standard circle. For standard circle, the circularity is 1, otherwise, the circularity is smaller than 1.

double convexity() const#

RleRegion’s convexity. The convexity is the measure of how closely the RleRegion approaches a convex polygon. For convex polygon, the convexity is 1, otherwise, the convexity is smaller than 1.

double compactness() const#

RleRegion’s compactness. The compactness measure is a numerical quantity representing the degree to which a shape is compact. A standard circle is the most shape, whose compactness is 1. For other shape, the compactness is greater than 1.

Note

if the RleRegion has more than one connected component, only first one is considered.

double rectangularity() const#

RleRegion’s rectangularity. The rectangularity is the measure of how closely the RleRegion approaches a rectangle. For rectangle, the rectangularity is 1, otherwise, the rectangularity is smaller than 1.

geometry::MultiPolygon2i contours(bool include_inners = true, bool pixel_edge_boundary = true) const#

Get RleRegion contours with 8-connected consecutive pixel boundary polygon.

Parameters:
  • include_inners – If true, include inner contours, otherwise, only include outer contours.

  • pixel_edge_boundary – If get pixel edge boundary. Usually pixel boundary is one pixel ‘smaller’ than pixel edge boundary. So if ‘pixel_edge_boundary’ is set to false, it returns a valid MultiPolygon only when region has more than one row and one column.

geometry::Rect2i bounding_box() const#

Bounding rectangle parallel to the coordinate axes.

geometry::RotateRect2f min_area_rect() const#

Smallest bounding rectangle with any orientation.

Note

Angle of RotateRect is (-pi/2, pi/2].

geometry::Rect2i inner_rectangle() const#

Largest inner rectangle of a RleRegion.

geometry::Circle2f bounding_circle() const#

Smallest surrounding circle of a RleRegion.

geometry::Circle2f inner_circle() const#

Largest inner rectangle of a RleRegion.

Note

If the position of the circle is ambiguous, the “first possible” position is returned.

geometry::Ellipse2f elliptic_axis() const#

Calculate the parameters of the equivalent ellipse. The equivalent ellipse have the same orientation and the same aspect ratio as the RleRegion.

Note

For single row RleRegion, it returns ellipse whose axis height is 0.5, for single column RleRegion, it returns ellipse whose axis width is 0.5.

geometry::Ring2i convex_hull() const#

Convex hull of a RleRegion.

class MultiRleRegion#

Multiple RleRegion.

Public Functions

MultiRleRegion() = default#

Default constructor, no initialization.

MultiRleRegion(std::initializer_list<RleRegion> init)#

Constructor taking std::initializer_list, filling the MultiRleRegion.

explicit MultiRleRegion(RleRegion region)#

Construct a MultiRleRegion with RleRegion.

explicit MultiRleRegion(std::vector<RleRegion> region)#

Construct a new MultiRleRegion with std::vector.

explicit MultiRleRegion(size_t n)#

Construct a new MultiRleRegion with n empty RleRegion.

RleRegion &at(size_t index)#

Get a reference to a RleRegion at the given index.

const RleRegion &at(size_t index) const#

Get a const reference to a RleRegion at the given index.

RleRegion &operator[](size_t index)#

Get a reference to a RleRegion at the given index.

const RleRegion &operator[](size_t index) const#

Get a const reference to a RleRegion at the given index.

RleRegion &front()#

Returns a reference to the first element.

const RleRegion &front() const#

Returns a reference to the first element.

RleRegion &back()#

Returns a reference to the last element.

const RleRegion &back() const#

Returns a reference to the last element.

std::vector<RleRegion>::iterator begin() noexcept#

Returns an iterator to the first element.

std::vector<RleRegion>::const_iterator begin() const noexcept#

Returns an iterator to the first element.

std::vector<RleRegion>::iterator end() noexcept#

Returns an iterator to the element following the last element.

std::vector<RleRegion>::const_iterator end() const noexcept#

Returns an iterator to the element following the last element.

bool empty() const noexcept#

Check if the MultiRleRegion is empty.

size_t size() const noexcept#

Get the number of polygons in the MultiRleRegion.

void clear() noexcept#

Clear the MultiRleRegion.

Public Members

std::vector<RleRegion> regions#

RleRegions of the MultiRleRegion.

RleRegion Base Operators#

Image visionflow::rle::region_to_image(const RleRegion &region, const geometry::Size2i &img_size = geometry::Size2i())#

Convert the RleRegion to a kDepthU8 Image. RleRegion transforms to 255 and background to 0.

RleRegion r(Rect2i(Point2i(-10, -20), Point2i(20, 10)));
//return a 100x100 Image with RleRegion's range from (0, 0) to (20, 10)
Image m1 = region_to_image(r, Size2i(100, 100));
//return a 30x30 Image with all 255
Image m2 = region_to_image(r);

Note

Return an empty image when both RleRegion and size are empty.

Parameters:
  • regionInput region.

  • img_size – Size of output image, if not empty, only the part of RleRegion inside in img_size will be considered. Otherwise, use default minimum size enclosing the RleRegion.

bool visionflow::rle::cover_point(const RleRegion &region, const geometry::Point2f &point)#

Test if the RleRegion contains a given point.

Parameters:
bool visionflow::rle::cover_point(const MultiRleRegion &region, const geometry::Point2f &point)#

Test if the MultiRleRegion contains a given point.

Parameters:
  • regionInput regions.

  • pointInput point.

geometry::MultiPolygon2i visionflow::rle::find_contours(const RleRegion &region, bool include_inners = true, bool pixel_edge_boundary = true)#

Get RleRegion contours with 8-connected consecutive pixel boundary polygon.

Parameters:
  • regionInput region.

  • include_inners – If true, include inner contours, otherwise, only include outer contours.

  • pixel_edge_boundary – If get pixel edge boundary. Usually pixel boundary is one pixel ‘smaller’ than pixel edge boundary. So if ‘pixel_edge_boundary’ is set to false, it returns a valid MultiPolygon only when region has more than one row and one column.

std::vector<geometry::MultiPolygon2i> visionflow::rle::find_contours(const MultiRleRegion &region, bool include_inners = true, bool pixel_edge_boundary = true)#

Get MultiRleRegion contours with 8-connected consecutive pixel boundary polygon.

Parameters:
  • regionInput regions.

  • include_inners – If true, include inner contours, otherwise, only include outer contours.

  • pixel_edge_boundary – If get pixel edge boundary. Usually pixel boundary is one pixel ‘smaller’ than pixel edge boundary. So if ‘pixel_edge_boundary’ is set to false, it returns a valid MultiPolygon only when region has more than one row and one column.

RleRegion Morphology Operators#

RleRegion visionflow::rle::dilation_rectangle(const RleRegion &region, const geometry::Size2i &ksize)#

Dilate a RleRegion with a rectangular structuring element.

Parameters:
  • regionInput region.

  • ksize – Size of the structuring element, it must be odd and in range from 1 to 511.

Throws:

excepts::InvalidArgument – if ksize is illegal or it exceeds RleRegion’s range.

MultiRleRegion visionflow::rle::dilation_rectangle(const MultiRleRegion &region, const geometry::Size2i &ksize)#

Dilate MultiRleRegion with a rectangular structuring element.

Parameters:
  • regionInput regions.

  • ksize – Size of the structuring element, it must be odd and in range from 1 to 511.

Throws:

excepts::InvalidArgument – if ksize is illegal or it exceeds RleRegion’s range.

RleRegion visionflow::rle::dilation_circle(const RleRegion &region, double radius)#

Dilate a RleRegion with a circular structuring element.

Parameters:
  • regionInput region.

  • radius – Radius of the structuring element, its range is from 0 to 512.

Throws:

excepts::InvalidArgument – if radius is illegal or it exceeds RleRegion’s range.

MultiRleRegion visionflow::rle::dilation_circle(const MultiRleRegion &region, double radius)#

Dilate MultiRleRegion with a circular structuring element.

Parameters:
  • regionInput regions.

  • radius – Radius of the structuring element, its range is from 0 to 512.

Throws:

excepts::InvalidArgument – if radius is illegal or it exceeds RleRegion’s range.

RleRegion visionflow::rle::erosion_rectangle(const RleRegion &region, const geometry::Size2i &ksize)#

Erode a RleRegion with a rectangular structuring element.

Parameters:
  • regionInput regions.

  • ksize – Size of the structuring element, it must be odd and in range from 1 to 511.

Throws:

excepts::InvalidArgument – if ksize is illegal.

MultiRleRegion visionflow::rle::erosion_rectangle(const MultiRleRegion &region, const geometry::Size2i &ksize)#

Erode MultiRleRegion with a rectangular structuring element.

Parameters:
  • regionInput regions.

  • ksize – Size of the structuring element, it must be odd and in range from 1 to 511.

Throws:

excepts::InvalidArgument – if ksize is illegal.

RleRegion visionflow::rle::erosion_circle(const RleRegion &region, double radius)#

Erode a RleRegion with a circular structuring element.

Parameters:
  • regionInput region.

  • radius – Radius of the structuring element, its range is from 0 to 512.

Throws:

excepts::InvalidArgument – if radius is illegal.

MultiRleRegion visionflow::rle::erosion_circle(const MultiRleRegion &region, double radius)#

Erode MultiRleRegion with a circular structuring element.

Parameters:
  • regionInput regions.

  • radius – Radius of the structuring element, its range is from 0 to 512.

Throws:

excepts::InvalidArgument – if radius is illegal.

RleRegion visionflow::rle::opening_rectangle(const RleRegion &region, const geometry::Size2i &ksize)#

Open a RleRegion with a rectangular structuring element.

Parameters:
  • regionInput region.

  • ksize – Size of the structuring element, it must be odd and in range from 1 to 511.

Throws:

excepts::InvalidArgument – if ksize is illegal.

MultiRleRegion visionflow::rle::opening_rectangle(const MultiRleRegion &region, const geometry::Size2i &ksize)#

Open MultiRleRegion with a rectangular structuring element.

Parameters:
  • regionInput regions.

  • ksize – Size of the structuring element, it must be odd and in range from 1 to 511.

Throws:

excepts::InvalidArgument – if ksize is illegal.

RleRegion visionflow::rle::opening_circle(const RleRegion &region, double radius)#

Open a RleRegion with a circular structuring element.

Parameters:
  • regionInput region.

  • radius – Radius of the structuring element, its range is from 0 to 512.

Throws:

excepts::InvalidArgument – if radius is illegal.

MultiRleRegion visionflow::rle::opening_circle(const MultiRleRegion &region, double radius)#

Open MultiRleRegion with a circular structuring element.

Parameters:
  • regionInput regions.

  • radius – Radius of the structuring element, its range is from 0 to 512.

Throws:

excepts::InvalidArgument – if radius is illegal.

RleRegion visionflow::rle::closing_rectangle(const RleRegion &region, const geometry::Size2i &ksize)#

Close a RleRegion with a rectangular structuring element.

Parameters:
  • regionInput region.

  • ksize – Size of the structuring element, it must be odd and in range from 1 to 511.

Throws:

excepts::InvalidArgument – if ksize is illegal or it exceeds RleRegion’s range.

MultiRleRegion visionflow::rle::closing_rectangle(const MultiRleRegion &region, const geometry::Size2i &ksize)#

Close MultiRleRegion with a rectangular structuring element.

Parameters:
  • regionInput regions.

  • ksize – Size of the structuring element, it must be odd and in range from 1 to 511.

Throws:

excepts::InvalidArgument – if ksize is illegal or it exceeds RleRegion’s range.

RleRegion visionflow::rle::closing_circle(const RleRegion &region, double radius)#

Close a RleRegion with a circular structuring element.

Parameters:
  • regionInput region.

  • radius – Radius of the structuring element, its range is from 0 to 512.

Throws:

excepts::InvalidArgument – if radius is illegal or it exceeds RleRegion’s range.

MultiRleRegion visionflow::rle::closing_circle(const MultiRleRegion &region, double radius)#

Close MultiRleRegion with a circular structuring element.

Parameters:
  • regionInput regions.

  • radius – Radius of the structuring element, its range is from 0 to 512.

Throws:

excepts::InvalidArgument – if radius is illegal or it exceeds RleRegion’s range.

RleRegion Set Operators#

RleRegion visionflow::rle::intersection(const RleRegion &region1, const RleRegion &region2)#

Calculate the intersection of two regions.

Parameters:
RleRegion visionflow::rle::intersection(const RleRegion &region1, const MultiRleRegion &region2)#

Calculate the intersection of multiple regions.

Parameters:
  • region1 – First RleRegion.

  • region2 – Multiple RleRegions, all elements are seen a whole region.

MultiRleRegion visionflow::rle::intersection(const MultiRleRegion &region1, const RleRegion &region2)#

Calculate the intersection of multiple regions.

Parameters:
  • region1 – Multiple RleRegions, intersect with other RleRegion separately.

  • region2 – Second RleRegion.

RleRegion visionflow::rle::union2(const RleRegion &region1, const RleRegion &region2)#

Calculate the union of two regions.

Parameters:
RleRegion visionflow::rle::union2(const RleRegion &region1, const MultiRleRegion &region2)#

Calculate the union of multiple regions.

Parameters:
  • region1 – First RleRegion.

  • region2 – Multiple RleRegions, all elements are seen a whole region.

MultiRleRegion visionflow::rle::union2(const MultiRleRegion &region1, const RleRegion &region2)#

Calculate the union of multiple regions.

Parameters:
  • region1 – Multiple RleRegions, union with other RleRegion separately.

  • region2 – Second RleRegion.

RleRegion visionflow::rle::union_all(const MultiRleRegion &region)#

Calculate the union of all regions.

Parameters:

region – Multiple RleRegions.

RleRegion visionflow::rle::complement(const RleRegion &region, const geometry::Rect2i &range = geometry::Rect2i())#

Calculate the complement of a RleRegion.

Parameters:
  • regionInput region.

  • range – Range of scene, it should enclosing current RleRegion. If empty, use default range of RleRegion.

Throws:

excepts::InvalidArgument – if both RleRegion and range are empty.

RleRegion visionflow::rle::difference(const RleRegion &region1, const RleRegion &region2)#

Calculate the difference of two regions.

Parameters:
RleRegion visionflow::rle::difference(const RleRegion &region1, const MultiRleRegion &region2)#

Calculate the difference of multiple regions.

Parameters:
  • region1 – First RleRegion.

  • region2 – Multiple RleRegions, all elements are seen a whole region.

MultiRleRegion visionflow::rle::difference(const MultiRleRegion &region1, const RleRegion &region2)#

Calculate the difference of multiple regions.

Parameters:
  • region1 – Multiple RleRegions, difference other RleRegion separately.

  • region2 – Second RleRegion.

RleRegion visionflow::rle::symm_difference(const RleRegion &region1, const RleRegion &region2)#

Calculate the symmetric difference of two regions.

Parameters:
RleRegion visionflow::rle::symm_difference(const RleRegion &region1, const MultiRleRegion &region2)#

Calculate the symmetric difference of multiple regions.

Parameters:
  • region1 – First RleRegion.

  • region2 – Multiple RleRegions, all elements are seen a whole region.

MultiRleRegion visionflow::rle::symm_difference(const MultiRleRegion &region1, const RleRegion &region2)#

Calculate the difference of multiple regions.

Parameters:
  • region1 – Multiple RleRegions, symmetric difference with other RleRegion separately.

  • region2 – Second RleRegion.

RleRegion Connection Operators#

MultiRleRegion visionflow::rle::connection(const RleRegion &region)#

Compute the connected components of a RleRegion.

Parameters:

regionInput region.

MultiRleRegion visionflow::rle::connection(const MultiRleRegion &region)#

Compute the connected components of MultiRleRegion. All results of input will be added into output in sequence.

Parameters:

regionInput regions.

RleRegion visionflow::rle::fill_up(const RleRegion &region, double min_area = 0, double max_area = 1e10)#

Fill up holes in RleRegion.

Parameters:
  • regionInput region.

  • min_area – Holes whose area equal to or larger than min_area will be filled.

  • max_area – Holes whose area equal to or smaller than max_area will be filled.

MultiRleRegion visionflow::rle::fill_up(const MultiRleRegion &region, double min_area = 0, double max_area = 1.7976931348623157e+308)#

Fill up holes in MultiRleRegion.

Parameters:
  • regionInput regions.

  • min_area – Holes whose area equal to or larger than min_area will be filled.

  • max_area – Holes whose area equal to or smaller than max_area will be filled.

RleRegion Transformation Operators#

RleRegion visionflow::rle::transform_translate(const RleRegion &region, int dx, int dy)#

Translate a RleRegion.

Parameters:
  • regionInput region.

  • dx – Translate distance in x axis direction.

  • dy – Translate distance in y axis direction.

Throws:

excepts::InvalidArgument – if it exceeds RleRegion’s range.

MultiRleRegion visionflow::rle::transform_translate(const MultiRleRegion &region, int dx, int dy)#

Translate MultiRleRegion.

Parameters:
  • regionInput regions.

  • dx – Translate distance in x axis direction.

  • dy – Translate distance in y axis direction.

Throws:

excepts::InvalidArgument – if it exceeds RleRegion’s range.

RleRegion visionflow::rle::transform_scale(const RleRegion &region, double scale_width, double scale_height)#

Enlarge or reduce the RleRegion in the x- and y-direction.

Note

Return empty RleRegion when it’s smaller than one pixel.

Parameters:
  • regionInput region.

  • scale_width – Scale factor in x-direction, the range is (0, 100].

  • scale_height – Scale factor in y-direction, the range is (0, 100].

Throws:

excepts::InvalidArgument – if it exceeds RleRegion’s range.

MultiRleRegion visionflow::rle::transform_scale(const MultiRleRegion &region, double scale_width, double scale_height)#

Enlarge or reduce the RleRegion in the x- and y-direction.

Note

Return empty RleRegion when it’s smaller than one pixel.

Parameters:
  • regionInput regions.

  • scale_width – Scale factor in x-direction, the range is (0, 100].

  • scale_height – Scale factor in y-direction, the range is (0, 100].

Throws:

excepts::InvalidArgument – if it exceeds RleRegion’s range.

RleRegion Advanced Operators#

enum visionflow::rle::FeatureType#

RleRegion feature type.

Values:

enumerator kMaxArea#

max area

enumerator kArea#

area of the RleRegion

enumerator kRow#

row coordinate of the geometric center

enumerator kColumn#

column coordinate of the geometric center

enumerator kWidth#

width of the RleRegion (parallel to the coordinate axes)

enumerator kHeight#

height of the RleRegion (parallel to the coordinate axes)

enumerator kRow1#

row coordinate of upper left corner

enumerator kColumn1#

column coordinate of upper left corner

enumerator kRow2#

row coordinate of lower right corner

enumerator kColumn2#

column coordinate of lower right corner

enumerator kCircularity#

circularity

enumerator kCompactness#

compactness

enumerator kConvexity#

convexity

enumerator kRectangularity#

rectangularity

enumerator kOuterRadius#

radius of smallest surrounding circle

enumerator kInnerRadius#

radius of largest inner circle

enumerator kInnerWidth#

width of the largest axis-parallel rectangle that fits into the RleRegion

enumerator kInnerHeight#

height of the largest axis-parallel rectangle that fits into the RleRegion

enumerator kOrientation#

orientation (in radian)

enumerator kMassCenterRow#

row coordinate of the mass center

enumerator kMassCenterColumn#

column coordinate of the mass center

enumerator kMinAreaRectLongSide#

long side of the smallest surrounding rectangle

enumerator kMinAreaRectShortSide#

short side of the smallest surrounding rectangle

enumerator kMinAreaRectCenterRow#

row coordinate of center of the smallest surrounding rectangle

enumerator kMinAreaRectCenterColumn#

column coordinate of center of the smallest surrounding rectangle

enumerator kMinAreaRectAngle#

orientation of the smallest surrounding rectangle (in radian)

enumerator kMomentX2nd#

secondary moment in x axis direction

enumerator kMomentY2nd#

secondary moment in y axis direction

struct SelectFeature#

RleRegion select feature.

Param type:

RleRegion feature type, see FeatureType. If type is kMaxArea, other parameter min/max/invert will be ignored.

Param min:

Low limit of filter (inclusive).

Param max:

High limit of filter (inclusive).

Param invert:

If invert, the RleRegion whose properties smaller than min or larger than max will be considered.

enum visionflow::rle::SelectLogic#

RleRegion select logic.

Values:

enumerator kAnd#

all filters connect with AND, RleRegion must satisfy all filters

enumerator kOr#

all filters connect with OR, RleRegion only need satisfy one filter

enum visionflow::rle::ShapeTransType#

RleRegion shape transform type.

Values:

enumerator kConvex#

convex hull

enumerator kEllipse#

ellipse with the same moments and area as the input RleRegion

enumerator kOuterCircle#

smallest enclosing circle

enumerator kInnerCircle#

largest circle fitting into the RleRegion

enumerator kBoundingBox#

smallest enclosing rectangle parallel to the coordinate axes

enumerator kMinAreaRect#

smallest enclosing rectangle

enumerator kInnerRectangle#

largest axis-parallel rectangle fitting into the RleRegion

RleRegion visionflow::rle::shape_transform(const RleRegion &region, ShapeTransType type)#

Transform the shape of a RleRegion.

Parameters:
MultiRleRegion visionflow::rle::shape_transform(const MultiRleRegion &region, ShapeTransType type)#

Transform the shape of a vector of RleRegion.

Parameters:
std::vector<double> visionflow::rle::region_features(const RleRegion &region, const std::vector<FeatureType> &types)#

Calculate shape features of RleRegion.

Note

If there is only one element in types whose type is kMaxArea, the function returns a single value in output. If there is more than one element in types, the output size is equal to types’ size, and all elements with type kMaxArea will be ignored. The sequence in output is feature_1, feature_2 … feature_n of input region. If the feature is angle, it represents by radian.

Parameters:
Throws:

excepts::InvalidArgument – if types is empty.

std::vector<double> visionflow::rle::region_features(const MultiRleRegion &region, const std::vector<FeatureType> &types)#

Calculate shape features of MultiRleRegion.

Note

If there is only one element in types whose type is kMaxArea, the function returns a single value in output. If there is more than one element in types, the output has regions’ size multiply types’ size elements, and all elements with type kMaxArea will be ignored. The sequence in output is feature_1, feature_2 … feature_n of first region, then features of second region, and so on. If the feature is angle, it represents by radian.

Parameters:
Throws:

excepts::InvalidArgument – if types is empty.

MultiRleRegion visionflow::rle::select_shape(const MultiRleRegion &region, const std::vector<SelectFeature> &feats, SelectLogic logic = SelectLogic::kAnd)#

Choose MultiRleRegion with the aid of shape features.

Note

If there is only one feature in ‘feats’ whose type is kMaxArea, the function returns a single region in RleRegion with max area, and parameter logic will be ignored. If there is more than one feature in ‘feats’, all features with type kMaxArea will be ignored. The output only contains non-empty region.

Parameters:
  • regionInput regions.

  • feats – A series of select features.

  • logic – Select logic, see SelectLogic.

MultiRleRegion visionflow::rle::sort_character_order(const MultiRleRegion &region, int axis = 0, bool reverse = false, double overlap = 0.15)#

Sort MultiRleRegion with respect to their relative position.

Note

The output only contains non-empty region.

Parameters:
  • regionInput regions.

  • axis – Sort first in which axis, 0 indicates sorting first with respect to row, then to column, 1 indicates sorting first with respect to column, then to row.

  • reverse – Determine whether reverse the sorted order, false for increasing and true for decreasing.

  • overlap – Maximum percentage of overlap, overlap between adjacent rows (or columns) exceed this value will be considered as same rows (or columns), only used for kCharacter mode.

MultiRleRegion visionflow::rle::sort_by_feature(const MultiRleRegion &region, FeatureType type, bool ascending = false)#

Sort MultiRleRegion with respect to their features.

Note

The output only contains non-empty region.

Parameters:
  • regionInput regions.

  • typeRleRegion feature type, see FeatureType.

  • ascending – If true, sort in ascending order, otherwise in decending order.