OpenCV in c++ to java [closed]

asked 2017-01-22 07:19:31 -0500

Clementf2b gravatar image

updated 2017-01-25 20:10:26 -0500

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);
   }
  }

  }
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-11-05 12:55:04.167394

Comments

Do you know about JNI (NDK for Android)?

hoang anh tuan gravatar imagehoang anh tuan ( 2017-01-23 02:15:25 -0500 )edit

I knew but I dun know how does it work so I translate it to java

Clementf2b gravatar imageClementf2b ( 2017-01-23 03:34:59 -0500 )edit

please have a look at the docs -- then start trying. come back with more specific issues.

berak gravatar imageberak ( 2017-01-23 05:50:27 -0500 )edit

preshap I place my translation of code to let you guys to give me some suggestions?

Clementf2b gravatar imageClementf2b ( 2017-01-23 08:06:33 -0500 )edit

^^ yes, please. just edit your question, and show, what you have.

berak gravatar imageberak ( 2017-01-23 08:26:53 -0500 )edit

This is the part that I have done. I am still working it but I dun know the part of iterator, the size_t and the pt[2] = Point2f(t[4], t[5 ]);. How to work it in java? Thanks.

Clementf2b gravatar imageClementf2b ( 2017-01-25 20:11:50 -0500 )edit