STL容器之Set,MultiSet

本文详细介绍了Set与MultiSet这两种关联容器的特点与使用方法,包括它们的创建、元素插入删除、迭代器操作等,并探讨了这些容器如何自动排序及其背后的二叉树实现原理。
Set,MultiSet都是关联容器,它们的元素是按照一定的顺序排列的并且排列是自动的。关联容器代表性的是用二叉树实现。每一个元素有一个父亲和两个孩子。并且父元素比它的左孩子 要大,比它的右孩子要小。
Set:所有元素不能是重复的。并且按照一定的顺序排列,默认是从小到大。
MultiSet:和Set差不多,只不多它支持重复的元素。

它们的元素自动排序,默认是<。元素间的比较是很严格的:
1.它们是对称的:This means for a predicate op(): If op(x,y) is true, then op(y,x) is false
2.它们是传递的:This means for a predicate op(): If op(x,y) is true and op (y,z) is true, then op(x,z) is true.
3.它们不得是反射的:This means for a predicate op(): op(x,x) is always false.
它们的特点:
1.       它们不支持直接访问元素
2.       间接访问通过Const的迭代器,从迭代器角度来看,它的值是Const的。
Create, Copy, and Destroy Operations
set c                                    Creates an empty set/multiset without any elements
set c(op)                             Creates an empty set/multiset that uses op as the sorting criterion
set c1(c2)                            Creates a copy of another set/multiset of the same type (all elements arecopied)
set c(beg,end)                    Creates a set/multiset initialized by the elements of the range [beg,end)
set c(beg,end,op)               Creates a set/multiset with the sorting criterion op initialized by the elements of the range [beg,end)
c.~set() Destroys all elements and frees the memory
comparisons Operator
c.size() Returns the actual number of elements
c.empty () Returns whether the container is empty (equivalent to size()==0, but might be faster)
c.max_size() Returns the maximum number of elements possible
c1 == c2 Returns whether c1 is equal to c2
c1 != c2 Returns whether c1 is not equal to c2 (equivalent to ! (c1==c2) )
c1 < c2 Returns whether c1 is less than c2
c1 > c2 Returns whether c1 is greater than c2 (equivalent to c2<c1)
c1 <= c2 Returns whether c1 is less than or equal to c2 (equivalent to ! (c2<c1) )
c1 >= c2 Returns whether c1 is greater than or equal to c2 (equivalent to !(c1<c2))

元素位置操作:
count (elem)                    Returns the number of elements with value elem
find(elem)                        Returns the position of the first element with value elem or end()
lower _bound(elem)        Returns the first position, where elem would get inserted (the first element>= elem)
upper _bound(elem)       Returns the last position, where elem would get inserted (the firstelement > elem)
equal_range(elem)          Returns the first and last position, where elem would get inserted (the range of elements == elem)

Swap 操作:
c1 = c2            Assigns all elements of c2 to c1
c1.swap(c2)     Swaps the data of c1 and c2
swap(c1,c2)     Same (as global function)

iterators Operator
c.begin()           Returns a bidirectional iterator for the first element (elements are considered const)
c.end()             Returns a bidirectional iterator for the position after the last element (elements are considered const)
c.rbegin()          Returns a reverse iterator for the first element of a reverse iteration
c.rend()             Returns a reverse iterator for the position after the last element of a reverse teration

Insert ,Erase,Clear Operators
c. insert(elem)            Inserts a copy of elem and returns the position of the new element and,for sets, whether it succeeded
c. insert(pos,elem)     Inserts a copy of elem and returns the position of the new element 
c. insert(beg,end)      Inserts a copy of all elements of the range [beg,end) (returns nothing)
c. erase(elem)          Removes all elements with value elem and returns the number of removed elements
c. erase(pos)            Removes the element at iterator position pos (returns nothing)
c.erase(beg,end)      Removes all elements of the range [beg,end) (returns nothing)
c. clear()                 Removes all elements (makes the container empty)

Set对元素的要求,默认构造函数,Operator<,赋值操作法,拷贝构造函数,Operator==,在析构函数里处理掉。
本指南详细阐述基于Python编程语言结合OpenCV计算机视觉库构建实时眼部状态分析系统的技术流程。该系统能够准确识别眼部区域,并对眨眼动作与持续闭眼状态进行判别。OpenCV作为功能强大的图像处理工具库,配合Python简洁的语法特性与丰富的第三方模块支持,为开发此类视觉应用提供了理想环境。 在环境配置阶段,除基础Python运行环境外,还需安装OpenCV核心模块与dlib机器学习库。dlib库内置的HOG(方向梯度直方图)特征检测算法在面部特征定位方面表现卓越。 技术实现包含以下关键环节: - 面部区域检测:采用预训练的Haar级联分类器或HOG特征检测器完成初始人脸定位,为后续眼部分析建立基础坐标系 - 眼部精确定位:基于已识别的人脸区域,运用dlib提供的面部特征点预测模型准确标定双眼位置坐标 - 眼睑轮廓分析:通过OpenCV的轮廓提取算法精确勾勒眼睑边缘形态,为状态判别提供几何特征依据 - 眨眼动作识别:通过连续帧序列分析眼睑开合度变化,建立动态阈值模型判断瞬时闭合动作 - 持续闭眼检测:设定更严格的状态持续时间与闭合程度双重标准,准确识别长时间闭眼行为 - 实时处理架构:构建视频流处理管线,通过帧捕获、特征分析、状态判断的循环流程实现实时监控 完整的技术文档应包含模块化代码实现、依赖库安装指引、参数调优指南及常见问题解决方案。示例代码需具备完整的错误处理机制与性能优化建议,涵盖图像预处理、光照补偿等实际应用中的关键技术点。 掌握该技术体系不仅有助于深入理解计算机视觉原理,更为疲劳驾驶预警、医疗监护等实际应用场景提供了可靠的技术基础。后续优化方向可包括多模态特征融合、深度学习模型集成等进阶研究领域。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值