Thanks very much for doing that for me. I just tested it. It does indeed work on some subjects, but on others, where there are even higher contrasting edges more out of focus, it detects those too. Not knowing much about that edge-detection algorithm, I would be in error of trying to suggest anything further, I think. Is there a way you could put in a menu option for line-thickness so this could be experimented with? Is that for the edge thickness being detected? Or only for the size of the lines being displayed? If the former, then it might just be the solution. If it's just for the display thickness, then it won't change anything for this intended use. I found that if I set the threshold quite high (around 180 or so), it does a better job at rejecting some of the out-of-focus edges. Perhaps combining that with thinner edge-detection might just act as a very effective precision manual focusing aid.
An easy way to test this is by putting a high-diopter (+6 or more) close-up filter on the camera. Then zooming in about halfway so you get a rather shallow DOF. Then try focusing at an angle to any surface with some texture (so the shallow DOF only cuts across part of the textured surface). You'll see the edge detection lines only highlighting those areas in focus. But as I said, if I put something like a black and white writing-pen in the field of view (something of even more contrast), then the lines also follow the edges of the pen into the very out of focus areas. Which makes me suspect that the algorithm being used to detect edges really can't be used effectively for this purpose. It appears to detect anything with high contrasting regions even if out of focus, rather than only those that are finer and in focus.