OpenCV contour get specific point X Y values

Hi all! i’m a bit of a newbie here

i’m working with openCV Library and i’m trying to make a sketch that draw lines between points of a contour.

I have no experience working with array lists and pvectors, but basicaly i’m tryng to make a for loop to load the points but I can’t make it load it

The way it generate the contours is this
But i have no idea how to read an specific point in the array and return the x and y value

pls help!

import gab.opencv.*;
PImage src, dst;
OpenCV opencv;

Capture video;
ArrayList<Contour> contours;
ArrayList<Contour> polygons;

void setup() {
  size(800, 600);
  video = new Capture(this, 800 , 600);
  opencv = new OpenCV(this, video);
void captureEvent(Capture video) {;

void draw() {
  dst = opencv.getOutput();
  image(dst, 0, 0);

  contours = opencv.findContours();
  for (Contour contour : contours) {
    stroke(0, 255, 0);
    stroke(255, 0, 0);
    for (PVector point : contour.getPoints()) {
      vertex(point.x, point.y);
1 Like

If you want an explanation of ArrayList and/or PVector, check out the Processing reference page or this video about ArrayList and this video about PVector by Dan Shiffman.

From the opencv example on github it looks like you may need to convert the contours to polygons first if you’re having trouble. You could try this:

for (PVector point : contour.getPolygonApproximation().getPoints()) {
      vertex(point.x, point.y);

If I misunderstood what you’re trying to do. Could you describe what you’re goal is a little more and what’s you’re having trouble with?

1 Like


What i’m trying to do is to draw random lines inside each contour. For that i think i need to get only the xy value for specific points.

El El mié, 2 de ene. de 2019 a las 00:11, Fi Graham escribió: