I want to create an AI to detect and identify certain edge lines on my image. The input image is a locker key, and I want to know the exact position of certain edges.

Sample input image:

enter image description here

Sample output image. As output i have each red line position.

enter image description here

I was thinking in finetuning some kind of instace segmentation or even yolo network but maybe there is a better approach. Ideally, I would like the software to be light enoguh to run in a mobilephone.

I also considered two "simpler" approaches:

  • Using corner detection
  • Using Unet to get the contour + opencv approxpoly to get straight lines coordinates

Nevertheless, I believe I would obtain a more consistent result with more advanced AI. (I do have a lot of training images to use)

  • $\begingroup$ Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. $\endgroup$
    – Community Bot
    Jun 6 at 13:51
  • $\begingroup$ Please, put your specific question in the title. "Precision edge identification" is not a question and it's also not specific. A question is something like "What is 2+2?". $\endgroup$
    – nbro
    Jun 7 at 20:25

1 Answer 1


I don't think that more advanced AI would necessarily produce more consistent results. Check something as simple as the Prewitt operator, which is pretty damn good at edge detection. I would suggest starting with something simple, looking at what are the failure edge cases (pun unintended), and only use a more complicated network if the failure cases are plenty and addressable by some more advanced technique.

  • $\begingroup$ The problem is that when I detect edges is hard to identify and diferentiate the actual edge lines. For example, in this image first and second from the left are really close, how can I actualy obtain the points that define the lines? Also consider some images have more shadows or lights... $\endgroup$
    – Lluis C
    Jun 6 at 13:03
  • $\begingroup$ I suppose this boils down to how you define edges. My previous suggestion would basically identify the boundaries of the object that's on the picture, not just the top "edges" as you call them. Your definition of edges is thus different, more nuanced than the usual ML edge-detection tasks which try to identify outlines of the objects in the picture. $\endgroup$
    – ImotVoksim
    Jun 6 at 13:14
  • 1
    $\begingroup$ I think your second proposed approach is worth trying. Get the whole outline of the object using whatever edge-detection CNN you have at your disposal and create a function that identifies straight lines that lie on the pixels that correspond to the outline. $\endgroup$
    – ImotVoksim
    Jun 6 at 13:18
  • $\begingroup$ thanks, I edited the post to clarify my definition of edges $\endgroup$
    – Lluis C
    Jun 6 at 14:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .