OpenCV Convert C++ to Java [closed]
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!
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
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.
in that case you don't need the hierarchy. you can traverse the contours list directly. have a look at that android sample , again.
ok. Thanks!