Note that you can also publish a notebook as âunlistedâ. That way it will be accessible to anyone who has the link, but wonât be listed publicly on your profile or in the global list of recently published notebooks.
Very handy if youâre still working on a notebook but want to show it someone else.
And instead of forking the OpenCV notebook, I recommend just importing cv into your own notebook:
@mootari I need to find centroid coordinate points for all the circles. I think the Watershed link you shared is not computing centroid coordinate points. Iâm much familiar with Python OpenCV. So, I decided to use OpenCV.JS. It will be fine for me if you want to use any other libraries.
@mootari Could you please tell me how can I define center as a global variable? Also is it possible to get X and Y coordinates separately? Something like below const {centerX, CenterY} = new cv.Point(m10 / m00, m01 / m00);
These kinds of questions are best answered by the OpenCV API docs. E.g., if you look at the reference for cv::Point, youâll see x and y listed under public attributes.
Be sure to name your cell, then collect the x/y values into an array that you return:
centers = {
// ... Skipping over getting the image data and contours. ...
const coordinates = [];
for(let i = 0; i < contours.size(); i++) {
const {m00, m01, m10} = cv.moments(contours.get(i));
if(m00 === 0) continue;
const {x, y} = new cv.Point(m10 / m00, m01 / m00);
coordinates.push({x, y});
// Or, if you prefer an array of arrays:
//coordinates.push([x, y]);
};
// ... remember to call .delete() on any cv objects before returning, to avoid memory leaks. ...
return coordinates;
}