Identifying rectangles within an image (using OpenCV?)

edited November 2013 in Library Questions

Hey :) I've been trying to identify rectangles for quite some time using OpenCV and C++ for quite some time and the results varied, but turned out okay. Now I'm trying to do the same thing in Processing, but I'm not really having a good time doing it... I've been trying to use OpenCV for Processing to do so, but It's being difficult because the Processing version of OpenCV because the syntax is wildly different and it seems to be missing some of the methods that I was absolutely relying on. A friend of mine said that it could probably be done without OpenCV altogether by using built-in Processing image processing methods, but I'm not sure where to begin with that. I have no idea how to approximate a polygons in Processing, but in C++ I could use opencv.approxPoly(args), ignore anything with more than four sides or angles far from 90 degrees, and average the corner coordinated to get the centre coordinates. Is there a systematic (or built in) way to approximate polygons in Processing? I've gotten pre-processing pretty much figured out (threshold, erode, and dilate with or without OpenCV), and here is my progress so far (the point from which I will begin identifying rectangles): http://imgur.com/jVNiRq9. And here's the code to get that far (using OpenCV):

import gab.opencv.*;

OpenCV opencv;
PImage src, canny;

void setup() {
  src = loadImage("test4.png");
  size(src.width*2, src.height, P2D);

  opencv = new OpenCV(this, src);

  opencv.findCannyEdges(20,75);
  canny = opencv.getSnapshot();
}


void draw() {
  pushMatrix();
  scale(1);
  image(src, 0, 0);
  image(canny, src.width, 0);
  popMatrix();

  text("Source", 10, 25); 
  text("Canny", src.width + 10, 25);
  //saveFrame();
}

Does anyone have any suggestions for where to go from here? Thanks!

Sign In or Register to comment.