Created
April 24, 2015 19:04
-
-
Save atduskgreg/7448a49ffd1d3545008b to your computer and use it in GitHub Desktop.
opencv_processing_hough_circles_example.pde
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gab.opencv.*; | |
import org.opencv.imgproc.Imgproc; | |
import org.opencv.core.Mat; | |
OpenCV opencv; | |
PImage src; | |
ArrayList<Circle> circles; | |
void setup(){ | |
src = loadImage("cans.jpg"); | |
src.resize(800,0); | |
opencv = new OpenCV(this, src); | |
size(opencv.width, opencv.height); | |
circles = new ArrayList<Circle>(); | |
} | |
void draw(){ | |
opencv.loadImage(src); | |
// opencv.setROI(mouseX, mouseY, 90, 100); | |
// opencv.threshold(190); | |
image(opencv.getOutput(),0,0); | |
noFill(); | |
stroke(0,255,0); | |
strokeWeight(3); | |
for(Circle circle : circles){ | |
circle.draw(); | |
} | |
} | |
void keyPressed(){ | |
findCircles(); | |
} | |
void findCircles(){ | |
Mat cs = new Mat(); | |
println("find hough circles"); | |
Imgproc.HoughCircles(opencv.getGray(), cs, Imgproc.CV_HOUGH_GRADIENT, opencv.getGray().rows()/20, 50); | |
println(); | |
for(int i = 0; i < cs.cols(); i++){ | |
println(i); | |
circles.add(new Circle((float)cs.get(0,i)[0], (float)cs.get(0,i)[1], (float)cs.get(0,i)[2])); | |
} | |
println(cs.cols() + "x" + cs.rows()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment