Debugging the RDP Algorithm
The Problem
Even though we had
the proper input for the RDP algorithm, we weren't getting useful or
consistent results from it. This was partially due to our not knowing
the algorithm very well, but even when we managed to understand
enough to see what it was supposed to be doing, we found that it
wasn't performing correctly. We consistently got results that varied
between runs and were impossible for a given shape because there were
either no lines or far too few to actually make up the shape. After
checking the logic of the algorithm numerous times with as many
sources as we could, in addition to going over the code with a fine
toothed comb, we found nothing out of place or wrong. It was only at
that point that we decided it would be worthwhile to check what the
contoured image actually looked like and see what was happening.
The Hunt
It turned out that
the cv2.blur() function we were using to simulate the effects of the
camera turning was actually causing the contour detection to miss
entire sections of shapes. For instance, the circle was contoured
such that it was divided up into four, unconnected contours. This was
a major source of error, but even when this was removed we ended up
with strange values. We knew for a fact that a circle couldn't be
reasonably smoothed out to one line, but that was exactly what our
algorithm was telling us. We tried messing with the epsilon, figuring
that we were getting rid of important lines, but all we got for our
trouble was exceeding maximum recursion depth in Python and no real
changes in the values.
The Resolution
The code wasn't
wrong, the algorithm was doing the right thing, but we were not
getting what we wanted. After filling almost the entire code with
print statements to confirm things were happening the way we thought
they were, we found that our distance function was not finding the
distance from the closest point on the line, but instead, just the y
value from one of our points. Finally having located the error, we
were able to readdress that section of code and make it a functional
part of the system. This is certainly a testament to the mantra:
“test your code in isolated sections before combining it.”
Comments
Post a Comment