We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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 http://www.pyimagesearch.com/2016/02/08/opencv-shape-detection/ .
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.*;
import processing.video.*;
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
webCam.start();
}
void captureEvent(Capture webCam) {
webCam.read();
}
void draw(){
image(webCam, 0, 0);
if(foreGExists){
set(0, 0, finalImg);
}else{
set(0,0, webCam);
}
}
void keyPressed(){
if( key == 'b' ){
PImage temp = new PImage(640, 480);
temp.loadPixels();
temp.pixels = webCam.pixels;
temp.updatePixels();
finalImgcv = new OpenCV(this, temp);
}
if( key == 'f' ){
finalImgcv.diff(webCam);
finalImgcv.threshold(10);
finalImg = finalImgcv.getSnapshot();
contours = finalImgcv.findContours();
println("found " + contours.size() + " contours");
M = contours.get(0);
foreGExists = true;
}
}
Answers
Try the $1 Unitroske Recognizer library available through the library manager in the processing IDE.
Kf