QT opencv 学习day02 基本数据结构 point Scalar Size Rect Mat 等等

news2024/10/6 4:05:23

1.point   (画点)

1. 函数原型: 

//二维的点
typedef Point_<int> Point2i;
typedef Point_<int64> Point2l;
typedef Point_<float> Point2f;
typedef Point_<double> Point2d;
typedef Point2i Point;


//三维的点
typedef Point3_<int> Point3i;
typedef Point3_<float> Point3f;
typedef Point3_<double> Point3d;

二维的结构体模板 :Point_

template<typename _Tp> class Point_
{
public:
    typedef _Tp value_type;

    //! default constructor
    Point_();
    Point_(_Tp _x, _Tp _y);
    Point_(const Point_& pt);
    Point_(const Size_<_Tp>& sz);
    Point_(const Vec<_Tp, 2>& v);

    Point_& operator = (const Point_& pt);
    //! conversion to another data type
    template<typename _Tp2> operator Point_<_Tp2>() const;

    //! conversion to the old-style C structures
    operator Vec<_Tp, 2>() const;

    //! dot product
    _Tp dot(const Point_& pt) const;
    //! dot product computed in double-precision arithmetics
    double ddot(const Point_& pt) const;
    //! cross-product
    double cross(const Point_& pt) const;
    //! checks whether the point is inside the specified rectangle
    bool inside(const Rect_<_Tp>& r) const;
    _Tp x; //!< x coordinate of the point
    _Tp y; //!< y coordinate of the point
};

三维的结构体模板 :Point3_

template<typename _Tp> class Point3_
{
public:
    typedef _Tp value_type;

    //! default constructor
    Point3_();
    Point3_(_Tp _x, _Tp _y, _Tp _z);
    Point3_(const Point3_& pt);
    explicit Point3_(const Point_<_Tp>& pt);
    Point3_(const Vec<_Tp, 3>& v);

    Point3_& operator = (const Point3_& pt);
    //! conversion to another data type
    template<typename _Tp2> operator Point3_<_Tp2>() const;
    //! conversion to cv::Vec<>
#if OPENCV_ABI_COMPATIBILITY > 300
    template<typename _Tp2> operator Vec<_Tp2, 3>() const;
#else
    operator Vec<_Tp, 3>() const;
#endif

    //! dot product
    _Tp dot(const Point3_& pt) const;
    //! dot product computed in double-precision arithmetics
    double ddot(const Point3_& pt) const;
    //! cross product of the 2 3D points
    Point3_ cross(const Point3_& pt) const;
    _Tp x; //!< x coordinate of the 3D point
    _Tp y; //!< y coordinate of the 3D point
    _Tp z; //!< z coordinate of the 3D point
};

 

2.参数: 

Point2i(int x,int y)参数1: int  参数2: int
Point2l(int64 x,int64 y )参数1:  int64  参数2: int64
Point2f(float x, float y )参数1: float  参数2: float
Point2d(double x, doubley)参数1: double 参数2: double
Point3i(int x,int y ,int z)参数1: int  参数2: int
Point3f(float x, float y, float z)参数1 float  参数2: float  参数3: float
Point3d(double x, double y ,double z)参数1:double  参数2:double 参数3 : double

 3. 使用方法

 cv::Point2i a1(1,1);//二维 int 类型的点

 cv::Point2l a2(16,16);//二维 int64 类型的点

 cv::Point2f a3(1.1,1.1);//二维 float 类型的点

 cv::Point2d a4(1.1,1.1);//二维 double 类型的点

 cv::Point3i a5(1,1,1);//三维 int 类型的点

 cv::Point3f a6(1.1,1.2,1.3);//三维 float 类型的点

 cv::Point3d a7(1.1,1.2,1.3);//三维  double  类型的点


2. Scalar  颜色 (RGB)

1. 函数原型:

typedef Scalar_<double> Scalar;

class Scalar_ 结构体:

template<typename _Tp> class Scalar_ : public Vec<_Tp, 4>
{
public:
    //! default constructor
    Scalar_();  //构造
    Scalar_(_Tp v0, _Tp v1, _Tp v2=0, _Tp v3=0);//两位的构造
    Scalar_(_Tp v0);//一位的构造

    template<typename _Tp2, int cn>
    Scalar_(const Vec<_Tp2, cn>& v);

    //! returns a scalar with all elements set to v0
    static Scalar_<_Tp> all(_Tp v0);

    //! conversion to another data type
    template<typename T2> operator Scalar_<T2>() const;

    //! per-element product
    Scalar_<_Tp> mul(const Scalar_<_Tp>& a, double scale=1 ) const;

    //! returns (v0, -v1, -v2, -v3)
    Scalar_<_Tp> conj() const;

    //! returns true iff v1 == v2 == v3 == 0
    bool isReal() const;
};

2. 使用方法

    cv::Scalar s1;//空构造
    cv::Scalar s2(s1);//拷贝构造
    cv::Scalar s3(255);//赋值构造1
    cv::Scalar s4(255,255,255,0);//赋值构造2
    cv::Scalar s5(255,255,255,0);//定义点s5
    cv::Scalar s6(10,10,10,0);//定义点s6
    cv::Scalar s7;//定义点s7
    s7=s5.mul(s6);//s7=s5*s6

    //scalar(g,b,r)可以用于表示色彩。

    //scalar(255)表示全白。

3.Size  (大小)

1.函数原型:

typedef Size_<int> Size2i;
typedef Size_<int64> Size2l;
typedef Size_<float> Size2f;
typedef Size_<double> Size2d;
typedef Size2i Size;

 Size_ 结构体 模板:

template<typename _Tp> class Size_
{
public:
    typedef _Tp value_type;

    //! default constructor
    Size_();
    Size_(_Tp _width, _Tp _height);
    Size_(const Size_& sz);
    Size_(const Point_<_Tp>& pt);

    Size_& operator = (const Size_& sz);
    //! the area (width*height)
    _Tp area() const;
    //! true if empty
    bool empty() const;

    //! conversion of another data type.
    template<typename _Tp2> operator Size_<_Tp2>() const;

    _Tp width; //!< the width
    _Tp height; //!< the height
};

2. 使用方法:

Size2i s1(1,1);
Size2l s2(100,200);
Size2f s3(1.1,1.2);
Size2d s4(1.3,1.4);


 4. Rect   (矩形)

1.函数模型:

typedef Rect_<int> Rect2i;
typedef Rect_<float> Rect2f;
typedef Rect_<double> Rect2d;
typedef Rect2i Rect; //Rect  默认是 Rect2i

Rect_ 结构体模板:

template<typename _Tp> class Rect_
{
public:
    typedef _Tp value_type;

    //! default constructor
    Rect_();
    Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height);
    Rect_(const Rect_& r);
    Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz);
    Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2);

    Rect_& operator = ( const Rect_& r );
    //! the top-left corner
    Point_<_Tp> tl() const;
    //! the bottom-right corner
    Point_<_Tp> br() const;

    //! size (width, height) of the rectangle
    Size_<_Tp> size() const;
    //! area (width*height) of the rectangle
    _Tp area() const;
    //! true if empty
    bool empty() const;

    //! conversion to another data type
    template<typename _Tp2> operator Rect_<_Tp2>() const;

    //! checks whether the rectangle contains the point
    bool contains(const Point_<_Tp>& pt) const;

    _Tp x; //!< x coordinate of the top-left corner
    _Tp y; //!< y coordinate of the top-left corner
    _Tp width; //!< width of the rectangle
    _Tp height; //!< height of the rectangle
};

2. 使用方法

方法一: 先创两个点, 再创建一个矩形

//定义起点和终点
    cv::Point p1(1,1);
    cv::Point p2(2,2);
    cv::Rect r5(p1,p2);

方法二: 先创建一个点  再创建一个 尺寸

//定义起点和尺寸
    cv::Point p1(1,1);
    cv::Size s1(1,1);
    cv::Rect r4(p1,s1);

方法三: 填写每个参数

//定义起点、宽度、高度
    int x = 10;
    int y = 10;
    int w = 100;
    int h = 100;
    cv::Rect r3(x,y,w,h);

方法四 : 拷贝构造

3.相关的函数

    //定义一个矩形
    int p = r3.x;
    int q = r3.y;
    int m = r3.width;
    int n = r3.height;
 
    //矩形的面积
    int area = r3.area();
 
    //矩形的尺寸
    cv::Size size = r3.size();
 
    //矩形的左上点
    cv::Point a = r3.tl();
 
    //矩形的右下点
    cv::Point b = r3.br();
 
    //是否包含点a
    bool i = r3.contains(a);


5.RotatedRect   (旋转矩形)

1.函数原型: 

1. RotatedRect();
2. RotatedRect(const Point2f& center, const Size2f& size, float angle);
3. RotatedRect(const Point2f& point1, const Point2f& point2, const Point2f& point3);

解读: 
1. RotatedRect()  空构造

2. RotatedRect(const Point2f& center, const Size2f& size, float angle);

参数:

center : 矩形的中心点

size :   矩形的宽度和高度  

angle :  顺时针旋转的角度


3. RotatedRect(const Point2f& point1, const Point2f& point2, const Point2f& point3);

参数: 矩形,顺时针的三个点。

2.使用方法:

    //定义3个点
    cv::Point p1(0,0);
    cv::Point p2(100,0);
    cv::Point p3(0,100);
    //定义一个旋转矩形
    cv::RotatedRect rr3(p1,p2,p3);
 
    //定义一个中心点
    cv::Point p0(500,500);
    //定义一个大小
    cv::Size sz(100,100);
    //定义一个旋转矩形
    cv::RotatedRect rr4(p0,sz,45);

3.相关函数

    //定义一个矩形
    cv::RotatedRect rr5;
    //获取矩形的中心点坐标
    cv::Point center5 = rr5.center;
    //获取矩形的大小
    cv::Size sz5 = rr5.size;
    //获取矩形的旋转角度
    float angle = rr5.angle;
    //获取矩形的4个端点
    cv::Point2f pts[4];
    rr5.points(pts);



6. Matx (矩阵)

1. 函数原型:

typedef Matx<float, 1, 2> Matx12f;
typedef Matx<double, 1, 2> Matx12d;
typedef Matx<float, 1, 3> Matx13f;
typedef Matx<double, 1, 3> Matx13d;
typedef Matx<float, 1, 4> Matx14f;
typedef Matx<double, 1, 4> Matx14d;
typedef Matx<float, 1, 6> Matx16f;
typedef Matx<double, 1, 6> Matx16d;

typedef Matx<float, 2, 1> Matx21f;
typedef Matx<double, 2, 1> Matx21d;
typedef Matx<float, 3, 1> Matx31f;
typedef Matx<double, 3, 1> Matx31d;
typedef Matx<float, 4, 1> Matx41f;
typedef Matx<double, 4, 1> Matx41d;
typedef Matx<float, 6, 1> Matx61f;
typedef Matx<double, 6, 1> Matx61d;

typedef Matx<float, 2, 2> Matx22f;
typedef Matx<double, 2, 2> Matx22d;
typedef Matx<float, 2, 3> Matx23f;
typedef Matx<double, 2, 3> Matx23d;
typedef Matx<float, 3, 2> Matx32f;
typedef Matx<double, 3, 2> Matx32d;

typedef Matx<float, 3, 3> Matx33f;
typedef Matx<double, 3, 3> Matx33d;

typedef Matx<float, 3, 4> Matx34f;
typedef Matx<double, 3, 4> Matx34d;
typedef Matx<float, 4, 3> Matx43f;
typedef Matx<double, 4, 3> Matx43d;

typedef Matx<float, 4, 4> Matx44f;
typedef Matx<double, 4, 4> Matx44d;
typedef Matx<float, 6, 6> Matx66f;
typedef Matx<double, 6, 6> Matx66d;

2.使用方法

    //空构造
    cv::Matx33f m1;
 
    //拷贝构造
    cv::Matx33f m2(m1);
 
    //赋值构造
    cv::Matx33f m3(1,2,3,
                   4,5,6,
                   7,8,9);

     //取值
    float c = m3(1,1);//取第二行、第二列的数据
    
    

 3.相关函数

    //矩阵计算
    cv::Matx33f m1;
    cv::Matx33f m2;
    cv::Matx33f m3;
 
    m1=m2.t();//转置
    m3=m1.mul(m2);//点乘



7.Range  (定义一个范围)

1.函数原型 

class CV_EXPORTS Range
{
public:
    Range();
    Range(int _start, int _end);
    int size() const;
    bool empty() const;
    static Range all();

    int start, end;
};

2. 使用方法

    cv::Range ran(0,10);//定义一个范围
 
    int a = ran.start;//取范围的起点
    int b = ran.end;//取范围的终点
 
    qDebug()<<a;//打印a
    qDebug()<<b;//打印b




8.Ptr     (指针)

opencv中的Ptr指其使用的智能指针,指的是Template class for smart reference-counting pointers(智能指针模板类)

ptr是在访问图片中像素时的操作,如image.ptr<uchar>(5),指的是访问image图片的第6行像素值。

1.使用方法:

    //构造形式1
    cv::Ptr<Matx33d>p1(new cv::Matx33d);
 
 
    //构造形式2
    cv::Ptr<Matx33d>p2=makePtr<Matx33d>;

2.相关函数

    //判断是否为空
    bool b1 = p1.empty();
    
 
    //主动释放
    p2.release();



9.Mat  (图片)

1.函数原型:

1. Mat();  //空构造
2. Mat(int rows, int cols, int type);//
3. Mat(Size size, int type);
4. Mat(int rows, int cols, int type, const Scalar& s);
5. Mat(Size size, int type, const Scalar& s);
6. Mat(int ndims, const int* sizes, int type);
7. Mat(const std::vector<int>& sizes, int type);
8. .........

2.使用方法

    //空构造
    cv::Mat mat1;
 
    //赋值构造(大概有29种重载,只示例了其中一种)
    cv::Mat mat2(cv::Size sz,int type);
 
    //读取一张图片,将数据存储到mat3,然后进行处理
    cv::Mat mat3 = imread("C:/opencv/123.jpg");
 
    //特殊构造
    Mat mat4 = Mat::zeros(10,10,CV_32F);//全黑(全部为0)
    Mat mat5 = Mat::ones(10,10,CV_32F);//全白(全部为1)
    Mat mat6 = Mat::ones(10,10,CV_32F);//对角为白,其余为黑(对角为1,其余为0)

 




本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/195997.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

EasyExcel 实现 批量生成多sheet多Excel打包zip下载

目录说明需求场景实现1、准备一个excel模板2、把整个excel模板放在resources里面3、重点代码效果图说明 需求场景 导出学校中高年级的学生信息&#xff0c;根据班级名称分组&#xff0c;一个班级一个excel导出&#xff0c;如果多个excel需要打包成zip压缩包下载&#xff0c;一…

Linux应用编程-音频应用编程-语音转文字项目

文章目录前言Linux语音识别alsa-lib简介&#xff1a;安装alsa-lib库&#xff1a;API调用录音相关概念样本长度&#xff08;Sample&#xff09;声道数&#xff08;channel&#xff09;帧&#xff08;frame&#xff09;周期&#xff08;period&#xff09;采样率&#xff08;Samp…

springboot整合JSR303参数校验与全局异常处理

一、前言 我们在日常开发中&#xff0c;避不开的就是参数校验&#xff0c;有人说前端不是会在表单中进行校验的吗&#xff1f;在后端中&#xff0c;我们可以直接不管前端怎么样判断过滤&#xff0c;我们后端都需要进行再次判断&#xff0c;为了安全。因为前端很容易拜托&#…

[面试八股] Mysql

1、Mysql中的索引类型 &#xff08;1&#xff09;普通索引&#xff08;2&#xff09;唯一索引&#xff08;3&#xff09;主键索引&#xff08;4&#xff09;组合索引&#xff08;5&#xff09;全文索引 缺点 1、虽然索引大大提高了查询速度&#xff0c;同时却会降低更新表的速…

Mysql高级部分学习笔记(二)——事务锁

一、buffer pool 1.1 缓冲池&#xff08;buffer pool&#xff09; 简介&#xff1a;InnoDB是基于磁盘存储的&#xff0c;并将其中的数据按页的方式进行管理。因此InnoDB可视为基于磁盘的数据库系统。由于CPU的速度和磁盘IO速度的巨大鸿沟&#xff0c;需要**缓冲池(buffer poo…

windows下通过uiAutomation技术获取ui元素

最近接个需求&#xff0c;要求获取 windows 下 ui 元素&#xff0c;经一番搜索后了解到可通过工具 UISpy.exe 或 inspect.exe 来进行查看。以软件 davinci resolve 为例&#xff1a; 右侧即 UISpy 工具&#xff0c;根据内容可以看出已捕获到 davinci 界面的各属性及对应值。而 …

ItextPdf 字体显示差异分析与处理

ItextPdf 同span下字体显示差异分析与处理 在文章itext7 字体问题解答与相应源代码分析 中是分析了框架的字体设置与相关代码&#xff0c;在本篇文章里将对其生效效果进行分析和相关问题进行处理&#xff08;可持续更新&#xff0c;问题请留言&#xff09; 问题一 问题说明&…

将无风险资产与两种风险资产进行组合

目录 最优风险资产组合。 计算权重的公式。 应用。 最优风险资产组合。 曲线 AB 是两种风险资产的权衡取舍线。 A 点为资产组合中仅有风险资产 1 的情况。将 O 点与 A 点相连&#xff0c;便得到无风险资产与单个风险资产的权衡取舍线。 实际上&#xff0c;曲线 AB 上任一点…

【青训营】分布式理论初探

本文内容总结自 字节跳动青年训练营 第五届后端组 分布式理论初探 一、概述 分布式系统是计算机程序的集合&#xff0c;这些程序利用横跨多个独立计算节点的计算资源实现共同目标&#xff0c;可分为分布式计算、分布式存储、分布式数据库。 其优势是&#xff1a;去中心化、…

ESP32设备驱动-TEA5767收音机模块驱动

TEA5767收音机模块驱动 1、TEA5767介绍 TEA5767HN 是一款用于低压应用的单芯片电子调谐 FM 立体声收音机,具有完全集成的中频 (IF) 选择性和解调功能,频率范围从76—108MHZ自动数字调谐。 该收音机完全无需调整,高灵敏度,高稳定性,低噪音,收音模块。只需要最少的小型低…

Win10安装MySQL、Pycharm连接Mysql、Pycharm中运行django

目录 一、windows系统mysql相关操作 1、检查当前系统是否已安装mysql 1. 按win r 键&#xff08;调出运行窗口&#xff09; 2. 输入service.msc&#xff0c;点击[ 确定 】 3.打开服务列表 - 检查是否有mysql服务 2、windows安装mysql 1.下载mysql 2. 解压 mysql 到自己…

【面试题:三个线程轮流打印A ,B,C】

面试题&#xff1a;三个线程轮流打印A &#xff0c;B&#xff0c;C面试介绍说明思考方案代码实现Print 打印基类APrint 打印字符A 线程CPrint 打印字符C 线程PrintConstant 常量类StrRun 启动类测试结果总结面试介绍说明 当时是2022 年3月 在深圳面试的一家公司。由于疫情比较…

内网渗透(三)之基础知识-域环境的介绍和优点

系列文章 内网渗透(一)之基础知识-内网渗透介绍和概述 内网渗透(二)之基础知识-工作组介绍 注&#xff1a;阅读本编文章前&#xff0c;请先阅读系列文章&#xff0c;以免造成看不懂的情况&#xff01;&#xff01; 域介绍 域的介绍 Windows域是计算机网络的一种形式&#…

DMTet 阅读笔记

介绍 主页 https://nv-tlabs.github.io/DMTet/论文pdf https://nv-tlabs.github.io/DMTet/assets/dmtet.pdf视频汇报 https://slideslive.com/38967642/deep-marching-tetrahedra-a-hybrid-representation-for-highresolution-3d-shape-synthesis?refhomepage疑似代码 在nvdi…

【手写 Promise 源码】第十八篇 - EventLoop 简介

theme: fancy 一&#xff0c;前言 近期公司项目比较忙&#xff0c;粘了老博客几篇 Spring 源码来充数&#xff0c;周末腾出时间把 Promise 做个收尾&#xff1b; 在开始 EventLoop 前&#xff0c;我对 Promise 源码部分进行了简单回顾&#xff0c;并更新了【Promise 源码学习…

【链表面试题】解决环形链表和相交链表问题

在力扣上发现这样的几道题&#xff0c;尝试做了一下&#xff0c;也发现了一个关于这类题的一种做法&#xff1a;快慢指针的使用。废话不多说&#xff0c;上例题 目录 一、环形链表 1.定义&#xff08;概念&#xff09; 2.如何判断是否为环形链表 1.快慢指针 2.为什么快指针…

限期出国|CSC资助赴世界top50名校英国曼彻斯特大学访学

我们先为J老师40天获得佐治亚理工学院&#xff08;美国三大理工学院之一&#xff09;的访问学者邀请函&#xff0c;又成功申报CSC。后因其担心被美国拒签要求重新申请英国名校&#xff0c;10天后拿到跻身世界top50英国曼彻斯特大学的offer&#xff0c;后经ATAS审批、CSC改派、使…

linux基本功系列-help命令实战

文章目录前言&#x1f680;&#x1f680;&#x1f680;一. help命令介绍二. 语法格式及常用选项三. 参考案例3.1 显示某个命令的帮助信息3.2 查看某个命令的简述3.3 以伪man手册格式输出cd信息四. windows中的help总结前言&#x1f680;&#x1f680;&#x1f680; 想要学好Lin…

车载网络 - Autosar网络管理 - 基本概念

Autosar作为当前车载行业使用最为广泛的一种汽车开发系统架构&#xff0c;网上也有很多相关的介绍&#xff1b;不过我看很多有完整的来讲一下这个规范的&#xff0c;一般都是只讲了其中一部分&#xff0c;我这就准备搞出来一套完整版本的Autosar网络管理的规范、测试设计、自动…

新C++(7):多态那些事儿_下

"当人类悬浮到腐朽&#xff0c;有谁愿追随彗星漂流哦~"一、多态原理(1)虚函数表指针(虚表指针)紧接上一篇sizeof(Base)这一小段说起。class Base1 { public:void func(){} private:int _a; };class Base2 { public:virtual void func() {} private:int _a; };我们知道…