本文整理了Java中org.opencv.imgproc.Imgproc.HoughCircles()
方法的一些代码示例,展示了Imgproc.HoughCircles()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Imgproc.HoughCircles()
方法的具体详情如下:
包路径:org.opencv.imgproc.Imgproc
类名称:Imgproc
方法名:HoughCircles
[英]Finds circles in a grayscale image using the Hough transform.
The function finds circles in a grayscale image using a modification of the Hough transform. Example: ``
// C++ code:
#include
#include
#include
using namespace cv;
int main(int argc, char argv)
Mat img, gray;
if(argc != 2 && !(img=imread(argv[1], 1)).data)
return -1;
cvtColor(img, gray, CV_BGR2GRAY);
// smooth it, otherwise a lot of false circles may be detected
GaussianBlur(gray, gray, Size(9, 9), 2, 2);
vector circles;
HoughCircles(gray, circles, CV_HOUGH_GRADIENT,
2, gray->rows/4, 200, 100);
for(size_t i = 0; i < circles.size(); i++)
Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
int radius = cvRound(circles[i][2]);
// draw the circle center
circle(img, center, 3, Scalar(0,255,0), -1, 8, 0);
// draw the circle outline
circle(img, center, radius, Scalar(0,0,255), 3, 8, 0);
namedWindow("circles", 1);
imshow("circles", img);
return 0;
Note: Usually the function detects the centers of circles well. However, it may fail to find correct radii. You can assist to the function by specifying the radius range (minRadius
and maxRadius
) if you know it. Or, you may ignore the returned radius, use only the center, and find the correct radius using an additional procedure.
Note:
minRadius
和maxRadius
),则可以通过指定半径范围来辅助该函数。或者,您可以忽略返回的半径,仅使用中心,然后使用其他步骤找到正确的半径。代码示例来源:origin: openpnp/openpnp
public FluentCv findCirclesHough(int minDiameter, int maxDiameter, int minDistance,
String... tag) {
Mat circles = new Mat();
Imgproc.HoughCircles(mat, circles, Imgproc.CV_HOUGH_GRADIENT, 1, minDistance, 80, 10,
minDiameter / 2, maxDiameter / 2);
store(circles, tag);
return this;
}
代码示例来源:origin: openpnp/openpnp
@Override
public Result process(CvPipeline pipeline) throws Exception {
Mat mat = pipeline.getWorkingImage();
Mat output = new Mat();
Imgproc.HoughCircles(mat, output, Imgproc.CV_HOUGH_GRADIENT, dp, minDistance, param1,
param2, minDiameter / 2, maxDiameter / 2);
List<Result.Circle> circles = new ArrayList<>();
for (int i = 0; i < output.cols(); i++) {
double[] circle = output.get(0, i);
double x = circle[0];
double y = circle[1];
double radius = circle[2];
circles.add(new Result.Circle(x, y, radius * 2.0));
}
output.release();
return new Result(null, circles);
}
}
代码示例来源:origin: openpnp/openpnp
Imgproc.HoughCircles(mat, output, Imgproc.CV_HOUGH_GRADIENT, dp,
minDistance,
param1, param2,
代码示例来源:origin: us.ihmc/IHMCPerception
Imgproc.HoughCircles(thresholdMat, houghCirclesOutputMat, Imgproc.CV_HOUGH_GRADIENT, 1, thresholdMat.rows() / 8, 100, 15, 0, 0);
代码示例来源:origin: us.ihmc/ihmc-perception
Imgproc.HoughCircles(thresholdMat, houghCirclesOutputMat, Imgproc.CV_HOUGH_GRADIENT, 1, thresholdMat.rows() / 8, 100, 15, 0, 0);
代码示例来源:origin: openpnp/openpnp
public static Mat houghCircles(Mat mat, double minDiameter, double maxDiameter,
double minDistance) {
Logger.debug("houghCircles(Mat, {}, {}, {})",
new Object[] {minDiameter, maxDiameter, minDistance});
saveDebugImage(OpenCvUtils.class, "houghCircles", "input", mat);
// save a copy of the image for debugging
Mat debug = mat.clone();
// hough requires grayscale images
mat = toGray(mat);
// and prefers a blurred image
mat = gaussianBlur(mat, 9);
// run the houghcircles algorithm
Mat circles = new Mat();
Imgproc.HoughCircles(mat, circles, Imgproc.CV_HOUGH_GRADIENT, 1, minDistance, 80, 10,
(int) (minDiameter / 2), (int) (maxDiameter / 2));
if (LogUtils.isDebugEnabled()) {
drawCircles(debug, circles);
saveDebugImage(OpenCvUtils.class, "houghCircles", "debug", debug);
}
saveDebugImage(OpenCvUtils.class, "houghCircles", "output", mat);
return circles;
}
代码示例来源:origin: JavaOpenCVBook/code
Imgproc.HoughCircles(canny, circles,Imgproc.CV_HOUGH_GRADIENT, 1, canny.rows()/8, 200, lowThreshold, 0, 0 );
System.out.println(circles.size());
for( int i=0;i<circles.cols();i++){
内容来源于网络,如有侵权,请联系作者删除!