The obvious thing to do first is discarding any edges that don't belong to a rectangle. The best case is if your rectangles are all oriented the same direction as the camera. In that case, discard any edge that's not North-South or East-West. If the rectangles all have the same orientation, but the camera doesn't, find the dominant direction module 90 degrees, and discard any outlier edges. The worst case is when the rectangles all have different orientations. In that case, you'd still expect edge direcions to cluster: for every edge, there should be at least one parallel and two orthogonal edges. Discard any unmatched edge. (This assumes you find edges more than a few pixels long; it's hard to deterimine the angle of shorter edges.)
After you've eliminated spurious edges by direction, the next step is to see whether you can connect them. You should still have them grouped by angle from the previous step. Now, assume that edges which are aligned belong to the same rectangle, and replace them with a single longer edge. This may cause fake edges between aligned rectangles. This is probably not a major problem, but if it is, fix it with a validation step at the end.
It's likely your edge finder will not work well near corners, because the real edge changes direction abruptly there. Hence, you should extend the edges you've found by a few pixels.
The extended edges will now produce a whole bunch of crossings. Again, take advantage of the fact that you've ordered your edges by direction. Just check for crossings of almost-orthogonal edges. If you find them, create a "crossing" object and associate it with the two edges. They're the tentative corners.
Once you've doe this, look for edges which have at least 2 crossings and see if you can match them up. Depending on the quality of your data, you may want to decide you've found a rectangle when you have 3 or 4 corners. If you find too many crossings on a single edge, you might have connected the edges of two aligned rectangles. This can be especially hard if you have rectangles that are aligned on both sides:
_ _
|_|_|