Skip to main content

Blog Post 2


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

Popular posts from this blog

First Algorithm Implementation

The Ramer Douglas Peucker Algorithm: We decided to use the Ramer Douglas Peucker algorithm in order to perform shape recognition. This algorithm takes a set of points as an input and attempts to extrapolate away all extraneous points and reduce the number of points down to the essentials that make up the shape. The idea behind using this algorithm for our project was to see if we could find a range of points that generally characterizes certain shapes. In other words, if we could determine that a general sphere could be made up by, say, five points after being refined to no longer contain extraneous points, we could set that as a known value for spheres and recognize all shapes with five points as spheres.    Wikipedia     However, we ran into some trouble actually using this algorithm because we needed contours, or lists of points, to run through the algorithm. Because contour detection isn’t something we planned to have implemented yet, we are currently using OpenC