Coder Social home page Coder Social logo

Comments (2)

atduskgreg avatar atduskgreg commented on August 16, 2024

I think I know what the issue is here. Can you post your full sketch so I can run it locally?

from opencv-processing.

jorditost avatar jorditost commented on August 16, 2024

Hi Greg,

Sorry for the slow reply, I got your notification emails into the spam folder. Here's the complete sketch. The line that makes the sketch crash is the 40, where I set the color mode back to RGB. I tested it with the last lib version (0.45).

import gab.opencv.*;
import processing.video.*;
import java.awt.Rectangle;

Capture video;
OpenCV opencv;
PImage src, processedImage, cannyImage, contoursImage;
ArrayList<Contour> contours;

void setup() {

  video = new Capture(this, 640, 480);
  opencv = new OpenCV(this, video.width, video.height);
  size(video.width, video.height, P2D);

  contours = new ArrayList<Contour>();

  video.start();
}

void draw() {

  // Load current frame
  opencv.useColor();
  opencv.loadImage(video);
  src = opencv.getSnapshot();

  opencv.useColor(HSB); // Change to HSB color space
  opencv.setGray(opencv.getS().clone());
  opencv.threshold(95);
  opencv.erode();
  processedImage = opencv.getSnapshot();

  // Contours
  contours = opencv.findContours(true, true);
  contoursImage = opencv.getSnapshot();

  // Canny Edges
  opencv.loadImage(src);
  opencv.useColor(RGB); // Change back to RGB color space
  opencv.findCannyEdges(20,75);
  opencv.dilate();
  opencv.erode();
  cannyImage = opencv.getSnapshot();

  displayImages();
}

void displayImages() {
  pushMatrix();
  scale(0.5);
  image(src, 0, 0);
  image(processedImage, src.width, 0);
  image(cannyImage, 0, src.height);
  image(src, src.width, src.height);
  popMatrix();

  text("Source", 10, 25); 
  text("Pre-processed Image", src.width/2 + 10, 25); 
  text("Canny Edges", 10, src.height/2 + 25); 
  text("Contours", src.width/2 + 10, src.height/2 + 25);

  displayContours();
}

void displayContours() {

  pushMatrix();
  scale(0.5);
  translate(src.width, src.height);

  noFill();
  strokeWeight(3);

  for (Contour contour : contours) {

    Rectangle r = contour.getBoundingBox();

    if ((contour.area() > 0.9 * src.width * src.height) ||
        (r.width < 30 || r.height < 30))
      continue;

    stroke(255, 0, 0);
    fill(255, 0, 0, 150);
    strokeWeight(2);
    rect(r.x, r.y, r.width, r.height);
  }
  popMatrix();
}

void captureEvent(Capture c) {
  c.read();
}

from opencv-processing.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.