OpenCV "FindContours" wont get me the number of Points

I am using the example “findContours” from the Open CV library.
Here I found the reference for the library.
http://atduskgreg.github.io/opencv-processing/reference/gab/opencv/Contour.html

I am trying to determine how many dots are in the contour.
So I tried:

import gab.opencv.*;

PImage src, dst;
OpenCV opencv;

ArrayList<Contour> contours;
ArrayList<Contour> polygons;

void setup() {
  src = loadImage("test.jpg"); 
  size(1080, 360);
  opencv = new OpenCV(this, src);

  opencv.gray();
  opencv.threshold(70);
  dst = opencv.getOutput();

  contours = opencv.findContours();
  contours = opencv.getPoints();
  println("found " + contours.size() + " contours");
  println("found " + contours.numPoints() + " contours");

The scketch wont even run.
It says that getPoints and numPoints “function does not exist”.

What am I doing wrong?
Thanks

might wanna file this under Processing Libraries for help regarding openCV

I did, still no one can help me.

Any ideas?

when i run the full example
Processing IDE / File / Examples / OpenCV for Processing / FindContours /
and not your code snipplet
it works here:
Raspberry Pi / Raspbian Linux / Processing 3.5.1 / JAVA mode

Yes, the example works for me too, but I need to get the number of pixels of the contour,

Any ideas?

yes
( if you would have marked the 2 lines you added, it might have been more easy )

  contours = opencv.findContours();
  println("found " + contours.size() + " contours");   // shows found 166 contours
  
// @laptophead
// contours = opencv.getPoints();
// println("found " + contours.numPoints() + " contours");
  for (Contour contour : contours) {                                               // kll add
    println("found " + contour.numPoints() + " points in contour " +contour);
  }

but that might be related to vertex points ( not same as pixels )

Thanks , that worked.
I made a simple image for testing.

The outbound box is found as a contour and came up at 2388 points. Close enough to the 600x4 dimension. I guess some points are cut a the corners.
But then the weirdest thing: The circle inside is not found as an edge.

Why would that be?
Thanks

sorry, i know nothing about that library,
but possibly the meaning of CONTOUR is outbounds?

-a- did you check all examples?
-b- did you check on his book


-c- did you try 2 concentric circles and what “he” find?

Thanks ,
I looked a the book, very little on this subject matter (contour).

I wonder if you’d know how to write your line:

println("found " + contour.numPoints() + " points in contour " +contour);

Specific for each contour.
The sketch finds a number of contours and indexes them 0,1,2,3,…
Right now the numPoints refers to the sum total of all of them.
Is there syntax that would extract the points for contour 1 for instance?

Thanks
My C++ is weak , sorry,

no, that’s why the loop was needed,
contours is a array(list)
and each contour in contours has numPoints,

so actually if you need all points must calc yourself:

  int allnum = 0;
  for (Contour contour : contours) { 
    int num =  contour.numPoints();
    println("found " + num + " points in contour " +contour);
    allnum += num;
  }
  println("points sum: "+allnum);

p.s. array and arraylists have to be treated differently,
pls check like
https://processing.org/reference/StringList.html
so there will be no
contours[0]
but
contours.get(0).numPoints() might work.

kll
Thanks again, you’re a big help.
The code above worked, however the result of println is not giving me the contour number as a 0,1,2 but I get:
found 219 points in contour gab.opencv.Contour@56005110
found 563 points in contour gab.opencv.Contour@118bf155
found 3588 points in contour gab.opencv.Contour@3621520a

I wonder what those numbers mean. Is there a way to make them comprehensible?

also I tried

   int PointsFor0 = contours.get(0).numPoints() ;
    int PointsFor1 = contours.get(1).numPoints() ;
    int PointsFor2 = contours.get(2).numPoints() ;
    println(PointsFor0+ " " +PointsFor1+ " "  +PointsFor2);

And it worked really well.
I made a simple jpeg for testing and the numbers make sense.

If you still want to help, there is one more thing. You could do this for the entire Processing community.
Greg, the author of this library has also developed a compare contours function. That would be really useful to me and probably others.
All the class definitions and stuff are here. I just wish I knew how to generate an example.
But I dont. Wonder if you’d want to make one.

http://atduskgreg.github.io/opencv-processing/reference/gab/opencv/ContourComparator.html