使用c++在OpenCV中获取blob的位置

Get the location of a blob in OpenCV using C++

本文关键字:blob 位置 获取 c++ OpenCV 使用      更新时间:2023-10-16

输入图片描述

显示的图像是两个图像之间的差异。我要做的就是得到白色部分的位置。我想这样做是因为我想突出显示原始图像中存在差异的地方

我正在考虑使用聚类或斑点检测,或者可能只是定位图像中最亮或最白的像素。

你认为最简单的方法是什么?还有其他我没想到的方法吗?

使用findContour方法查找图像中的闭合轮廓。

vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours( BinaryImage, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );

你可以使用drawContours来绘制轮廓。

变量contours包含生成该特定轮廓的坐标。您可以通过以下命令

显示它
for(double i=0; i<contours.size(); i++)
{
    cout << contours[i];
    drawContours( OutputImage, contours, i, Scalar(0,255,0), 2, 8, hierarchy, 0, Point() );
}