Directly manipulating binary image

Hi there, I am working on a project where I run a small autonomous car through a track. I have some experience with opencv but I just can’t wrap my head around how to solve this. The problem is, I have a binary image (a lane mask) and I want to get small non overlapping squares of SxS ‘on’ pixels, or more importantly the centroids of all such squares. In opencv I would probably just directly iterate through the numpy array but I understand that is not recommended here. Is there any way to do this? Please let me know if any additional info is required.

Some extra context in case there’s better ways to go about it, I am using something like pseudo vector field to navigate the car. I want each centroid to give it some sort of ‘push’ (magnitude and angle) based on its location in the frame. I already have done some preprocessing like perspective transform, lens correction as well as thresholding to detect lane lines (they’re colour coded in this context)

edit: I have also looked at find blobs but for this exact use case I’m not sure how to use it outside of running it on lots of small regions of interest which may be inefficient. I will also be working with low quality images QVGA or even QQVGA so there might be some leeway with efficiency but I have to repeat this process on at least three individual masks.

Hi, you want to just run find_blobs() on small regions of interest. There’s no speed difference here really as each region has less pixels to process.

That said… how small of a region are we talking about though? Is it like 8x8? or smaller?

Thanks! I was considering possible amortisation but wasn’t sure.

As for the region size, that’s something I’ll have to tune but around 10x10 is what I’d expect, wouldnt go any smaller.

Sound be fine then.