Ask Your Question
0

Converting c++ to java

asked 2016-07-15 06:53:42 -0600

abhilash1in gravatar image

updated 2016-07-15 06:55:32 -0600

I have the following code in C++

vector<Vec4i> hierarchy;
//some code here

findContours( edges, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE);
//some code here

while(hierarchy[k][2] != -1)
{
    k = hierarchy[k][2] ;    // k is an integer
    c = c+1;                      // c in an integer
}
if(hierarchy[k][2] != -1)
    c = c+1;

I'm trying to convert it to Java. I've achieved the following so far:

Mat hierarchy = new Mat();
//some code here

Imgproc.findContours(edges,contours,hierarchy,Imgproc.RETR_TREE,Imgproc.CHAIN_APPROX_SIMPLE);
//some code here

I'm facing a problem with converting lines like these

while(hierarchy[k][2] != -1)

where I'm accessing some

hierarchy[i][j]

How do I do this in Java? I can see that I can do a Mat.get(int row,int col) in Java which returns me a double[ ] but I'm looking for an int return value when I do hierarchy[i][j] in C++

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2016-08-11 22:41:21 -0600

Cheqrd gravatar image

Hierarchy should be a Mat type and yes you can simply use something like this.

while(hierarchy.get(k, 2) != -1)
{
     (int)k = hierarchy.get(k, 2) // type casting to integer
     c++;
}
edit flag offensive delete link more
0

answered 2016-07-17 10:56:17 -0600

irla gravatar image

I think java equivalent of C++ hierarchy[k] will be hierarchy.get(0, k).

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-07-15 06:53:42 -0600

Seen: 280 times

Last updated: Jul 15 '16