【问题标题】:How to get vertex index from Subdiv2D Delaunay triangulation如何从 Subdiv2D Delaunay 三角剖分中获取顶点索引
【发布时间】:2016-06-12 10:31:48
【问题描述】:

我正在使用 OpenCV 3.1,想知道如何获取 Subdiv2D Delaunay 三角剖分中边的顶点索引,而不仅仅是顶点坐标? 我想使用这个索引来保留顶点值以进行进一步的插值。

例如:

cv::Subdiv2D subdiv(rect);
// Insert some points to subdiv....
cv::Point2f org, dst;
subdiv.edgeOrg(edge, &org); // starting point of edge

这只会给我org 中的顶点坐标。

我已经看到,在 OpenCV 2.4 中,我们可以使用 CvSubdiv2DPoint 类型,除了标准的 Point32f 之外,它还包含 id。 在 OpenCV 3.1 中,我找不到这个结构,而且它看起来好像由于某种原因被删除了。

【问题讨论】:

    标签: c++ opencv opencv3.0 delaunay


    【解决方案1】:

    如果有其他人看这个问题。您可以创建一个继承自 subdiv2D 的类并实现您自己的函数以这种方式返回索引:

    .h

    #ifndef __Subdiv2DIndex__
    #define __Subdiv2DIndex__
    
    #include <vector>
    #include <opencv2\opencv.hpp>
    using namespace cv;
    
    class Subdiv2DIndex : public Subdiv2D
    {
    public :
      Subdiv2DIndex(Rect rectangle);
    
      //Source code of Subdiv2D: https://github.com/opencv/opencv/blob/master/modules/imgproc/src/subdivision2d.cpp#L762
      //The implementation tweaks getTrianglesList() so that only the indice of the triangle inside the image are returned
      void getTrianglesIndices(std::vector<int> &ind) const;
    };
    
    #endif
    

    .cpp #include "Subdiv2DIndex.h"

    Subdiv2DIndex::Subdiv2DIndex(Rect rectangle) : Subdiv2D{rectangle}
    {
    }
    
    void Subdiv2DIndex::getTrianglesIndices(std::vector<int> &triangleList) const
    {
      triangleList.clear();
      int i, total = (int)(qedges.size() * 4);
      std::vector<bool> edgemask(total, false);
      const bool filterPoints = true;
      Rect2f rect(topLeft.x, topLeft.y, bottomRight.x - topLeft.x, bottomRight.y - topLeft.y);
    
      for (i = 4; i < total; i += 2)
      {
        if (edgemask[i])
          continue;
        Point2f a, b, c;
        int edge_a = i;
        int indexA = edgeOrg(edge_a, &a) -4;
        if (filterPoints && !rect.contains(a))
          continue;
        int edge_b = getEdge(edge_a, NEXT_AROUND_LEFT);
        int indexB = edgeOrg(edge_b, &b) - 4;
        if (filterPoints && !rect.contains(b))
          continue;
        int edge_c = getEdge(edge_b, NEXT_AROUND_LEFT);
        int indexC = edgeOrg(edge_c, &c) - 4;
        if (filterPoints && !rect.contains(c))
          continue;
        edgemask[edge_a] = true;
        edgemask[edge_b] = true;
        edgemask[edge_c] = true;
    
        triangleList.push_back(indexA);
        triangleList.push_back(indexB);
        triangleList.push_back(indexC);
      }
    }
    

    【讨论】:

      【解决方案2】:

      事实证明,在 OpenCV 3 中,cv::Subdiv2D 中的一些函数现在是 void 返回一个整数。 就我而言,我发现 subdiv.edgeOrg(...)subdiv.edgeDst(...) 将顶点 id 作为整数返回。

      【讨论】:

        猜你喜欢
        • 2013-11-19
        • 2020-08-05
        • 1970-01-01
        • 1970-01-01
        • 2023-04-08
        • 2021-05-27
        • 2020-10-20
        • 1970-01-01
        • 2015-01-07
        相关资源
        最近更新 更多