OpenCV Convert C++ to Java [closed]

asked 2016-06-28 11:28:24 -0600

SumeetB gravatar image

updated 2016-06-28 17:47:29 -0600

Hi all,

I have the following code written in c++:

vector<Vec4i> hierarchy;
vector<vector<Point>> contours;
findContours(temp, contours, hierarchy, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);
double refArea = 0;
if(hierarchy.size() > 0) {
     int numObjects = hierarchy.size();
    //do stuff
 for(int i = 0; i >= 0; i = hierarchy[i][0]) {
       Moments moment = moments((Mat)contours[i]);
       double area = moment.m00;
       //do more stuff
 }
}

I want to convert this to java for opencv android programming, but am unsure how. If anyone can help, that would be much appreciated!

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-10-07 13:24:32.036479

Comments

hmm, your c++ code already looks inconsistent (if using RETR_EXTERNAL, you should not try to traverse the hierarchy)

what are you trying to achieve ?

have a look at some android sample

berak gravatar imageberak ( 2016-06-28 23:58:05 -0600 )edit

I am detecting objects who appear as halos in a binary matrix, so I thought RETR_EXTERNAL would be good to get the outer contours only. I want to traverse the hierarchy to get the area of each contour and filter out bad candidates based on a min_area threshold. I also use this later on in my program to get a rotated rect so I can draw ellipses around good candidates.

SumeetB gravatar imageSumeetB ( 2016-06-29 00:05:26 -0600 )edit

in that case you don't need the hierarchy. you can traverse the contours list directly. have a look at that android sample , again.

berak gravatar imageberak ( 2016-06-29 00:16:03 -0600 )edit

ok. Thanks!

SumeetB gravatar imageSumeetB ( 2016-06-29 00:35:21 -0600 )edit