How to distinguish two shapes from another

edited June 2017 in Kinect

Hello, I'm trying to decide, if an object looks more like a rectangle or a circle!

I already transformed the image into a binary image and am using the OpenCV libary.

I've tried to work with the contour of the object, but didn't find a way to translate it from OpenCV examples like .

If anybody has an idea on where to start or just some code as an example, that would be great!

My Code so far :

import gab.opencv.*;

Capture webCam;
OpenCV finalImgcv, cv2;
PImage finalImg,  temp;
boolean foreGExists = false;
ArrayList<Contour> contours;
Contour M;

void setup(){
  size(640, 480);
  String[] cams = Capture.list();

  webCam = new Capture(this, width, height, cams[0], 30); // = name=Vimicro USB2.0 Camrera,size=640x480,fps=30

void captureEvent(Capture webCam) {;

void draw(){

  image(webCam, 0, 0);
     set(0, 0, finalImg);
     set(0,0, webCam);

void keyPressed(){

  if( key == 'b' ){
    PImage temp = new PImage(640, 480);
    temp.pixels = webCam.pixels;
    finalImgcv = new OpenCV(this, temp);


  if( key == 'f' ){
    finalImg = finalImgcv.getSnapshot();
    contours = finalImgcv.findContours();
    println("found " + contours.size() + " contours");
    M = contours.get(0);

    foreGExists = true;


  • Try the $1 Unitroske Recognizer library available through the library manager in the processing IDE.


Sign In or Register to comment.