Skip to content

API v1.1.0

taotianran edited this page Feb 6, 2023 · 4 revisions

API 文档

  1. API 目录

  2. API 详细中文说明

1. API 目录



2. API 详细中文说明

core

命名空间

默认命名空间:fcv


枚举类型

FCVImageType

声明文件: modules/core/base/interface/basic_types.h

说明: 图像类型枚举

enum class FCVImageType {
    GRAY_U8 = 0,            // 单通道,unsigned char存储
    GRAY_U16,               // 单通道,unsigned short存储
    GRAY_S16,               // 单通道,signed short存储
    GRAY_S32,               // 单通道,int32存储
    GRAY_F32,               // 单通道,float32存储
    GRAY_F64,               // 单通道,double存储
    PLA_BGR_U8 = 20,        // 三通道,unsigned char存储,存储顺序:BBB...GGG...RRR...
    PLA_RGB_U8,             // 三通道,unsigned char存储,存储顺序:RRR...GGG...BBB...
    PKG_BGR_U8,             // 三通道,unsigned char存储,存储顺序:BGRBGR...
    PKG_RGB_U8,             // 三通道,unsigned char存储,存储顺序:RGBRGB...
    PLA_BGRA_U8,            // 四通道,unsigned char存储,存储顺序:BBB...GGG...RRR...AAA...
    PLA_RGBA_U8,            // 四通道,unsigned char存储,存储顺序:RRR...GGG...BBB...AAA...
    PKG_BGRA_U8,            // 四通道,unsigned char存储,存储顺序:BGRABGRA...
    PKG_RGBA_U8,            // 四通道,unsigned char存储,存储顺序:RGBARGBA...
    PLA_BGR_F32 = 40,       // 三通道,float存储,存储顺序:BBB...GGG...RRR...
    PLA_RGB_F32,            // 三通道,float存储,存储顺序:RRR...GGG...BBB...
    PKG_BGR_F32,            // 三通道,float存储,存储顺序:BGRBGR...
    PKG_RGB_F32,            // 三通道,float存储,存储顺序:RGBRGB...
    PLA_BGRA_F32,           // 四通道,float存储,存储顺序:BBB...GGG...RRR...AAA...
    PLA_RGBA_F32,           // 四通道,float存储,存储顺序:RRR...GGG...BBB...AAA...
    PKG_BGRA_F32,           // 四通道,float存储,存储顺序:BGRABGRA...
    PKG_RGBA_F32,           // 四通道,float存储,存储顺序:RGBARGBA...
    PKG_BGR_F64,            // 三通道,double存储,存储顺序:BGRBGR...
    PKG_RGB_F64,            // 三通道,double存储,存储顺序:RGBRGB...
    PKG_BGRA_F64,           // 四通道,double存储,存储顺序:BGRABGRA...
    PKG_RGBA_F64,           // 四通道,double存储,存储顺序:RGBARGBA...
    PKG_BGR565_U8,          // 三通道,unsigned char存储,存储顺序:BGRBGR...
    PKG_RGB565_U8,          // 三通道,unsigned char存储,存储顺序:RGBRGB...
    NV12 = 60,              // YUV420SP类型,像素占比为Y:V:U=4:1:1,存储顺序:YYY...UVUV...
    NV21,                   // YVU420SP类型,像素占比为Y:U:V=4:1:1,存储顺序:YYY...VUVU...
    I420,                   // YUV420P类型,像素占比为Y:U:V=4:1:1,存储顺序:YYY...UUU...VVV...
};

InterpolationType

声明文件: modules/core/base/interface/basic_types.h

说明: 插值类型枚举

enum class InterpolationType {
    INTER_NEAREST = 0,          // 最近邻插值
    INTER_LINEAR,               // 双线性插值
    INTER_CUBIC,                // 立方插值
    INTER_AREA,                 // 区域插值
    WARP_INVERSE_MAP = 16       // 双线性插值(变换矩阵不求逆)
};

BorderType

声明文件: modules/core/base/interface/basic_types.h

说明: 边缘填充类型

enum class BorderType {
    BORDER_CONSTANT    = 0, //!< `iiiiii|abcdefgh|iiiiiii`  with some specified `i`
    BORDER_REPLICATE   = 1, //!< `aaaaaa|abcdefgh|hhhhhhh`
    BORDER_REFLECT     = 2, //!< `fedcba|abcdefgh|hgfedcb`
    BORDER_WRAP        = 3, //!< `cdefgh|abcdefgh|abcdefg`
    BORDER_REFLECT_101 = 4, //!< `gfedcb|abcdefgh|gfedcba`
    BORDER_TRANSPARENT = 5  //!< `uvwxyz|abcdefgh|ijklmno`
};

NormType

声明文件: modules/core/base/interface/basic_types.h

说明: 范数类型

enum class NormType {
    NORM_INF       = 0,    // 无穷范数,所有元素中绝对值最大的数
    NORM_L1,               // L1范数,各个元素绝对值之和
    NORM_L2                // L2范数,各个元素平方和的平方根
};

Size_

声明文件: modules/core/base/interface/basic_types.h

template<class T>
class Size_ {
public:
    // 构造函数
    Size_();
    Size_(int width, int height);
    Size_(const Size_& sz);

    // 设置宽度
    void set_width(T width);

    // 设置高度
    void set_height(T height);

    // 获取宽度
    T width() const;

    // 获取高度
    T height() const;
};

typedef Size_<int> SizeI;
typedef Size_<int64_t> SizeL;
typedef Size_<float> SizeF;
typedef Size_<double> SizeD;
typedef SizeI Size;

说明: Size_模板类用于存储图像的宽高信息,目前支持32位及64位的整型或浮点存储。


Point_

声明文件: modules/core/base/interface/basic_types.h

template<class T>
class Point_ {
public:
    // 构造函数
    Point_();
    Point_(T x, T y);
    Point_(const Point_& p) = default;

    // 默认赋值行为
    Point_& operator=(const Point_& p) = default;

    // 析构函数(使用默认生成)
    ~Point_() = default;

    // 设置x坐标值
    void set_x(T x);

    // 设置y坐标值
    void set_y(T y);

    // 获取x坐标值
    T x() const;

    // 获取y坐标值
    T y() const;
};

typedef Point_<int> Point;
typedef Point Point2i;
typedef Point_<float> Point2f;
typedef Point_<double> Point2d;

说明: Point_模板类存储坐标点数据的模板类。


Rect_

声明文件: modules/core/base/interface/basic_types.h

template<class T>
class Rect_ {
public:
    // 构造函数
    Rect_();
    Rect_(T x, T y, T width, T height);
    Rect_(const Rect_& rectangle) = default;

    // 析构函数(使用默认生成)
    ~Rect_() = default;

    // 默认赋值行为
    Rect_& operator=(const Rect_& rectangle) = default;

    // 设置左上角顶点x坐标值。
    void set_x(T x);

    // 置左上角顶点y坐标值
    void set_y(T y);

    // 设置矩形宽度
    void set_width(T width);

    // 设置矩形高度
    void set_height(T height);

    // 获取矩形左上角顶点x的坐标值
    T x() const;

    // 获取矩形左上角顶点y的坐标值
    T y() const;

    // 获取矩形宽度
    T width() const;

    // 获取矩形高度
    T height() const;
};

typedef Rect_<int> RectI;
typedef Rect_<float> RectF;
typedef Rect_<double> RectD;
typedef RectI Rect;

说明: Rect_模板类用于存储矩形框信息,支持32位整数型、32位浮点型、64位浮点型数据,主要包含左上角点在图像中的横坐标_x,纵坐标_y,宽度值_width,高度值_height


RotatedRect

声明文件: modules/core/base/interface/basic_types.h

class RotatedRect {
public:
    // 构造函数
    RotatedRect();

    // center_x:旋转矩形的中心点x坐标值。
    // center_y:旋转矩形的中心点y坐标值。
    // width:旋转矩形的宽度。
    // height:旋转矩形的高度。
    // angle:旋转矩形的角度(角度制),与x轴平行的方向为角度为0,逆时针旋转角度为负,顺时针旋转角度为正。
    RotatedRect(const float& center_x, const float& center_y,
            const float& width, const float& height, const float& angle);
    RotatedRect(const Point2f& center, const Size2f& size, const float& angle);
    RotatedRect(const RotatedRect&) = default;

    // 析构函数(使用默认生成)
    ~RotatedRect() = default;

    // 设置旋转矩形中心点坐标
    void set_center(const Point2f& center);

    // 设置旋转矩形中心点x坐标
    void set_center_x(const float& center_x);

    // 设置旋转矩形中心点y坐标
    void set_center_y(const float& center_y);

    // 设置旋转矩形宽高
    void set_size(const Size2f& size);

    // 设置旋转矩形宽度
    void set_width(const float& width);

    // 设置旋转矩形高度
    void set_height(const float& height);

    // 设置旋转矩形角度
    void set_angle(const float& angle);

    // 返回旋转矩形的四个顶点坐标
    void points(std::vector<Point2f>& pts);

    // 获取旋转矩形中心点坐标
    Point2f center() const;

    // 获取旋转矩形中心点x坐标值
    float center_x() const;

    // 获取旋转矩形中心点y坐标值
    float center_y() const;

    // 获取旋转矩形宽高
    Size2f size() const;

    // 获取旋转矩形宽度
    float width() const;

    // 获取旋转矩形高度
    float height() const;

    // 获取旋转矩形角度
    float angle() const;
};

说明: RotatedRect类用于存储带有角度信息的矩形框数据,只支持float类型数据


Scalar_

声明文件: modules/core/base/interface/basic_types.h

template<class T>
class Scalar_ {
public:
    // 构造函数
    Scalar_();
    Scalar_(T v0, T v1, T v2 = 0, T v3 = 0);
    Scalar_(T v0);
    Scalar_(const Scalar_& s);

    // 重载赋值运算符
    Scalar_& operator= (const Scalar_& s);

    // 重载[]运算符,支持下标取值/赋值
    T& operator[] (int index);

    // 重载[]运算符,支持下标取值(针对常量)
    const T& operator[] (int index) const;

    // 设置索引位置的值。
    int set_val(int index, T val);

    // 返回标量数据的指针。
    const T* val() const;

    // 用给定的值初始化标量数组
    static Scalar_<T> all(T v0);
};

typedef Scalar_<double> Scalar;

说明: 存储标量数据的模板类。存储数据上限为4,通常对应图像数据的不同channel参与计算。


Mat

声明文件: modules/core/mat/interface/mat.h

class Mat {
public:
    // 构造函数
    Mat();

    // width:图像宽度;height:图像高度;type:图像类型;data:图像数据指针;stride:对齐宽度(字节数)
    Mat(int width, int height, FCVImageType type, void* data, int stride = 0);

    // phy_addrs:物理地址指针数组;vir_addrs:虚拟地址指针数组
    Mat(int width, int height, FCVImageType type, std::vector<uint64_t*>& phy_addrs,
            std::vector<uint64_t*>& vir_addrs, int stride = 0);
    Mat(int width, int height, FCVImageType type, int stride = 0,
            PlatformType platform = PlatformType::CPU);
    Mat(Size size, FCVImageType type, int stride = 0, PlatformType platform = PlatformType::CPU);

    // 析构函数
    ~Mat();

    // 返回图像宽度
    int width() const;

    // 返回图像高度
    int height() const;

    // 返回图像宽高
    Size2i size() const;

    // 返回图像通道数
    int channels() const;

    // 返回单行所占字节数
    int stride() const;

    // 返回图像类型
    FCVImageType type() const;

    // 返回存储数据类型所占的字节数
    int type_byte_size() const;

    // 返回所有数据总字节数
    uint64_t total_byte_size() const;

    // 判断图像是否为空
    bool empty() const;

    // 获取图像数据指针
    void* data() const;

    // 返回物理地址(针对部分特定硬件)
    uint64_t* phy_data() const;

    // 返回虚拟地址(针对部分特定硬件)
    uint64_t* vir_data() const;

    // 深度拷贝图像数据
    Mat clone() const;

    // 返回指定坐标像素值的引用,x:横坐标;y:纵坐标;c:通道
    template<typename T>
    T& at(int x, int y, int c = 0);

    // 返回指定坐标像素的常量引用
    template<typename T>
    const T& at(int x, int y, int c = 0) const;

    // 返回指定坐标的指针
    template<typename T>
    T* ptr(int x, int y, int c = 0);

    // 返回指定坐标的常量指针
    template<typename T>
    const T* ptr(int x, int y, int c = 0) const;

    /* 缩放、平移,转化为指定数据类型
     * dst:目的矩阵
     * dst_type:指定目的矩阵的类型。
     * scale:缩放系数
     * shift:平移值
     */
    void convert_to(Mat& dst, FCVImageType dst_type, double alpha = 1.0, double beta = 0.0) const;

    // 数据深拷贝到指定目标
    void copy_to(Mat& dst) const;

    // 数据根据遮罩拷贝到指定目标
    void copy_to(Mat& dst, Mat& mask) const;

    // 根据给定的矩形框将数据拷贝到指定目标
    void copy_to(Mat& dst, Rect& rect) const;

    // 点乘
    double dot(Mat& m) const;

    // 求逆
    bool invert(Mat& dst) const;
};

说明: 图像数据类。采用引用计数,内部分配的数据空间无需手动释放;外部传入的数据需要进行外部自行释放。


函数

fcv_round

声明文件: modules/core/basic_math/interface/basic_math.h

函数原型

inline int fcv_round(doubel value);

说明: 浮点类型数据四舍五入转为整型。


fcv_floor

声明文件: modules/core/basic_math/interface/basic_math.h

函数原型

inline int fcv_floor(double value);

说明: 双精度浮点型数据类型向下取整(例如:-0.3转为-1,10.4转为10)


fcv_ceil

声明文件: modules/core/basic_math/interface/basic_math.h

函数原型

inline int fcv_ceil(double value);

说明: 双精度浮点型数据类型向上取整(例如:-0.3转为0,10.4转为11)


fcv_clamp

声明文件: modules/core/basic_math/interface/basic_math.h

函数原型

template<class T, class D>
static inline constexpr T fcv_clamp(const T& val, const D& min, const D& max);

说明: 将随机值固定在限定区间,低于下限则返回下限,超出上限则返回上限。

参数 类型 说明
val const T& 给定的值
min const D& 区间下限
max const D& 区间上限

fcv_cast_s16

声明文件: modules/core/basic_math/interface/basic_math.h

函数原型

template<class T>
static inline constexpr short fcv_cast_s16(const T& val);

说明: 将给定的值限制在signed short可表示的范围之内。


fcv_cast_u16

声明文件: modules/core/basic_math/interface/basic_math.h

函数原型

template<class T>
static inline constexpr unsigned short fcv_cast_u16(const T& val);

说明: 将给定的值限制在unsigned short可表示的范围之内。


fcv_cast_s8

声明文件: modules/core/basic_math/interface/basic_math.h

函数原型

template<class T>
static inline constexpr signed char fcv_cast_s8(const T& val);

说明: 将给定的值限制在signed char可表示的范围之内。


fcv_cast_u8

声明文件: modules/core/basic_math/interface/basic_math.h

函数原型

template<class T>
static inline constexpr unsigned char fcv_cast_u8(const T& val);

说明: 将给定的值限制在unsigned char可表示的范围之内。


parallel_run

声明文件: modules/core/parallel/interface/parallel.h

函数原型

int parallel_run(
        const Range& range,
        const ParallelTask& task,
        int nstripes = -1);

说明: 多线程并行运行接口函数。


set_thread_num

声明文件: modules/core/parallel/interface/parallel.h

函数原型

void set_thread_num(int num);

说明: 设置线程池线程数。


get_thread_num

声明文件: modules/core/parallel/interface/parallel.h

函数原型

int get_thread_num();

说明: 获取线程池线程数。


img_transform

枚举类型

ColorConvertType

说明: 颜色空间转换枚举

enum class ColorConvertType {
    CVT_PA_BGR2GRAY = 0,
    CVT_PA_RGB2GRAY,

    CVT_PA_BGR2PA_RGB,
    CVT_PA_RGB2PA_BGR,
    CVT_PA_BGR2PA_BGRA,
    CVT_PA_RGB2PA_RGBA,
    CVT_PA_BGR2PA_RGBA,
    CVT_PA_RGB2PA_BGRA,
    CVT_PA_BGRA2PA_BGR,
    CVT_PA_RGBA2PA_RGB,
    CVT_PA_RGBA2PA_BGR,
    CVT_PA_BGRA2PA_RGB,
    CVT_PA_BGRA2PA_RGBA,
    CVT_PA_RGBA2PA_BGRA,

    CVT_GRAY2PA_RGB,
    CVT_GRAY2PA_BGR,
    CVT_GRAY2PA_BGRA,
    CVT_GRAY2PA_RGBA,

    CVT_PA_BGR2NV12,
    CVT_PA_BGR2NV21,
    CVT_PA_RGB2NV12,
    CVT_PA_RGB2NV21,

    CVT_PA_BGRA2NV12,
    CVT_PA_BGRA2NV21,
    CVT_PA_RGBA2NV12,
    CVT_PA_RGBA2NV21,

    CVT_NV122PA_RGB,
    CVT_NV212PA_RGB,
    CVT_NV122PA_BGR,
    CVT_NV212PA_BGR,
    CVT_I4202PA_BGR,

    CVT_NV122PA_BGRA,
    CVT_NV212PA_BGRA,
    CVT_NV122PA_RGBA,
    CVT_NV212PA_RGBA,

    CVT_PA_BGR2PL_BGR,  //bgrbgrbgr... convert to bbb...ggg...rrr
    CVT_PL_BGR2PA_BGR,  //bb..gg..rr.. convert to bgrbgr..

    CVT_PA_GRAY2PA_BGR565,
    CVT_PA_BGR2PA_BGR565,
    CVT_PA_RGB2PA_BGR565,
    CVT_PA_BGRA2PA_BGR565,
    CVT_PA_RGBA2PA_BGR565,

    CVT_PA_RGBA2PA_mRGBA,
};

说明: ColorConvertType类型名中的PA指代Package排列,PL为Planar排列,左侧指源格式,右侧指目标格式。

类型 源格式 目标格式
CVT_INVALID 无效的转换类型
CVT_PA_BGR2GRAY PACKAGE排列,三通道,BGR图像 单通道,灰度图
CVT_PA_RGB2GRAY PACKAGE排列,三通道,RGB图像 单通道,灰度图
CVT_PA_BGR2PA_RGB PACKAGE排列,三通道,BGR图像 PACKAGE排列,三通道,RGB图像
CVT_PA_RGB2PA_BGR PACKAGE排列,三通道,RGB图像 PACKAGE排列,三通道,BGR图像
CVT_PA_BGR2PA_BGRA PACKAGE排列,三通道,BGR图像 PACAKGE排列,四通道,BGRA图像
CVT_PA_RGB2PA_RGBA PACKAGE排列,三通道,RGB图像 PACAKGE排列,四通道,RGBA图像
CVT_PA_BGR2PA_RGBA PACKAGE排列,三通道,BGR图像 PACAKGE排列,四通道,RGBA图像
CVT_PA_RGB2PA_BGRA PACKAGE排列,三通道,RGB图像 PACAKGE排列,四通道,BGRA图像
CVT_PA_BGRA2PA_BGR PACKAGE排列,四通道,BGRA图像 PACKAGE排列,三通道,BGR图像
CVT_PA_RGBA2PA_RGB PACKAGE排列,四通道,RGBA图像 PACKAGE排列,三通道,RGB图像
CVT_PA_RGBA2PA_BGR PACKAGE排列,四通道,RGBA图像 PACKAGE排列,三通道,BGR图像
CVT_PA_BGRA2PA_RGB PACKAGE排列,四通道,BGRA图像 PACKAGE排列,三通道,RGB图像
CVT_PA_BGRA2PA_RGBA PACKAGE排列,四通道,BGRA图像 PACKAGE排列,四通道,RGBA图像
CVT_PA_RGBA2PA_BGRA PACKAGE排列,四通道,RGBA图像 PACKAGE排列,四通道,BGRA图像
CVT_GRAY2PA_RGB 单通道,灰度图 PACKAGE排列,三通道,RGB图像
CVT_GRAY2PA_BGR 单通道,灰度图 PACKAGE排列,三通道,BGR图像
CVT_GRAY2PA_BGRA 单通道,灰度图 PACKAGE排列,四通道,BGRA图像
CVT_GRAY2PA_RGBA 单通道,灰度图 PACKAGE排列,四通道,RGBA图像
CVT_PA_BGR2NV12 PACKAGE排列,三通道,BGR图像 NV12图像
CVT_PA_BGR2NV21 PACKAGE排列,三通道,BGR图像 NV21图像
CVT_PA_RGB2NV12 PACKAGE排列,三通道,RGB图像 NV12图像
CVT_PA_RGB2NV21 PACKAGE排列,三通道,RGB图像 NV21图像
CVT_PA_BGRA2NV12 PACKAGE排列,四通道,BGRA图像 NV12图像
CVT_PA_BGRA2NV21 PACKAGE排列,四通道,BGRA图像 NV21图像
CVT_PA_RGBA2NV12 PACKAGE排列,四通道,RGBA图像 NV12图像
CVT_PA_RGBA2NV21 PACKAGE排列,四通道,RGBA图像 NV21图像
CVT_NV122PA_RGB NV12图像 PACKAGE排列,三通道,RGB图像
CVT_NV212PA_RGB NV21图像 PACKAGE排列,三通道,RGB图像
CVT_NV122PA_BGR NV12图像 PACKAGE排列,三通道,BGR图像
CVT_NV212PA_BGR NV21图像 PACKAGE排列,三通道,BGR图像
CVT_I4202PA_BGR I420图像 PACKAGE排列,三通道,BGR图像
CVT_NV122PA_BGRA NV12图像 PACKAGE排列,四通道,BGRA图像
CVT_NV212PA_BGRA NV21图像 PACKAGE排列,四通道,BGRA图像
CVT_NV122PA_RGBA NV12图像 PACKAGE排列,四通道,RGBA图像
CVT_NV212PA_RGBA NV21图像 PACKAGE排列,四通道,RGBA图像
CVT_PA_BGR2PL_BGR PACKAGE排列,三通道,BGR图像 PLANAR排列,三通道,BGR图像
CVT_PL_BGR2PA_BGR PLANAR排列,三通道,BGR图像 PACKAGE排列,三通道,BGR图像
CVT_PA_GRAY2PA_BGR565 单通道,灰度图 PACKAGE排列,三通道,BGR图像
CVT_PA_BGR2PA_BGR565 PACKAGE排列,三通道,BGR图像 PACKAGE排列,三通道,BGR图像(存储位数不一样)
CVT_PA_RGB2PA_BGR565 PACKAGE排列,三通道,RGB图像 PACKAGE排列,三通道,BGR图像
CVT_PA_BGRA2PA_BGR565 PACKAGE排列,四通道,BGRA图像 PACKAGE排列,三通道,BGR图像
CVT_PA_RGBA2PA_BGR565 PACKAGE排列,四通道,RGBA图像 PACKAGE排列,三通道,BGR图像

FlipType

说明: 翻转类型枚举

enum class FlipType {
    X = 0,  // 沿X轴翻转
    Y,      // 沿Y轴翻转
    XY,     // 沿XY轴翻转
};

函数

cvt_color

声明文件: modules/img_transform/color_convert/interface/color_convert.h

int cvt_color(const Mat& src, Mat& dst, ColorConvertType cvt_type);

说明: 该接口主要用于输入图像数据连续的情况下,进行颜色空间转换,支持单通道、三通道,支持u8数据。

返回值为0表示转换成功,不为0则表示转换失败。

参数 类型 说明
src Mat 输入图像的Mat对象,务必确保其图像数据在内存中连续
dst Mat 输出图像的Mat对象
cvt_type ColorConvertType 颜色空间转换类型

int cvt_color(const Mat& src_y, Mat& src_u, Mat& src_v, Mat& dst, ColorConvertType cvt_type);

说明: 该接口主要用于对通道分离的YUV图像进行颜色空间转换,目前仅支持转成RGB。

返回值为0表示转换成功,不为0则表示转换失败。

参数 类型 说明
src_y Mat YUV图像的Y通道的Mat对象
src_u Mat YUV图像的U通道的Mat对象
src_v Mat YUV图像的V通道的Mat对象
dst Mat 输出图像的Mat对象
cvt_type ColorConvertType 颜色空间转换类型,仅支持CVT_I4202PA_BGR

copy_make_border

声明文件: modules/img_transform/copy_make_border/interface/copy_make_border.h

int copy_make_border(
        Mat& src,
        Mat& dst,
        int top,
        int bottom,
        int left,
        int right,
        BorderTypes border_type,
        const Scalar& value = Scalar());

说明: 边界填充方法。

返回值为0表示成功,不为0则失败。

参数 类型 说明
src Mat& 源图像,仅支持PACKAGE格式图像,支持int8、int16、int32、f32以及f64数据
dst Mat& 目标图像
top int 图像顶部需要填充的长度
bottom int 图像底部需要填充的长度
left int 图像左边需要填充的长度
right int 图像右边需要填充的长度
border_type BorderTypes 边界填充算法,目前只支持BORDER_CONSTANT
value const Scalar& 填充的像素值,默认为全0

crop

声明文件: modules/img_transform/crop/interface/crop.h

int crop(Mat& src, Mat& dst, Rect& drect);

说明: 根据源图像内的指定子矩形框进行扣图(目前仅支持PACKAGE排列的RGB颜色空间数据,支持多通道1-4)

返回值为0表示裁剪成功,不为0表示裁剪失败。

参数 类型 说明
src Mat& 源图像Mat对象
dst Mat& 输出图像Mat对象
drect Rect& 裁剪矩形框对象

flip

声明文件: modules/img_transform/flip/interface/flip.h

int flip(const Mat& src, Mat& dst, FlipType type);

说明: 图像翻转方法。

参数 类型 说明
src Mat& 源图像,支持单通道,三通道,支持u8/f32
dst Mat& 目标图像
type FlipType 翻转类型,支持X轴、Y轴、XY轴翻转

remap

声明文件: modules/img_transform/remap/interface/remap.h

int remap(
        const Mat& src,
        Mat& dst,
        const Mat& map1,
        const Mat& map2,
        InterpolationType inter_type = InterpolationType::INTER_LINEAR,
        BorderTypes border_method = BorderTypes::BORDER_CONSTANT,
        const Scalar border_value = {0});

说明: 重映射计算。

参数 类型 说明
src const Mat& 源图像,支持单通道、三通道,支持u8/f32
dst Mat& 目标图像
map1 const Mat& 表示(x,y)坐标点或是x坐标,类型为GRAY_S16或者GRAY_F32
map2 const Mat& 表示y坐标
inter_type InterpolationType 使用的插值算法,仅支持双线性插值
border_method BorderTypes 使用的边界填充算法,仅支持常量填充
border_value const Scalar 边界填充值

resize

声明文件: modules/img_transform/resize/interface/resize.h

int resize(
        Mat& src,
        Mat& dst,
        const Size& dsize,
        double fx = 0,
        double fy = 0,
        InterpolationType interpolation = InterpolationType::INTER_LINEAR);

说明: 图像缩放方法。

参数 类型 说明
src Mat 输入图像Mat对象,支持1,3,4通道
dst Mat 输出图像Mat对象
dsize Size 目标宽高size对象,若已同时设置fx与fy参数,此项可忽略
fx double 横向缩放系数(fx=目标宽度/输入图像宽度),若已设置dsize,此项可忽略
fy double 纵向缩放系数(fy=目前高度/输入图像高度),若已设置dsize,此项可忽略
interpolation InterpolationType 缩放插值计算方式,默认为双线性插值

transpose

声明文件: modules/img_transform/rotation/interface/rotation.h

int transpose(Mat& src, Mat& dst);

说明: 对源矩阵进行矩阵转置后输出结果至目标矩阵

返回值为0表示转置成功,不为0表示转置失败。

参数 类型 说明
src Mat& 源图像Mat对象引用,支持多通道,支持u8/f32
dst Mat& 输出图像Mat对象引用

subtract

声明文件: modules/img_transform/subtract/interface/subtract.h

函数原型

int subtract(const Mat& src, Scalar scalar, Mat& dst);

说明:矩阵减法,各个通道像素值减去对应的scalar对应值

参数 类型 说明
src const Mat& 原图像,仅支持f32,支持多通道
scalar Scalar 各通道需要减去的值
dst Mat& 目标图像

get_affine_transform

声明文件: modules/img_transform/warp_affine/interface/warp_affine.h

Mat get_affine_transform(const Point2f src[], const Point2f dst[]);

说明: 该接口主要根据输入的映射源点坐标集与目标坐标集,计算仿射变换的系数矩阵并返回。

返回值Mat不为空表示计算成功,为空表示计算失败。

参数 类型 说明
src const Point2f [] 源像素点对象集合
dst const Point2f [] 目标像素点对象集合

get_rotation_matrix_2D

声明文件: modules/img_transform/warp_affine/interface/warp_affine.h

Mat get_rotation_matrix_2D(Point2f center, double angle, double scale);

说明: 该接口主要根据输入的中心点、旋转角度、缩放比例等参数计算仿射变换的系数矩阵并返回。

返回值Mat不为空表示计算成功,为空表示计算失败。

参数 类型 说明
center Point2f 中心点坐标对象
angle double 旋转角度值
scale double 缩放系数值

warp_affine

声明文件: modules/img_transform/warp_affine/interface/warp_affine.h

int warp_affine(
        const Mat& src,
        Mat& dst,
        Mat& m,
        InterpolationType flag = InterpolationType::INTER_LINEAR,
        BorderTypes border_method = BorderTypes::BORDER_CONSTANT,
        const Scalar borderValue = {0});

说明: 执行从源图像到目标图像的仿射变换操作。

返回值为0表示变换成功,不为0表示变换失败。

参数 类型 说明
src const Mat& 源图像Mat对象常量引用,支持多通道,支持u8/f32
dst Mat& 输出图像Mat对象引用
m Mat& 变换系数矩阵**(目前仅支持:宽3,高2,单通道,float或double数据类型)**
flag InterpolationType 插值方式,仅支持双线性插值
border_method BorderTypes 边界填充方式,仅支持常量填充
borderValue const Scalar 填充的边界值

get_perspective_transform

声明文件: modules/img_transform/warp_perspective/interface/warp_perspective.h

Mat get_perspective_transform(const Point2f src[], const Point2f dst[]);

说明: 计算透视变换变换矩阵。

参数 类型 说明
src Point2f[] 源点
dst Point2f[] 目标点

warp_perspective

声明文件: modules/img_transform/warp_perspective/interface/warp_perspective.h

int warp_perspective(
        const Mat& src,
        Mat& dst,
        Mat& m,
        InterpolationType flag = InterpolationType::INTER_LINEAR,
        BorderTypes border_method = BorderTypes::BORDER_CONSTANT,
        const Scalar border_value = {0});

说明: 透视变换。

参数 类型 说明
src const Mat& src 源图,支持多通道,支持u8/f32
dst Mat& 目标图
m Mat& 透视变换矩阵
flag InterpolationType 插值变换,仅支持双线性插值
border_method BorderTypes 边界填充方式,仅支持常量填充
border_value const Scalar 填充的值

add_weighted

声明文件: modules/img_transform/add_weighted/interface/add_weigghted.h

int add_weighted(
        Mat& src1,
        double alpha,
        Mat& src2,
        double beta,
        double gamma,
        Mat& dst);

说明: 图像融合方法。

参数 类型 说明
src1 Mat& src 第一张输入图像,支持三通道
alpha double 第一张输入权重
src2 Mat& 第二张输入图像,支持三通道
beta double 第二张输入权重
gamma double 图一和图二融合后添加的值
dst Mat& 输出图像

extract_channel

声明文件: modules/img_transform/extract_channel/interface/extract_channel.h

void extract_channel(
        Mat& src,
        Mat& dst,
        int index);

说明: 原图中提取某一个指定的单通道。

参数 类型 说明
src Mat& 输入图像,仅支持PKG_BGR_U8格式图像
dst Mat& 输出图像
index int 提取通道的索引位置

img_calculation

函数

connected_components

声明文件: modules/img_calculation/connected_componets/interface/connected_components.h

int connected_components(
        const Mat& src,
        Mat& labels,
        int connectivity = 8,
        FCVImageType ltype = FCVImageType::GRAY_S32);

说明: 连通域计算。

参数 类型 说明
src const Mat& 源图像,仅支持单通道
labels Mat& 标签
connectivity int 连通数
ltype FCVImageType labels的数据类型,仅支持int32

find_homography

声明文件: modules/img_calculation/find_homography/interface/find_homography.h

Mat find_homography(
        std::vector<Point2f> src_points,
        std::vector<Point2f> dst_points,
        int method = 0);

说明: 二维点对最优单映射变换矩阵计算。

参数 类型 说明
src_points std::vector 源点
dst_points std::vector 目标点
method int 计算单映矩阵的方法,默认且仅支持=0

matrix_mul

声明文件: modules/img_calculation/matrix_mul/interface/matrix_mul.h

Mat matrix_mul(
        const Mat& src0,
        const Mat& src1);

说明: 矩阵乘。

参数 类型 说明
src0 const Mat& 点乘左边矩阵,支持f32c1和f64c1
src1 const Mat& 点乘右边矩阵,支持f32c1和f64c1

mean

直接均值计算

声明文件: modules/img_calculation/mean/interface/mean.h

Scalar mean(const Mat& src);

说明: 对输入Mat的各个通道,分别求均值并返回结果(支持格式为1~4通道RGB颜色空间图像数据)

参数 类型 说明
src const Mat& 源图像Mat对象引用

部分均值计算

Scalar mean(const Mat& src, const Mat& mask);

说明: 对输入Mat的各个通道,分别求均值并返回结果(支持格式为1~4通道RGB颜色空间图像数据), 根据Mask的值决定对应像素是否参与计算,例如mask元素值为0,则返回值为全0

参数 类型 说明
src const Mat& 源图像Mat对象引用
mask const Mat& 计算系数,支持单通道或者多通道(<=输入图像通道数),数据类型为无符号8位整数

指定区域均值计算

Scalar mean(const Mat& src, const Rect& rect);

说明: 对输入Mat的各个通道,分别求均值并返回结果(支持格式为1~4通道RGB颜色空间图像数据),仅计算指定矩形区域的像素。

参数 类型 说明
src const Mat& 源图像Mat对象引用
rect const Rect& 计算区域,仅支持输入图像的子矩阵

mean_stddev

声明文件: modules/img_calculation/mean/interface/mean.h

void mean_stddev(const Mat& src, Mat& mean, Mat& stddev);

说明: 对输入Mat的各个通道,分别求均值和标准差,计算结果以矩阵形式存储(支持格式为1~4通道RGB颜色空间图像数据)

参数 类型 说明
src const Mat& 源图像Mat对象引用
mean Mat& 计算均值结果,输出矩阵引用
stddev Mat& 计算标准差结果,输出矩阵引用

min_area_rect

声明文件: modules/img_calculation/min_area_rect/interface/min_area_rect.h

RotatedRect min_area_rect(std::vector<Point>& pts);

说明: 计算最小外接矩形。

参数 类型 说明
pts std::vector& pts

min_max_loc

声明文件: modules/img_calculation/min_max_loc/interface/min_max_loc.h

int min_max_loc(
        const Mat& src,
        double* min_val,
        double* max_val,
        Point* min_loc,
        Point* max_loc,
        const Mat& mask = Mat());

说明: 计算最大、最小值。

参数 类型 说明
src const Mat& 源图,仅支持单通道
min_val double* 存储最小值的地址
max_val double* 存储最大值的地址
min_loc Point* 存储最小值在原图中的位置
max_loc Point* 存储最大值在原图中的位置
mask const Mat& 指定参与计算的范围,与原图同样大小的gray_u8数据

norm

声明文件: modules/img_calculation/norm/interface/norm.h

double norm(Mat& src, NormType norm_type = NormType::NORM_L2);

说明: 范数计算。

参数 类型 说明
src Mat& 源图,支持1-4通道
norm_type NormType 范数计算类型,支持L1、L2、INF

fusion_api

函数

nv12_to_resize_to_bgr

声明文件: modules/fusion_api/y420sp_to_resize_to_bgr/interface/y420sp_to_resize_to_bgr.h

int nv12_to_resize_to_bgr(
        Mat& src,
        Mat& dst,
        Size size = Size(0, 0),
        InterpolationType interpolation = InterpolationType::INTER_LINEAR);

说明: 对输入NV12格式源图像,缩放至目标图像大小,并同时转换为PACKAGE_BGR_U8格式。

返回值为0表示运行成功,不为0表示运行失败

参数 类型 说明
src Mat& 源图像Mat对象引用,u8数据
dst Mat& 输出图像Mat对象引用,u8数据
size Size 指定输出图像的大小,与源图像大小不一致时会进行缩放
interpolation InterpolationType 使用的插值算法,仅支持双线性插值和最近邻插值

nv21_to_resize_to_bgr

声明文件: modules/fusion_api/y420sp_to_resize_to_bgr/interface/y420sp_to_resize_to_bgr.h

int nv21_to_resize_to_bgr(
        Mat& src,
        Mat& dst,
        Size size = Size(0, 0),
        InterpolationType interpolation = InterpolationType::INTER_LINEAR);

说明: 对输入NV21格式源图像,缩放至目标图像大小,并同时转换为PACKAGE_BGR_U8格式

返回值为0表示运行成功,不为0表示运行失败

参数 类型 说明
src Mat& 源图像Mat对象引用,u8数据
dst Mat& 输出图像Mat对象引用,u8数据
size Size 指定输出图像的大小,与源图像大小不一致时会进行缩放
interpolation InterpolationType 使用的插值算法,仅支持双线性插值和最近邻插值

normalize_to_submean_to_reorder

声明文件: modules/fusion_api/normalize_to_submean_to_reorder/interface/normalize_to_submean_to_reorder.h

int normalize_to_submean_to_reorder(
        const Mat& src,
        const std::vector<float>& mean_params,
        const std::vector<float>& std_params,
        const std::vector<uint32_t>& channel_reorder_index,
        Mat& dst,
        bool output_package = false);

说明:对输入PACKAGE_BGR_U8格式源图像,按次序进行如下操作:

①根据输入参数设定三个通道的减法系数mean_params与除法系数std_params;

②遍历所有像素,每个u8通道值转换为浮点数,然后先减去对应通道的减法系数,再除以对应通道的除法系数;

③将计算结果由PACKAGE分布转换为PLANAR分布;

④根据输入的channel_reorder_index参数对各个通道planar顺序进行重新排序。

⑤输出package或者planar格式数据

返回值为0表示运行成功,不为0表示运行失败

参数 类型 说明
src Mat& 源图像Mat,支持bgr/rgb u8/f32数据
mean_params const std::vector& 三通道减法系数
std_params const std::vector& 三通道除法系数
channel_reorder_index const std::vector<uint32_t>& 通道重排序索引,注:该参数支持为空对象引用(即不重排序),非空对象引用,则实际元素取值范围仅限[0, 1, 2]
dst Mat& 输出图像Mat
output_package bool 输出数据是否为package格式,false:planar, true:package

bgr_to_rgba_with_mask

声明文件: modules/fusion_api/bgr_to_rgba_with_mask/interface/bgr_to_rgba_with_mask.h

int bgr_to_rgba_with_mask(Mat& src, Mat& mask, Mat& dst);

说明: 输入bgr三通道package格式u8图像,与单通道u8图像(Alpha通道),输出rgba四通道package格式u8图像。

返回值为0表示运行成功,不为0表示运行失败

参数 类型 说明
src Mat& 源图像Mat,仅支持三通道、u8、package格式数据
mask Mat& Alpha通道 单通道u8
dst Mat& 输出图像Mat

split_to_memcpy

声明文件: modules/fusion_api/split_to_memcpy/interface/split_to_memcpy.h

int split_to_memcpy(const Mat& src, float* dst);

说明: 输入bgr三通道package格式float图像,转换为planar形式,并拷贝至指定目标地址

返回值为0表示运行成功,不为0表示运行失败。

参数 类型 说明
src Mat& 源图像Mat,注:仅支持三/四通道package格式float图像
dst float* 输出数据地址

bgra_to_resize_to_bgr

声明文件: modules/fusion_api/bgra_to_resize_to_bgr/interface/bgra_to_resize_to_bgr.h

int bgra_to_resize_to_bgr(
    Mat& src,
    Mat& dst,
    const Size& dsize,
    InterpolationType interpolation = InterpolationType::INTER_LINEAR);

说明: 输入bgra四通道package格式图像,转换为bgr三通道package格式,并进行缩放。

返回值为0表示运行成功,不为0表示运行失败。

参数 类型 说明
src Mat& 源图像,支持u8数据
dst Mat& 目标图像,支持u8数据
dsize const Size& 目标图像大小
interpolation InterpolationType 插值方式,仅支持双线性插值

img_draw

枚举类型

LineType

enum class LineType {
    FILLED = -1,
    LINE_4 = 4,   //!< 4-connected line
    LINE_8 = 8,   //!< 8-connected line
    LINE_AA = 16  //!< antialiased line, not support now
};

函数

circle

声明文件: modules/img_draw/circle/interface/circle.h

void circle(Mat& img,
        Point center,
        int radius,
        const Scalar& color,
        int thickness = 1,
        LineType line_type = LineType::LINE_8,
        int shift = 0);

说明: 绘制圆形。

参数 类型 说明
img Mat& 源图像
center Point 中心点坐标
radius int 半径
color const Scalar 颜色
thickness int 正数,表示组成圆的线条的粗细程度。否则,表示圆是否被填充
line_type LineType 圆边界类型,支持LINE_4,LINE_8
shift int 中心坐标和半径值中的小数位数

line

声明文件: modules/img_draw/line_poly/interface/line_poly.h

void line(Mat& img,
        Point pt1,
        Point pt2,
        const Scalar& color,
        int thickness = 1,
        LineType line_type = LineType::LINE_8,
        int shift = 0);

说明: 绘制直线。

参数 类型 说明
img Mat& 源图像
pt1 Point 直线端点坐标
pt2 Point 直线端点坐标
color const Scalar 颜色
thickness int 正数,表示组成圆的线条的粗细程度。否则,表示圆是否被填充
line_type LineType 边界类型
shift int 坐标点小数点位数

fill_poly

声明文件: modules/img_draw/line_poly/interface/line_poly.h

void fill_poly(Mat& img,
        const Point** pts,
        const int* npts,
        int ncontours,
        const Scalar& color,
        LineType lineType = LineType::LINE_8,
        int shift = 0,
        Point offset = Point(0, 0));

说明: 多边形绘制填充。

参数 类型 说明
img Mat& 源图像
pts const Point** pts 多边形曲线数组
npts const int* 多边形顶点计数器数组
ncontours int 曲线数
color const Scalar 颜色
line_type LineType 边界类型
shift int 坐标点小数点位数
offset Point 轮廓点偏移量

poly_lines

声明文件: modules/img_draw/poly_lines/interface/po**_lines.h

int poly_lines(Mat& img,
        const Point2l* v,
        int count,
        bool is_closed,
        const void* color,
        int thickness,
        LineType line_type,
        int shift);

说明: 多边形绘制。

参数 类型 说明
img Mat& 源图像
v const Point2l* 多边形曲线数组
count int 绘制多边形的个数
is_closed bool 表示多边形是否闭合, 1:闭合,0:不闭合
thickness int 线条宽度
line_type int 边界类型
shift int 坐标点小数点位数

media_io

函数

imread

声明文件: modules/imgcodecs/interface/imgcodecs.h

Mat imread(const std::string& file_name, int flags = 0);

说明: 读取指定路径的图像文件,文件格式及后缀仅支持jpg或jpeg,返回Mat对象(仅支持PKG_BGR_U8或GRAY_U8

返回对象非空表示运行成功,为空则表示运行失败

参数 类型 说明
file_name const std::string& 待读取文件路径
flags int 保留字段,可忽略

imwrite

声明文件: modules/imgcodecs/interface/imgcodecs.h

bool imwrite(const std::string& file_name, Mat& img, int quality = 95);

说明: 将指定Mat对象写为图像文件,文件格式及后缀仅支持jpg或jpeg,输入Mat对象仅支持PKG_BGR_U8或GRAY_U8

返回true表示运行成功,false则表示运行失败

参数 类型 说明
file_name const std::string& 待写入文件名
img Mat& 输出图像Mat对象
quality int 图像压缩质量,值范围[0~100]

imdecode

声明文件: modules/imgcodecs/interface/imgcodecs.h

Mat imdecode(const uint8_t* buf, const size_t size, int flags = 0);

说明: 对输入标准JPEG或PNG数据,进行解码,返回Mat对象(仅支持PKG_BGR_U8或GRAY_U8)

返回对象非空表示运行成功,为空则表示运行失败

参数 类型 说明
buf const uint8_t* 原始数据地址
size const size_t 原始数据长度
flags int 保留字段,可忽略

imencode

声明文件: modules/imgcodecs/interface/imgcodecs.h

bool imencode(const std::string& ext, const Mat& img, std::vector<uint8_t>& buf, int quality = 95);

说明: 将指定Mat对象编码为标准JPEG或PNG格式数据,通过ext后缀进行格式指定,输入Mat对象仅支持PKG_BGR_U8或GRAY_U8

返回true表示运行成功,false则表示运行失败

参数 类型 说明
ext const std::string& 编码格式后缀,.jpg.jpeg表明为JPEG编码,.png表明为PNG编码
img Mat& 输出图像Mat对象
buf std::vector<uint8_t>& 结果数据
quality int 图像压缩质量,值范围[0~100](注:仅影响JPEG格式编码)

math_operator

函数

get_l2

声明文件: modules/math_operator/vector_operator/interface/vector_operator.h

函数原型

float get_l2(int dimension, float* vector);

说明: 计算给定数组的平方和。

参数 类型 说明
dimension int 向量长度
vector float* 数据指针

dot_vectors

声明文件: modules/math_operator/vector_operator/interface/vector_operator.h

函数原型

void dot_vectors(int dimension, float* v0, float* v1, float* dot);

说明: 向量点乘。

参数 类型 说明
dimension int 向量长度
v0 float* 输入数据指针
v1 float* 输入数据指针
dot float* 输出数据指针

Clone this wiki locally