Connecting points with lines
in
Contributed Library Questions
•
4 months ago
I have been working on this openCV project and I am looking to connect the final dots together, literally.
How can I get the points from the blobs to draw lines from one another?
I tried to make a PVector array from a few pieces of code and I feel like I am getting close just missing the last part.
- import hypermedia.video.*;
- import java.awt.Rectangle;
- import java.awt.Point;
- OpenCV opencv;
- int LIMIT = 300;
- int cvthreshold = 80;
- int blur = 5;
- PVector[] vex;
- int numpoints;
- void setup() {
- size(640, 480, P3D);
- opencv = new OpenCV(this);
- opencv.allocate(640, 480);
- opencv.capture(640, 480);
- vex = new PVector[numpoints];
- // for(int i = 0; i < vex.length; i++){
- // vex[i] = new PVector(random(50,width-50), random(50,height-50));
- //
- // }
- }
- void draw() {
- background(10);
- opencv.read();
- opencv.blur(OpenCV.BLUR, blur);
- opencv.threshold(cvthreshold);
- image(opencv.image(), 0, 0, 640, 480);
- Blob[] blobs = opencv.blobs(20, width*height/50, 40, true);
- int numpoints = blobs.length;
- println("Number of points =" + numpoints);
- noFill();
- pushMatrix();
- for (int i = 0; i < blobs.length; i++) {
- Rectangle bounding_rect = blobs[i].rectangle;
- float area = blobs[i].area;
- float circumference = blobs[i].length;
- Point centroid = blobs[i].centroid;
- Point centroid2 = blobs[i].centroid;
- stroke(255, 255, 255, 150);
- strokeWeight(2);
- // line(centroid.x, centroid.y, 0, 0); // Top Left
- // line(centroid.x, centroid.y, 640, 0); // Top Right
- // line(centroid.x, centroid.y, 0, 480); // Bottom Left
- // line(centroid.x, centroid.y, 640, 480); // Bottom Right
- noStroke();
- stroke(255);
- strokeWeight(5);
- point(centroid.x, centroid.y);
- noStroke();
- fill(100, 100);
- ellipse(centroid.x, centroid.y, 50, 50);
- ellipse(centroid.x, centroid.y, 35, 35);
- }
- //// //DRAWS LINES
- // for (int t = 0; t < vex.length; t++) {
- // PVector pv1 = vex[t];
- // for (int g = 0; g < vex.length; g++) {
- // PVector pv2 = vex[g];
- // float d = dist(pv1.x, pv1.y, pv2.x, pv2.y);
- // if (d <= LIMIT) {
- // line(pv1.x, pv1.y, pv2.x, pv2.y);
- // }
- // }
- // }
- popMatrix();
- }
- //This allows you to use the mouse the adjust blur and threshold
- void mouseDragged() {
- cvthreshold = int( map(mouseX, 0, width, 0, 255) );
- blur = int( map(mouseY, 0, height, 50, 0) );
- }
1