Detect holes, ends and beginnings of a line using openCV?
<p>I'm trying to create a Python script that detects holes, ends and beginnings of a line. I thought that openCV would be great to achieve this.</p>

<p>So for example everything starts with this image:</p>

<p><a href="https://i.stack.imgur.com/sojmN.png" rel="noreferrer"><img src="https://i.stack.imgur.com/sojmN.png" alt="enter image description here"></a></p>

<p>finally what I want to achieve is this: </p>

<p><a href="https://i.stack.imgur.com/abiRm.png" rel="noreferrer"><img src="https://i.stack.imgur.com/abiRm.png" alt="enter image description here"></a></p>

<p>So I began with importing the image into Python and converting it in grayscale. Now I came to the idea to track the holes by using the <code>goodFeaturesToTrack()</code> method. It's normally used to find corners in the image.</p>

<p>However that didn't work so well because after that the script knows the points, but it doesn't know if a point is from a hole or if it's the beginning or end of the line. Another problem is that if I use another image this method detects more points than just the holes, beginnings and ends of the line.</p>

<p>Here is my full code to understand my problem a bit better:</p>

<pre><code>import cv2
import numpy as np
import matplotlib.pyplot as plt

# lodes in img

img = cv2.imread('png1.png', cv2.IMREAD_COLOR)
img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

corners = cv2.goodFeaturesToTrack(img_gray, 200, 0.05, 10)

for corner in corners:
    x, y = corner.ravel()
    cv2.circle(img, (x,y), 7, (255,255,0), -1)

cv2.imshow('img',img)
</code></pre>

<p>I have no idea to get around this problem.</p>