HoughCircles
import { HoughCircles } from '@banou/opencv-wasm'Use after await initOpenCV(). See the initialization and named imports guide.
example: samples/cpp/tutorial_code/ImgTrans/houghcircles.cpp An example using the Hough circle detector example: samples/python/snippets/houghcircles.py An example using the Hough circle detector in python 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: :
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, in the case of #HOUGH_GRADIENT method you may set maxRadius to a negative number to return centers only without radius search, and find the correct radius using an additional procedure.
It also helps to smooth image a bit unless it's already soft. For example, GaussianBlur() with 7x7 kernel and 1.5x1.5 sigma or similar blurring may help.
See: fitEllipse, minEnclosingCircle
HoughCircles(image: Mat, circles: Mat, method: number, dp: number, minDist: number, param1: number, param2: number, minRadius: number, maxRadius: number): void;5 available overloads
HoughCircles(image: Mat, circles: Mat, method: number, dp: number, minDist: number): void;HoughCircles(image: Mat, circles: Mat, method: number, dp: number, minDist: number, param1: number): void;HoughCircles(image: Mat, circles: Mat, method: number, dp: number, minDist: number, param1: number, param2: number): void;HoughCircles(image: Mat, circles: Mat, method: number, dp: number, minDist: number, param1: number, param2: number, minRadius: number): void;HoughCircles(image: Mat, circles: Mat, method: number, dp: number, minDist: number, param1: number, param2: number, minRadius: number, maxRadius: number): void;image8-bit, single-channel, grayscale input image.
circlesOutput destination, filled by the native operation. Output vector of found circles. Each vector is encoded as 3 or 4 element floating-point vector
(x, y, radius)or(x, y, radius, votes).methodDetection method, see #HoughModes. The available methods are #HOUGH_GRADIENT and #HOUGH_GRADIENT_ALT.
dpInverse ratio of the accumulator resolution to the image resolution. For example, if dp=1 , the accumulator has the same resolution as the input image. If dp=2 , the accumulator has half as big width and height. For #HOUGH_GRADIENT_ALT the recommended value is dp=1.5, unless some small very circles need to be detected.
minDistMinimum distance between the centers of the detected circles. If the parameter is too small, multiple neighbor circles may be falsely detected in addition to a true one. If it is too large, some circles may be missed.
param1First method-specific parameter. In case of #HOUGH_GRADIENT and #HOUGH_GRADIENT_ALT, it is the higher threshold of the two passed to the Canny edge detector (the lower one is twice smaller). Note that #HOUGH_GRADIENT_ALT uses #Scharr algorithm to compute image derivatives, so the threshold value should normally be higher, such as 300 or normally exposed and contrasty images.
param2Second method-specific parameter. In case of #HOUGH_GRADIENT, it is the accumulator threshold for the circle centers at the detection stage. The smaller it is, the more false circles may be detected. Circles, corresponding to the larger accumulator values, will be returned first. In the case of #HOUGH_GRADIENT_ALT algorithm, this is the circle "perfectness" measure. The closer it to 1, the better shaped circles algorithm selects. In most cases 0.9 should be fine. If you want get better detection of small circles, you may decrease it to 0.85, 0.8 or even less. But then also try to limit the search range [minRadius, maxRadius] to avoid many false circles.
minRadiusMinimum circle radius.
maxRadiusMaximum circle radius. If <= 0, uses the maximum image dimension. If < 0, #HOUGH_GRADIENT returns centers without finding the radius. #HOUGH_GRADIENT_ALT always computes circle radiuses.
These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.