opencv 中利用函数 findContours() 可以监测出物体的轮廓
drawContours() 可以画出物体的轮廓
- findContours()函数源码
void findContours(InputArray image, OutputArrayOfArrays contours,
OutputArray hierarchy, int mode,
int method, Point offset = Point());
image ,8位单通道图像。 非零像素被视为1。 零像素保持为0,因此图像被视为二值。
可以使用compare、inRange、threshold、adaptiveThreshold、Canny和
其他方法来从灰度或彩色图像创建二值图像。
contours 监测到的轮廓 原型 vector<vector<Point>> contours; 每个轮廓线存储为一个点的向量
hierarchy 可选输出向量 原型vector<Vec4i> hierarchy;
model 定义轮廓的检索模式 RETR_EXTERNAL 只监测最外围轮廓
RETR_LIST 检测所有轮廓
method 定义轮廓的近似方法 CHAIN_APPROX_NONE 保存物体所有连续的轮廓点到contours向量内
CHAIN_APPROX_SIMPLE 仅保存轮廓的拐点信息 拐点与拐点直接的信息不保留
point 偏移量
- drawContours()函数源码
void drawContours(InputOutputArray image, InputArrayOfArrays contours,
int contourIdx, const Scalar& color,
int thickness = 1

本文介绍如何使用OpenCV的findContours()函数检测图像中的轮廓,并通过drawContours()函数绘制轮廓。文章详细解释了findContours()函数的参数含义及使用方法,包括不同检索模式和近似方法的选择。同时,通过示例代码展示了轮廓检测的具体实现。
最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



