OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Tue, 19 Feb 2019 23:53:06 -0600Algorithm behind delaunay tringulationhttp://answers.opencv.org/question/209077/algorithm-behind-delaunay-tringulation/ There are several algorithms to perform Delaunay triangulation. But we normally use `subdiv2d.getTriangleList()` method to derive Delaunay translation on given vertices. What is the algorithm OpenCV used to construct this Delaunay triangulation?Vikum DheemanthaTue, 19 Feb 2019 23:53:06 -0600http://answers.opencv.org/question/209077/How to delete point(already inserted) in subdiv2d (python)http://answers.opencv.org/question/206362/how-to-delete-pointalready-inserted-in-subdiv2d-python/I implemented subdiv2d and insert some points as the following way to construct Delaunay triangulation.
size = img.shape
rect = (0, 0, size[0], size[1])
subdiv = cv2.Subdiv2D(rect)
points = []
x = 0
while(x<size[0]):
y = 0
while(y<size[1]):
points.append((x, y))
y = (y + 50)
points.append((x, size[1]-1))
x = x + 50
subdiv.insert(points)
I want to remove some points after that, let's assume I want to remove (0, 0), or (50,50) point from subdiv, that I already inserted through point array. How can I do this? please help me.Vikum DheemanthaThu, 03 Jan 2019 04:25:56 -0600http://answers.opencv.org/question/206362/How can I check homogenity of the grayscale region of the image?http://answers.opencv.org/question/199666/how-can-i-check-homogenity-of-the-grayscale-region-of-the-image/ I impliment the random delaunay triangulation on a image, using subdiv2d in python. I want to check the each triangle region(Generated by delaunay triangulation) is homogeneous or not. How can I achieve this using openCV? Thanks.Vikum DheemanthaTue, 18 Sep 2018 12:08:54 -0500http://answers.opencv.org/question/199666/Keypoint Matching Outlier Rejection, Delaunay Triangulationhttp://answers.opencv.org/question/54045/keypoint-matching-outlier-rejection-delaunay-triangulation/Can anyone point me to an OpenCV solution or a quality paper detailing outlier rejection based upon keypoint context, i.e. the keypoints surrounding the keypoint in the 'training' or model image? Matching could make use of this information (not brute force, but with a match threshold), or it could be a post brute-force refinement operation. The complexity difference would matter as I want this to run at super frame rate. The idea is to keep only those point matches that 'agree' with each other topologically, as in a deforming mesh. It seems [delaunay triangulation](http://docs.opencv.org/2.4.10/modules/legacy/doc/planar_subdivisions.html?highlight=delaunay "delaunay, OpenCV") could be used for identifying neighbors (creating the mesh), but this API is not super clear and has been deprecated.
Any high-level algorithm design thoughts?Der LuftmenschThu, 29 Jan 2015 08:42:24 -0600http://answers.opencv.org/question/54045/Out of range error in delaunay-triangulationhttp://answers.opencv.org/question/180984/out-of-range-error-in-delaunay-triangulation/I'm trying to run the program which is compiled from the code here.
http://www.learnopencv.com/delaunay-triangulation-and-voronoi-diagram-using-opencv-c-python/
I'm using Visual studio 2015 and openCV 3.2. I encounter run error whose message is "OpenCV Error: One of arguments' values is out of range () in cv::Subdiv2D::locate, ..."
Can anyone help solve this problem?GinaSun, 24 Dec 2017 07:32:10 -0600http://answers.opencv.org/question/180984/Delaunay triangulation and Point3fhttp://answers.opencv.org/question/168579/delaunay-triangulation-and-point3f/Hy,
I'm trying to create a delaunay triangulation from a set of point 3f. The 2 first coordinates are the coordinates in the plan and the third one is the value of my data at that point (the goal is to create isolines).
I have tried to use SubDiv2D but the problem is that it take point 2f and return a list of Vec6f and so I have to find the association of each point2f with my point3f. Is there a way to get the indice from the vector of input instead of the coordinates ?
Thanksesteban.daMon, 24 Jul 2017 03:07:55 -0500http://answers.opencv.org/question/168579/Delaunay triangulation - edge flip?http://answers.opencv.org/question/102085/delaunay-triangulation-edge-flip/I used this code: http://www.learnopencv.com/delaunay-triangulation-and-voronoi-diagram-using-opencv-c-python/ for Delaunay triangulation, now I'm trying to figure out how to flip edges like this: http://i.imgur.com/RqAQKN5.png.
I found that there is a member function of subdiv2d called "swapedges" which potentionally does exactly what I need but I don't know how it's supposed to be used, I'm pretty new at C++ and OpenCV and if there's anyone who could help me by showing an example of how it should work, I would be very thankful.
Thanks in advance.vaxonSat, 10 Sep 2016 06:39:05 -0500http://answers.opencv.org/question/102085/How to find Delaunay Neighborhood of all the vertices in OpenCV.http://answers.opencv.org/question/95498/how-to-find-delaunay-neighborhood-of-all-the-vertices-in-opencv/Delaunay Neighborhood of a vertex is its immediate spatial neighbors in the Delaunay Triangulation i.e. the vertices which share an edge with that vertex.
I wish to find Delaunay Neighborhood for all the points and store it in a vector<vector<Point2f>>.Abhishek_dogra_007Fri, 03 Jun 2016 01:20:45 -0500http://answers.opencv.org/question/95498/identifier "cvSubdivDelaunay2DInsert" is undefinedhttp://answers.opencv.org/question/94265/identifier-cvsubdivdelaunay2dinsert-is-undefined/the code throws exception
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/imgproc/imgproc_c.h>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include "PAW.h"
#include "Triangle.h"
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <time.h>
#include <string>
#include <algorithm>
#include <set>
///
//insert srcLandmark points in Delaunay subdivision
for (int i = 0; i<pointsToWarp.size(); i++){
double x = pointsToWarp.at(i).x;
double y = pointsToWarp.at(i).y;
points.push_back(cvPoint(x, y));
CvPoint2D32f fp = cvPoint2D32f(x, y);
cvSubdivDelaunay2DInsert(subdiv, fp);
}
////LusineSun, 15 May 2016 09:51:51 -0500http://answers.opencv.org/question/94265/generate Delaunay triangle meshhttp://answers.opencv.org/question/91627/generate-delaunay-triangle-mesh/Hello people,
Is it possible generate a 2D using opencv python?
I have this image:
![image description](https://dl.dropboxusercontent.com/u/710615/withframe.png)
I want to gerenate something like this:
![image description](http://i.stack.imgur.com/Ftvy2.jpg)
ThanksmarcoEFri, 01 Apr 2016 07:39:55 -0500http://answers.opencv.org/question/91627/How to do Delaunay Triangulation and return an adjacency matrix?http://answers.opencv.org/question/87540/how-to-do-delaunay-triangulation-and-return-an-adjacency-matrix/ I am trying to do Delaunay Triangulation for a set of points in OpenCV, but encountered a problem.
The function takes a matrix of coordinates and return an adjacency matrix. (If there is and edge connecting the point i and the point j, then adj(i,j) = 1, otherwise 0.)
I didn't get it working. The code below give strange results.
Could you please help?
An example of Delaunay Triangulation is given [here][1].
Thank you in advance.
#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
using namespace std;
using namespace cv;
Mat delaunay(const Mat& points, int imRows, int imCols)
/// Return the Delaunay triangulation, under the form of an adjacency matrix
/// points is a Nx2 mat containing the coordinates (x, y) of the points
{
Mat adj(points.rows, points.rows, CV_32S, Scalar(0));
/// Create subdiv and insert the points to it
Subdiv2D subdiv(Rect(0,0,imCols,imRows));
for(int p = 0; p < points.rows; p++)
{
float xp = points.at<float>(p, 0);
float yp = points.at<float>(p, 1);
Point2f fp(xp, yp);
subdiv.insert(fp);
}
/// Get the number of edges
vector<Vec4f> edgeList;
subdiv.getEdgeList(edgeList);
int nE = edgeList.size();
/// Check adjacency
for(int e = 1; e <= nE; e++)
{
int p = subdiv.edgeOrg(e); // Edge's origin
int q = subdiv.edgeDst(e); // Edge's destination
if(p < points.rows && q < points.rows)
adj.at<int>(p, q) = 1;
// else
// {
// cout<<p<<", "<<q<<endl;
// assert(p < points.rows && q < points.rows);
// }
}
return adj;
}
int main()
{
Mat points = Mat(100, 2, CV_32F);
randu(points, 0, 99);
int rows = 100, cols = 100;
Mat im(rows, cols, CV_8UC3, Scalar::all(0));
Mat adj = delaunay(points, rows, cols);
for(int i = 0; i < points.rows; i++)
{
int xi = points.at<float>(i,0);
int yi = points.at<float>(i,1);
/// Draw the edges
for(int j = i+1; j < points.rows; j++)
{
if(adj.at<int>(i,j) > 0)
{
int xj = points.at<float>(j,0);
int yj = points.at<float>(j,1);
line(im, Point(xi,yi), Point(xj,yj), Scalar(255,0,0), 1);
}
/// Draw the nodes
circle(im, Point(xi, yi), 1, Scalar(0,0,255), -1);
}
}
namedWindow("im", CV_WINDOW_NORMAL);
imshow("im",im);
waitKey();
return 0;
}
[1]: https://github.com/Itseez/opencv/blob/03e74330fa95306407f521beecdc3ae059f0cf1c/samples/cpp/delaunay2.cppNesbitFri, 12 Feb 2016 17:56:38 -0600http://answers.opencv.org/question/87540/Voronoi lineshttp://answers.opencv.org/question/59272/voronoi-lines/ I'm trying to have an image with the voronoi line (the point on the image which are at an equal distance of at least to 0-value pixel). I know of `distanceTransform` and for now I'm using this to return either the distance Mat or the label. I've tried using line detector to find the line but, if I use the label, I don't have all the line, if I use the distances, the image gets rather messy.
Using delaunay here isn't really an option because I have only an image with lines and no points to give to `Subdiv2D`. Plus subdiv doesn't give me an image as a result.
Is there any "easy way" to get all those point at equal distance of 0-value pixel ? If I could not have to reimplement a Voronoi less efficient than the one implemented I'll be really glad.
Here is a (bad) image made under GIMP. If the red lines are the 0-values point, then the black line would be my Voronoi lines :
![image description](/upfiles/14284474064598927.png)
Sorry for the very badly drawn drawing !
What I tried for now :
* Doing distanceTransform and then
* Using Laplace/Sobel to get the lines directly on the Vronoi diagram
* Using Laplace/Sobel on the label from CCOMP. That wasn't to bad but I missed some line. Especially, when There is a square (like in the figure) all the line are considered as 1element and I have no lines anymore.
* Using Delaunay.
* Calculating local maximum value . That gave quite good results but the lines are often disconnected.
![image description](/upfiles/14284476415968617.png)
For exemple, here are my results with Laplace and Sobel using the label. The Laplace one here is perfect because non of the lines are connected. If I were to put a "dead-end" (connect the two line on top for example), my top line would disappear. And I don't want that :)
Thanks !MalcolmMayaTue, 07 Apr 2015 15:25:03 -0500http://answers.opencv.org/question/59272/Alternatives for deprecated CreateSubdivDelaunay2D on version 2.4.6.0http://answers.opencv.org/question/17764/alternatives-for-deprecated-createsubdivdelaunay2d-on-version-2460/I'm developing a little application that needs to do a Delaunay triangulation on a set of points. I'm using C++, and as I've seen on the documentation, the function to use is CreateSubdivDelaunay2D, but it is found on the "legacy or deprecated" section of the on-line manual.
Is there any alternative to be used for the C++ API? Why is it marked as deprecated? Does it will be removed in the near future?
Thanks in advance!ggllTue, 30 Jul 2013 02:58:24 -0500http://answers.opencv.org/question/17764/How to get an edge associated to a vertex in a Delaunay triangulation?http://answers.opencv.org/question/14225/how-to-get-an-edge-associated-to-a-vertex-in-a-delaunay-triangulation/According to the reference manual when I use the command:
import cv2.cv as cv
a=cv.Subdiv2DLocate(subdiv,(x,y))
if the point (x,y) is a vertex from the triangulation, the function does not return an edge, but a tuple with a "cvsubdiv2dpoint".
How is it possible to get the information of one of the edges that are connected to this vertex?
I tried to access the field "first" from the "cvsubdiv2dpoint" structure, but the Python shell restarts (crashes).
I am using Python 2.7, OpenCV 2.4.4 on Linux Ubuntu machine.pdpcostaWed, 29 May 2013 13:11:42 -0500http://answers.opencv.org/question/14225/Delaunay stabilityhttp://answers.opencv.org/question/7230/delaunay-stability/Hi,
I'm working on AAM for facedetect, but I have a problem with my Delaunay triangulation : in every videos from youtube it's pretty stable, and the triangles are corresponding between frames. But when I do it, it's not really stable and the triangles are changing (i.e. it's not the same vertices linked each time). It's problematic for the texture warping, if triangles are not the same I can't warp them to find a correct mean texture.
I have a shape with points (vector<Point2f>) after adding each point in a subdiv2D (C++, but I tried with the C way) I get the triangle list and print them. My points are always in the same order.
Am I missing something in the principle of the algorithms ? Because I think it's natural that the triangles are not always the same if the shape change...
So is there a way to make this triangulation stable, or do I have to find another solution to warp my texture ? RogeeeerMon, 11 Feb 2013 05:09:29 -0600http://answers.opencv.org/question/7230/Edge index always -1http://answers.opencv.org/question/6953/edge-index-always-1/Hi
I'm trying to obtain the index of the vertices from the Delaunay triangulation.
Because it's quite a bit of code in all I'll only show the important bits, but I found here: https://code.ros.org/trac/opencv/browser/trunk/opencv/samples/c/delaunay.c?rev=1429
The function I use to get to the edges: CvSubdiv2DPoint* pt= cvSubdiv2DEdgeOrg( edge ). Where edge is of type CvSubdiv2DEdge. To get the index: int index= pt->id;
But this is always giving me -1 for every edge. I would like to get the indices to correspond with the order by which the points have been subdivided. I hope this is possible.
ovaalTue, 05 Feb 2013 14:40:53 -0600http://answers.opencv.org/question/6953/