轮廓计数和标记
Contours counting and labeling
本文关键字:轮廓 更新时间:2023-10-16
我正试图开发一个程序,将contourAreas
的数量作为大小的函数进行计数,并将其显示给用户。
我可以为所有区域创建drawContours
,但我想在每个contouArea
下添加一个文本标签,并在那里显示相应的大小。
这应该会让您开始。要浏览所有轮廓,必须使用下面带有h_next的for循环。如果你想了解更多,我真的推荐加里·布拉德斯基的书《开放式学习》。这本书中有一些关于轮廓发现的好例子。
CvMemStorage* contour_storage = cvCreateMemStorage(0);
CvSeq* contours;
CvFont font;
cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 0.6f, 0.6f, 0, 2);
cvFindContours(sourceImage, contour_storage, &contours, sizeof (CvContour), CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);
for (CvSeq* d = contours; d != NULL; d = d->h_next) {
CvRect iconBox = cvBoundingRect(d, 0);
CvPoint center = cvPoint(iconBox.x + (iconBox.width / 2), iconBox.y + (iconBox.height / 2));
int area = abs(cvContourArea(d, CV_WHOLE_SEQ));
cvPutText(sourceImage,"area", center, &font, CV_RGB(255, 255, 255));
}
您可以使用打开的cv函数putText
我想你知道如何检索你的轮廓中心的位置,不是吗?
相关文章:
- 使用libgdal从文件中获取地形的轮廓
- 如何在OpenCV中存储部分轮廓点喜欢新矢量中的左侧,该类型为<vector<vector<Point>>
- 如何阻止LWA_COLORKEY制作灰色轮廓?
- Opencv 时刻没有成员命名 m00,同时试图确定轮廓的中心
- 在X光片中找到轮廓
- 使用GDI(C )的轮廓绘制文字
- OpenCV : findcontours() , 太多的外部轮廓
- 查找从轮廓到点OPENCV C 的距离
- 在轮廓和垫子上应用同件
- 在 OpenCV 和 C++ 中查找距轮廓中心最近的黑色像素
- 来自Soble操作员的轮廓
- 排序矩形轮廓OPENCV
- 如何使用 OpenCv 从图像中"cut"轮廓?
- OpenCV c++ 断言失败调用绘制轮廓
- 重载函数查找轮廓的实例与参数列表不匹配
- 过滤不需要的轮廓-C 的OPENCV
- 轮廓的偏度
- 如何找到最大的轮廓
- 轮廓字体倒置 - glOrtho() 设置不正确
- 在OpenCV中使用遮罩和ROI计算轮廓内浮器的图像像素值(例如平均值)