Given a thresholded image with a small number (1-3) blobs in it, I'd like to pick the blob closest to the centre, which I expect to be a digit:
I'd like to extract the red rectangle as a separate Mat, since it's closest to the centre (green dot). My first thought is to iterate through all the blobs in the image and take the one with the smallest distance, pixelwise, from its centroid to the image centre. However, I'm not familiar with the vast majority of OpenCV functions (and there are a lot of them!) so I'm wondering if there's a better way.
I can already see a couple of problems with this, though:
- If the box on the outside covered 3 or 4 sides, the centroid might be close to the centre even though the box itself is nowhere near the centre. Perhaps I should use a higher-order moment to give more weight to points far away from the centre?
- OpenCV has no integrated blob-finding (or connected-component labeling) library that I know of. I could use find contours, but this might be inaccurate for numbers like 6, 8 or 9 with an interior portion.