BUG: blob elongation can exceed 1, roundness can be negative

I am logging blob detections in a CSV and saw this happening several times: blob.roundness() and blob.elongation() are supposed to be bounded between 0 and 1 but in rare instances where I had very elongated blobs, elongation could become >1 but it would still be a sum of 1 because the corresponding roundness would be negative.

It would be good to detail how these values are actually calculated, for the sake of reproducibility.

PS: I am unsure whether this should be an openMV IDE GitHub issue instead.

It’s just this: openmv/py_image.c at master · openmv/openmv · GitHub

So the roundness is more than 1. openmv/blob.c at master · openmv/openmv · GitHub

It’s probably happening because the blob is being created out of merged blobs and when I’m accumulating the roundness of multiple blobs the average goes above 1 because floats are being used.

Alright thanks Kwabena for showing how they are calculated. I don’t understand how an average of float numbers below 1 can go above 1, but I suppose I don’t have to.

Floating point it’s exact so adding two numbers that should equal 1 may go above it.

Sorry I still don’t understand how an average of numbers bound between 0 and 1 can be above 1. If the elongation of a merged blob is the sum of its constituent blobs’ elongtations then yes, I understand, but you previously wrote about an average and then about an addition so I am confused…

Anyway, I had a closer look at the detections data. Out of 17 000 detections, I have 3900 with blob elongation above 1 or below 0. blob elongation can reach up to 600 000 (!) and down to -141. But the sum with the roundness will be always very close to 1.
In a nutshell, maybe there is still something fishy with the calculation of these numbers? Because they do not make sense, and are not usable as they are.

It’s because I use an accumulator to add floating point numbers. I thought this might bite me when doing this but it was working okay so I didn’t change it.

It’s only safe to do math in floating point when you control the order of operations. Using a float as an accumulator can cause issues like this.

Again, the roundness value of it goes larger than 1 will result in a negative elongation. Roundness will go larger than 1 because the sum of multiple floating point numbers may result in a number less than the actual expected sum of the numbers have very different exponents. The sum is used to compute an average. So, if it’s too small then the result will be larger than expected.