OpenCV 中的 Blob 提取

发布于 2024-10-11 07:07:26 字数 263 浏览 5 评论 0原文

我正在使用 OpenCV 过滤图像中的某些颜色,因此我得到了检测到的区域的二值图像。

现在我想侵蚀这些区域,然后去掉较小的区域,并找到最大“斑点”的 x,y 坐标,

我一直在寻找关于最好使用什么库的建议?我见过 cvBlob 和 cvBlobsLib 但我不太确定如何设置它们。我想将它们与项目一起编译还是想将它们编译并安装到系统中(就像我对 OpenCV 所做的那样)?

我目前正在 Ubuntu 上使用 Code::Blocks IDE(尽管这不应该限制事情)

I'm using OpenCV to filter an image for certain colours, so I've got a binary image of the detected regions.

Now I want to erode those areas and then get rid of the smaller ones, and find the x,y coordinates of the largest 'blob'

I was looking for recommendations as to what the best library would be to use? I've seen cvBlob and cvBlobsLib but I'm not too sure how to set them up. Do I want to compile them along with the project or do I want to compile and install them to the system (like I did with OpenCV)?

I'm currently using the Code::Blocks IDE on Ubuntu (although that shouldn't restrict things)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

始终不够 2024-10-18 07:07:26

我迟到了,但我想插话一下,有一种方法可以在 opencv 中实现连接组件,只是还没有主流化。

更新:它已被主线化,只是多年来一直等待 3.0 的发布。 文档链接

请参阅http://code.opencv.org/issues/1236http://code.opencv.org/attachments/467/opencv-connectedcomponents.patch

免责声明 - 我是作者。

I'm late to the party, but I'd just like to chime in that there is a way to do connected components in opencv, it's just not mainlined yet.

Update: It is mainlined, it's just been stuck waiting for 3.0 to release for multiple years. Linky to documentation

See http://code.opencv.org/issues/1236 and http://code.opencv.org/attachments/467/opencv-connectedcomponents.patch

Disclaimer - I'm the author.

假面具 2024-10-18 07:07:26

您可以使用 findContours 来执行此操作,请参阅 opencv 手册教程查找连接的组件


编辑:教程中的代码(来自 Archive.org)

#include <stdio.h>
#include <cv.h>
#include <highgui.h>

int main(int argc, char *argv[])
{
    IplImage *img, *cc_color; /*IplImage is an image in OpenCV*/
    CvMemStorage *mem;
    CvSeq *contours, *ptr;
    img = cvLoadImage(argv[1], 0); /* loads the image from the command line */
    cc_color = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 3);

    cvThreshold(img, img, 150, 255, CV_THRESH_BINARY);
    mem = cvCreateMemStorage(0);
    cvFindContours(img, mem, &contours, sizeof(CvContour), CV_RETR_CCOMP,
        CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));


    for (ptr = contours; ptr != NULL; ptr = ptr->h_next) {
        CvScalar color = CV_RGB( rand()&255, rand()&255, rand()&255 );
        cvDrawContours(cc_color, ptr, color, CV_RGB(0,0,0), -1, CV_FILLED, 8, cvPoint(0,0));
    }

    cvSaveImage("result.png", cc_color);
    cvReleaseImage(&img);
    cvReleaseImage(&cc_color);
    return 0;
}

You can use findContours to do that, see the opencv manual and a Tutorial to find connected components.


Edit: Code from the tutorial (via Archive.org)

#include <stdio.h>
#include <cv.h>
#include <highgui.h>

int main(int argc, char *argv[])
{
    IplImage *img, *cc_color; /*IplImage is an image in OpenCV*/
    CvMemStorage *mem;
    CvSeq *contours, *ptr;
    img = cvLoadImage(argv[1], 0); /* loads the image from the command line */
    cc_color = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 3);

    cvThreshold(img, img, 150, 255, CV_THRESH_BINARY);
    mem = cvCreateMemStorage(0);
    cvFindContours(img, mem, &contours, sizeof(CvContour), CV_RETR_CCOMP,
        CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));


    for (ptr = contours; ptr != NULL; ptr = ptr->h_next) {
        CvScalar color = CV_RGB( rand()&255, rand()&255, rand()&255 );
        cvDrawContours(cc_color, ptr, color, CV_RGB(0,0,0), -1, CV_FILLED, 8, cvPoint(0,0));
    }

    cvSaveImage("result.png", cc_color);
    cvReleaseImage(&img);
    cvReleaseImage(&cc_color);
    return 0;
}
颜漓半夏 2024-10-18 07:07:26

不幸的是,OpenCV 没有任何连接的组件标记功能,这对于计算机视觉库来说似乎是一个严重的遗漏。无论如何,我最近有类似的要求,所以我实现了自己的 CCL 例程 - 上描述了几种不同的算法CCL 维基百科页面,它们的实现都非常简单。

Unfortunately OpenCV doesn't have any connected component labelling functionality, which seems like a serious omission for a computer vision library. Anyway I had a similar requirement recently so I implemented my own CCL routine - there are a couple of different algorithms described on the CCL Wikipedia page and they are both pretty simple to implement.

一抹微笑 2024-10-18 07:07:26

我认为使用 OpenCV 处理 blob 的最佳且简单的选择是使用 cvBlob 库。它是 OpenCV 的补充库,非常易于使用。

I think the best and easy option to work with blobs with OpenCV is to use cvBlob library. Its a complemntary library with OpenCV a its so easy to use.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文