• opencv中的数据结构


    一、Vec向量模板类

    vector(向量):是C++中的一个类,它相当与一个动态数组,当无法知道自己需要的数组大小是,可以使用它节约空间

    Vec是opencv中的向量模板类,而opencv中常用的Vec3b,Vec3s

    其实看源码可以看到它的定义,它们都是Vec类只是用于不同数据类型:

    typedef Vec<uchar, 2> Vec2b;
    typedef Vec<uchar, 3> Vec3b;
    typedef Vec<uchar, 4> Vec4b;
    
    typedef Vec<short, 2> Vec2s;
    typedef Vec<short, 3> Vec3s;
    typedef Vec<short, 4> Vec4s;
    
    typedef Vec<ushort, 2> Vec2w;
    typedef Vec<ushort, 3> Vec3w;
    typedef Vec<ushort, 4> Vec4w;
    
    typedef Vec<int, 2> Vec2i;
    typedef Vec<int, 3> Vec3i;
    typedef Vec<int, 4> Vec4i;
    typedef Vec<int, 6> Vec6i;
    typedef Vec<int, 8> Vec8i;
    
    typedef Vec<float, 2> Vec2f;
    typedef Vec<float, 3> Vec3f;
    typedef Vec<float, 4> Vec4f;
    typedef Vec<float, 6> Vec6f;
    
    typedef Vec<double, 2> Vec2d;
    typedef Vec<double, 3> Vec3d;
    typedef Vec<double, 4> Vec4d;
    typedef Vec<double, 6> Vec6d;

    用法:

    获取某像素的颜色值:

    例如:

    cout<<img.at<Vec3b>(row,col)<<endl;//获取点(row,col)的b,g,r值

    二、Point类

    point是opencv中常见的数据结构,支持整型,浮点型等数据类型,常用于表示矩阵中某个点

    按照维度主要分为二维(Point2),三维(Point3)两个类型

    Point2产生的变种:为Point2i、Point2l、Point2f、Point2d,其中i代表int,l代表int64, f代表float,d代表double,

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

    Point3变种为:Point3i、Point3f、Point3d

    typedef Point3_<int> Point3i;
    typedef Point3_<float> Point3f;
    typedef Point3_<double> Point3d;

    用法

    获取某像素点的坐标

    例如:

    Point2f a;
    a.x = 2;
    a.y = 2;// a的坐标为(2,2)
    ///
    Point2f a=(2,1.5);
    注意这种用法是错误的。

    参考博客:https://blog.csdn.net/weixin_42730667/article/details/104099293

  • 相关阅读:
    网络设备
    Linux常用操作
    工作常用笔记
    性能测试问题总结
    mysql性能分析
    Java8新特性学习笔记-CompletableFuture
    Java语言定义的线程状态分析
    Gatling-插件开发
    RabbitMQ记录
    Go常用库
  • 原文地址:https://www.cnblogs.com/zhongllmm/p/16305806.html
Copyright © 2020-2023  润新知