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.*;
import processing.video.*;
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);
  video.start();
  
  
}
void captureEvent(Capture video) {  
  video.read();
}

void draw() {
  opencv.loadImage(video);
  dst = opencv.getOutput();
  
  image(dst, 0, 0);
  
  opencv.gray();
  opencv.threshold(70);
  

  contours = opencv.findContours();
  
  noFill();
  strokeWeight(3);
  
  for (Contour contour : contours) {
    stroke(0, 255, 0);
    
    
    stroke(255, 0, 0);
    beginShape();
    for (PVector point : contour.getPoints()) {
      vertex(point.x, point.y);
    }
    endShape();
  }
}
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

Thanks!

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 processingfoundation1@discoursemail.com escribió: