Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OpenCV in c++ to java

static void calculateDelaunayTriangles(Rect rect, vector<Point2f> &points, vector< vector<int> > &delaunayTri){

Subdiv2D subdiv(rect);

for( vector<Point2f>::iterator it = points.begin(); it != points.end(); it++)
    subdiv.insert(*it);         

vector<Vec6f> triangleList;
subdiv.getTriangleList(triangleList);
vector<Point2f> pt(3);
vector<int> ind(3);

for( size_t i = 0; i < triangleList.size(); i++ )
{
Vec6f t = triangleList[i];
pt[0] = Point2f(t[0], t[1]);
pt[1] = Point2f(t[2], t[3]);
pt[2] = Point2f(t[4], t[5 ]);

if ( rect.contains(pt[0]) && rect.contains(pt[1]) && rect.contains(pt[2])){
    for(int j = 0; j < 3; j++)
        for(size_t k = 0; k < points.size(); k++)
            if(abs(pt[j].x - points[k].x) < 1.0 && abs(pt[j].y - points[k].y) < 1)                      
                ind[j] = k;                 

    delaunayTri.push_back(ind);
}
}

 }

I would like to use this function which builds from opencv but this function is C++ function. I want to convert it to java and use it in android. I am a beginner in c++ and I dun know how to convert them. Can anyone help me to convert it? Thank you very much.

OpenCV in c++ to java

static void calculateDelaunayTriangles(Rect rect, vector<Point2f> &points, vector< vector<int> > &delaunayTri){

Subdiv2D subdiv(rect);

for( vector<Point2f>::iterator it = points.begin(); it != points.end(); it++)
    subdiv.insert(*it);         

vector<Vec6f> triangleList;
subdiv.getTriangleList(triangleList);
vector<Point2f> pt(3);
vector<int> ind(3);

for( size_t i = 0; i < triangleList.size(); i++ )
{
Vec6f t = triangleList[i];
pt[0] = Point2f(t[0], t[1]);
pt[1] = Point2f(t[2], t[3]);
pt[2] = Point2f(t[4], t[5 ]);

if ( rect.contains(pt[0]) && rect.contains(pt[1]) && rect.contains(pt[2])){
    for(int j = 0; j < 3; j++)
        for(size_t k = 0; k < points.size(); k++)
            if(abs(pt[j].x - points[k].x) < 1.0 && abs(pt[j].y - points[k].y) < 1)                      
                ind[j] = k;                 

    delaunayTri.push_back(ind);
}
}

 }

I would like to use this function which builds from opencv but this function is C++ function. I want to convert it to java and use it in android. I am a beginner in c++ and I dun know how to convert them. Can anyone help me to convert it? Thank you very much.

This is the part that I have done. I am still working it. static void calculateDelaunayTriangles(org.opencv.core.Rect rect, Vector<org.opencv.core.point> points, Vector<vector<integer> > delaunayTri){

 // Create an instance of Subdiv2D
    Subdiv2D subdiv = new Subdiv2D(rect);

    // Insert points into subdiv
    for(int i = 0;i < points.size();i++)
    subdiv.insert(points.get(i));

    MatOfFloat6 triangleList = null;
    subdiv.getTriangleList(triangleList);
    Vector<MatOfPoint2f> pt = new Vector<>(3);
    MatOfInt ind = new MatOfInt(3);

   for( int i = 0; i < triangleList.size(); i++ )
   {
   MatOfFloat6 t = triangleList[i];
   pt[0] = new Vector<MatOfPoint2f>(t[0], t[1]);
   pt[1] = new Vector<MatOfPoint2f>(t[2], t[3]);
   pt[2] = new Vector<MatOfPoint2f>(t[4], t[5 ]);

   if ( rect.contains(pt[0]) && rect.contains(pt[1]) && rect.contains(pt[2])){
       for(int j = 0; j < 3; j++)
           for(int k = 0; k < points.size(); k++)
               if(Math.abs(pt[j].x - points[k].x) < 1.0 && abs(pt[j].y - points[k].y) < 1)
                   ind[j] = k;

       delaunayTri.push_back(ind);
   }
  }

  }

OpenCV in c++ to java

static void calculateDelaunayTriangles(Rect rect, vector<Point2f> &points, vector< vector<int> > &delaunayTri){

Subdiv2D subdiv(rect);

for( vector<Point2f>::iterator it = points.begin(); it != points.end(); it++)
    subdiv.insert(*it);         

vector<Vec6f> triangleList;
subdiv.getTriangleList(triangleList);
vector<Point2f> pt(3);
vector<int> ind(3);

for( size_t i = 0; i < triangleList.size(); i++ )
{
Vec6f t = triangleList[i];
pt[0] = Point2f(t[0], t[1]);
pt[1] = Point2f(t[2], t[3]);
pt[2] = Point2f(t[4], t[5 ]);

if ( rect.contains(pt[0]) && rect.contains(pt[1]) && rect.contains(pt[2])){
    for(int j = 0; j < 3; j++)
        for(size_t k = 0; k < points.size(); k++)
            if(abs(pt[j].x - points[k].x) < 1.0 && abs(pt[j].y - points[k].y) < 1)                      
                ind[j] = k;                 

    delaunayTri.push_back(ind);
}
}

 }

I would like to use this function which builds from opencv but this function is C++ function. I want to convert it to java and use it in android. I am a beginner in c++ and I dun know how to convert them. Can anyone help me to convert it? Thank you very much.

This is the part that I have done. I am still working it. it.

 static void calculateDelaunayTriangles(org.opencv.core.Rect rect, Vector<org.opencv.core.point> Vector<org.opencv.core.Point> points,       Vector<vector<integer> Vector<Vector<Integer> > delaunayTri){

delaunayTri){

 // Create an instance of Subdiv2D
    Subdiv2D subdiv = new Subdiv2D(rect);

    // Insert points into subdiv
    for(int i = 0;i < points.size();i++)
    subdiv.insert(points.get(i));

    MatOfFloat6 triangleList = null;
    subdiv.getTriangleList(triangleList);
    Vector<MatOfPoint2f> pt = new Vector<>(3);
    MatOfInt ind = new MatOfInt(3);

   for( int i = 0; i < triangleList.size(); i++ )
   {
   MatOfFloat6 t = triangleList[i];
   pt[0] = new Vector<MatOfPoint2f>(t[0], t[1]);
   pt[1] = new Vector<MatOfPoint2f>(t[2], t[3]);
   pt[2] = new Vector<MatOfPoint2f>(t[4], t[5 ]);

   if ( rect.contains(pt[0]) && rect.contains(pt[1]) && rect.contains(pt[2])){
       for(int j = 0; j < 3; j++)
           for(int k = 0; k < points.size(); k++)
               if(Math.abs(pt[j].x - points[k].x) < 1.0 && abs(pt[j].y - points[k].y) < 1)
                   ind[j] = k;

       delaunayTri.push_back(ind);
   }
  }

  }