OpenCV in c++ to java [closed]
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);
}
}
}
Do you know about JNI (NDK for Android)?
I knew but I dun know how does it work so I translate it to java
please have a look at the docs -- then start trying. come back with more specific issues.
preshap I place my translation of code to let you guys to give me some suggestions?
^^ yes, please. just edit your question, and show, what you have.
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.