# OpenCV contour get specific point X Y values

**URL:** <https://discourse.processing.org/t/opencv-contour-get-specific-point-x-y-values/7079>\
**Category:** Libraries\
**Created:** [January 1, 2019, 9:48pm UTC](https://discourse.processing.org/t/opencv-contour-get-specific-point-x-y-values/7079 "2019-01-01T21:48:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![felloduarte](https://avatars.discourse-cdn.com/v4/letter/f/82dd89/32.png) [@felloduarte](https://discourse.processing.org/u/felloduarte)\
**Post date:** [January 1, 2019, 9:48pm UTC](https://discourse.processing.org/t/opencv-contour-get-specific-point-x-y-values/7079/1 "2019-01-01T21:48:09Z")

</div>

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!

```auto
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();
  }
}

```

---

<div class="post-metadata">

**Author:** ![figraham](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/figraham/32/4161_2.png) [@figraham](https://discourse.processing.org/u/figraham)\
**Post date:** [January 2, 2019, 3:01am UTC](https://discourse.processing.org/t/opencv-contour-get-specific-point-x-y-values/7079/2 "2019-01-02T03:01:02Z")

</div>

If you want an explanation of ArrayList and/or PVector, check out the [Processing reference page](https://processing.org/reference/) or [this video about ArrayList](https://www.youtube.com/watch?v=HnSJZ4qTcwY) and [this video about PVector](https://www.youtube.com/watch?v=7nTLzLf7jUg) by Dan Shiffman.

From the [opencv example on github](https://github.com/atduskgreg/opencv-processing/blob/master/examples/FindContours/FindContours.pde) it looks like you may need to convert the contours to polygons first if you’re having trouble. You could try this:

```auto
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?

---

<div class="post-metadata">

**Author:** ![felloduarte](https://avatars.discourse-cdn.com/v4/letter/f/82dd89/32.png) [@felloduarte](https://discourse.processing.org/u/felloduarte)\
**Post date:** [January 2, 2019, 11:35am UTC](https://discourse.processing.org/t/opencv-contour-get-specific-point-x-y-values/7079/3 "2019-01-02T11:35:39Z")

</div>

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