Finding the positions of multiple dots of the same colour in an image
I’m trying to implement something that tracks dots of the same colour in an image and outputs the position of each dot as a separate position value x,y.
The image is very simple and the only colours will be the dots. I think the best object for the job would be jit.findbounds, but I can’t quite figure out how to get it to track multiple dots rather than just one.
It’s possible I could create separate findbounds objects and use a different colour for each dot, but it might be a bit difficult as potentially there will be a lot of points that need to be tracked.
Is this at all possible to do?
How many is a lot? What resolution do they track properly at?
jit.findbounds could work for distinct colours then the question is how you intend to use the colours. If the purpose is to track each colour in the order in which it’s presented then you should be using cv.jit.blobs.sort.
Create binary images from each isolated colour point, recomposite the matrices, label and sort each blob.
However if you are using different coloured points that are meant to be treated differently (say each colored point represented orientation), then you don’t need to sort in the same way.
You can find the centre point of the bounding box given by jit.findbounds by using the formula:
expr ($f1 – $f2)/2 + $f2
A lot could be as many as 40 or more on a page ideally.
What I’m trying to do is to track the position of bar lines on a piece of music notation and be able to cycle through their positions in order, and then draw an item on top using lcd when needed (like in time with a metronome, tracking through the piece). The easiest way would be to have a fixed width between the bars, but most music is not like that and it’s difficult to create it like that with notation software, so I figured if I could analyse the image and create a list of points that represents at which point each bar is and in the right order, then that could work.
So I thought by creating an image version of the music with a coloured dot or blob over the bar then it could be analysed and represented as data. Although I might use a different colour for something like the end of a stave.
The cv.jit stuff looks promising. A problem might be with ordering the blobs, because a blob that is closest isn’t necessarily the next one (if two bar lines are directly over each other on different staves then it might be closer, it would need to somehow prioritise blobs to the right).
I’ll take a look at the cv.jit objects in a bit more depth and see what I can do with it, but any more suggestions would be muchly appreciated.
look to the newer cv.jit objects, especially cv.jit.touches, which deals with some of the sorting problems that cv.jit.blobs.centroids/sort have had (they index by the X axis, in a scan-like fashion, so when blobs overlap the axis their indices will swap). Looks like cv.jit.touches was designed for just this, and for multi-touch capability… thank you Jean-Marc!
BTW sounds like a *very* interesting idea with the notation, hope you can get it to work!