Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
opencv查找凹壳_Opencv_Image Processing_Interpolation_Contour_Concave - Fatal编程技术网

opencv查找凹壳

opencv查找凹壳,opencv,image-processing,interpolation,contour,concave,Opencv,Image Processing,Interpolation,Contour,Concave,我在图像中显示了一组离散点,如下所示 我想重建或向上采样(我不确定描述它的正确方式是什么)图像,这样结果图像将如下所示。它不需要与示例图像完全相同,但主要思想是填充原始图像 我对如何做这件事有了初步的想法。但我不知道第一步之后怎么做。我的想法是首先使用kmeans分离图像并找出不同的对象。我已经成功地做到了。kmeans之后的结果图像为: 在kmeans之后,我想使用find contour或类似凹面的东西来获得这些形状的轮廓,并使用填充孔之类的函数来填充形状。但是,我发现“查找轮廓”不起作用

我在图像中显示了一组离散点,如下所示

我想重建或向上采样(我不确定描述它的正确方式是什么)图像,这样结果图像将如下所示。它不需要与示例图像完全相同,但主要思想是填充原始图像

我对如何做这件事有了初步的想法。但我不知道第一步之后怎么做。我的想法是首先使用kmeans分离图像并找出不同的对象。我已经成功地做到了。kmeans之后的结果图像为:

在kmeans之后,我想使用find contour或类似凹面的东西来获得这些形状的轮廓,并使用填充孔之类的函数来填充形状。但是,我发现“查找轮廓”不起作用,它会考虑每个单个像素作为轮廓。 我想的另一种方法是使用插值。但我不确定是否有可能有如此稀疏的点。有人知道怎么做吗?我不确定我是否走上了正确的道路,我愿意接受任何解决方案


非常感谢

看看形态变换。我将从使用大内核的膨胀操作开始,比如大小为(15,15)的变形椭圆。然后,使用具有相同大小内核的腐蚀操作将水滴减薄。看看这些文件。请注意,OpenCV也提供了链式或顺序式的形态学操作。看见然后,您将看到我的建议是“关闭”操作

更新: 我尝试了简单的扩张和轮廓,以产生图像中显示的结果。结果似乎满足问题的一般要求

同样,“实时”对应用程序的含义也没有具体说明,但这组操作可以快速执行,并且可以轻松地应用于30fps的应用程序。

下面的代码片段:

// Convert image to grayscale
cvtColor(src, gray, CV_BGR2GRAY);
threshold(gray, gray, 128.0, 128.0, THRESH_BINARY);

// Dilate to fill holes
dilate(gray, dest, getStructuringElement(MORPH_ELLIPSE, Size(13,13)));

// Find contours
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours(dest, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0,0)); 

  // Prune contours
  float maxArea = 0.0f;
  for (size_t i = 0; i< contours.size(); i++)
     {
       if (contourArea(contours[i]) >= maxArea)
         {
            maxArea = contourArea(contours[i]);
         }
     } 

  float minArea = 0.20f * maxArea;
  vector<vector<Point> > prunedContours;
  for (size_t i = 0; i< contours.size(); i++)
     {
       if (contourArea(contours[i]) >= minArea)
         {
           prunedContours.push_back(contours[i]);
         }
     }

// Smooth the contours
vector<vector<Point> > smoothedContours;
  smoothedContours.resize(prunedContours.size());
  for (size_t i=0;i<prunedContours.size();i++)
    {
    vector<float> x;
    vector<float> y;

    const size_t n = prunedContours[i].size();

    for (size_t j=0;j<n;j++)
      {
        x.push_back(prunedContours[i][j].x);
        y.push_back(prunedContours[i][j].y);
      }

    Mat G;
    transpose(getGaussianKernel(11,4.0,CV_32FC1),G);

    vector<float> xSmooth;
    vector<float> ySmooth;

    filter2D(x,xSmooth, CV_32FC1, G);
    filter2D(y,ySmooth, CV_32FC1, G);

    for (size_t j=0;j<n;j++)
      {
        smoothedContours[i].push_back(Point2f(xSmooth[j],ySmooth[j]));
      }
    }
//将图像转换为灰度
CVT颜色(src、灰色、CV_BGr2灰色);
阈值(灰度、灰度、128.0、128.0、阈值二元);
//扩孔
扩张(灰色,dest,getStructuringElement(变形椭圆,大小(13,13));
//寻找轮廓
矢量等值线;
向量层次;
findContours(目标、轮廓、层次、CV_RETR_树、CV_链_近似、简单、点(0,0));
//修剪轮廓
浮动最大面积=0.0f;
对于(size_t i=0;i=maxArea)
{
maxArea=轮廓面积(轮廓[i]);
}
} 
浮顶面积=0.20f*最大面积;
矢量修剪轮廓;
对于(size_t i=0;i=minArea)
{
修剪轮廓。推回(轮廓[i]);
}
}
//使轮廓平滑
向量平滑轮廓;
SmootedContours.resize(prunedContours.size());

对于(尺寸i=0;我不认为“上采样”是您要找的术语。@Markransem是的,我不确定使用哪个术语是正确的。有什么建议吗?我有关于形态学的想法。但是如果我们有不同的对象,这种方法不稳定,我们不能实时执行。两条评论:上面的变形操作相当快,可能在GPU中被加速(取决于平台)。你能澄清一下“不稳定”吗?这听起来是对你的问题的另一个限制,因为变形操作通常被认为是稳定的(从某种意义上说,它们在运行时没有太多意外的机会)我所说的不稳定是指形态取决于您使用的对象以及不同对象的外观。我的系统需要实时工作,无论它是什么对象,都必须在不调整形态参数的情况下完成。同样,还必须存在其他约束:形态操作符似乎适合状态d需要非常好,即“我想使用查找轮廓或类似凹面的东西来获得这些形状的轮廓,并使用填充孔等功能填充形状。”形态学操作符可以填充图像中所示的形状,以生成包含每个“对象”轮廓的单个轮廓。