Created
October 31, 2012 16:52
-
-
Save nikhil9/3988244 to your computer and use it in GitHub Desktop.
Hough Circle detection in Javacv
This file contains hidden or 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 static com.googlecode.javacv.cpp.opencv_core.*; | |
import static com.googlecode.javacv.cpp.opencv_highgui.*; | |
import static com.googlecode.javacv.cpp.opencv_imgproc.*; | |
public class circleDetection{ | |
public static void main(String[] args){ | |
IplImage src = cvLoadImage("img2.png"); | |
IplImage gray = cvCreateImage(cvGetSize(src), 8, 1); | |
cvCvtColor(src, gray, CV_BGR2GRAY); | |
cvSmooth(gray, gray, CV_GAUSSIAN, 3); | |
CvMemStorage mem = CvMemStorage.create(); | |
CvSeq circles = cvHoughCircles( | |
gray, //Input image | |
mem, //Memory Storage | |
CV_HOUGH_GRADIENT, //Detection method | |
1, //Inverse ratio | |
100, //Minimum distance between the centers of the detected circles | |
100, //Higher threshold for canny edge detector | |
100, //Threshold at the center detection stage | |
15, //min radius | |
500 //max radius | |
); | |
for(int i = 0; i < circles.total(); i++){ | |
CvPoint3D32f circle = new CvPoint3D32f(cvGetSeqElem(circles, i)); | |
CvPoint center = cvPointFrom32f(new CvPoint2D32f(circle.x(), circle.y())); | |
int radius = Math.round(circle.z()); | |
cvCircle(src, center, radius, CvScalar.GREEN, 6, CV_AA, 0); | |
} | |
cvShowImage("Result",src); | |
cvWaitKey(0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello ! sorry to disturb,.
I am trying your code, put in my case the new green circle drawn on the src image is not around the existing image!
Do you know with parameter , I should play with to make the green circle match my existing image?
Thanks!
Elder