C++ Code convert in Java or what does this line do ?

asked 2014-06-23 01:59:03 -0500

bbx gravatar image

updated 2014-06-23 02:00:09 -0500

Hello everbody, iam completly new in openCV and train with the Book "Mastering OpenCV". But all examples are in C++. I want to import one example in Java for android and there is a line i dont unterstand and how to convert in Java.

//Find contours of possibles plates
vector< vector< Point> > contours; // <-- What does this line do ?
contours,                          // a vector of contours
CV_RETR_EXTERNAL,                  // retrieve the external contours
CV_CHAIN_APPROX_NONE);             // all pixels of each contour

//Start to iterate to each contour found
vector<vector<Point> >::iterator itc= contours.begin(); // Here again, what does it mean?
vector<RotatedRect> rects;

I do not understand these 2 lines. Maybe someone can help me or explain what these 2 lines do and how i can realize it in java ?

Best regards

edit retag flag offensive close merge delete


since we're already talking about android, you might want to take a look at the color-blob-detection sample

berak gravatar imageberak ( 2014-06-23 02:07:56 -0500 )edit

Thanks a lot, i will now look at this! As far as i could find now: the first is a vector, filled with a vector that contains type of Points, declared as contours

But this i dont unterstand vector<vector<Point> >::iterator itc= contours.begin();

Now i will look at your link, berak. Thanks

bbx gravatar imagebbx ( 2014-06-23 03:24:45 -0500 )edit

there are no iterators in java, you probably will use indices or contours.get(i)

berak gravatar imageberak ( 2014-06-23 03:29:08 -0500 )edit

to convert these line in java, i found this: Multiple Vectors : private Vector <Vector <Point>> contours = new Vector <Vector <Point>> ();

@berak, thats not true, Java has since ver.1.2 iterators http://docs.oracle.com/javase/7/docs/api/java/util/Iterator.html

Maybe you mean that i cannot use iterators for vectors ?

bbx gravatar imagebbx ( 2014-06-23 04:30:21 -0500 )edit

;) ok. you win. (admittedly quite rusty with java)

on the other hand, findContours explicitly wants a List<MatOfPoint> in java, so you can stop worrying about vectors anyway

berak gravatar imageberak ( 2014-06-23 04:46:00 -0500 )edit

No thanks, both win :) you helped me a lot to find the right way and of course you were right. findContours want a List<MatOfPoint> And i got crazy about vectors :) in Java the function looks like

Imgproc.findcontours( [Mat Image] , [List<MatOfPoint>] , [Mat hierarchy] , [int mode] , [int method]

What does Mat hierarchy do ? At the moment 2 lines above I create a Mat with Mat mHierarchy = new Mat();

will this work without any problems ? or have I to create a specific Mat like defined cols rows etc...?

bbx gravatar imagebbx ( 2014-06-23 05:42:26 -0500 )edit

Mat mHierarchy = new Mat(); // will work perfectly

for the explanation, docs, again

berak gravatar imageberak ( 2014-06-23 05:51:53 -0500 )edit

Thx a lot ! thumbs up

bbx gravatar imagebbx ( 2014-06-23 07:37:55 -0500 )edit