circles = {
const cv = window.cv;
const src = cv.imread(image);
const grey = src.clone();
const blur = src.clone();
const canny = src.clone();
const ksize = new cv.Size(3, 3);
const sigma = [0, 0];
const borderType = cv.BORDER_DEFAULT;
const method = cv.HOUGH_GRADIENT;
const dp = 1.1;
const minDist = 12;
const param1 = 190;
const param2 = 14;
const minRadius = 2;
const maxRadius = 14;
cv.cvtColor(src, grey, cv.COLOR_RGBA2GRAY, 0);
cv.imshow('greyscale', grey);
cv.GaussianBlur(grey, blur, ksize, sigma[0], sigma[1], borderType);
cv.imshow('blur', blur);
cv.Canny(blur, canny, param1/2, param1, 3, false);
cv.imshow('edges', canny);
const circles = new cv.Mat();
cv.HoughCircles(blur, circles, method, dp, minDist, param1, param2, minRadius, maxRadius);
const color = [255, 0, 0, 255]; // colour for drawing circles
const thickness = 1; // thickness to draw circles, negative values mean filled
const lineType = 8; // '8-connected' line
const shift = 0; // Number of fractional bits in the coordinates of the center and in the radius value.
const dst = cv.Mat.zeros(src.rows, src.cols, cv.CV_8U); // setup output image
let circleOut = []; // store circle details
for (let i = 0; i < circles.cols; ++i) {
let x = circles.data32F[i * 3];
let y = circles.data32F[i * 3 + 1];
let radius = circles.data32F[i * 3 + 2];
let center = new cv.Point(x, y);
circleOut.push({x: x, y: y, radius: radius});
cv.circle(src, center, radius, color, thickness, lineType, shift); // outline
cv.circle(src, center, 1, [0, 255, 0, 255], -1, lineType, shift);
}
cv.imshow('output', src);
src.delete(); dst.delete(); circles.delete(); grey.delete(); blur.delete(); canny.delete();
return circleOut;
}