-2

I'm having the following problem: I cannot find a way to access each connected component's first and last pixels which were obtained through cv2.connectedComponentsWithStats function of OpenCV in Python. What i want to do, is to suppress the connected components whose first pixel does not coincide with the its last one (hence, unsevered) . Any ideas?

Here's the code calling cv2.connectedComponentsWithStats and suppressing too small and too big connected components:

#Find connected components
    nb_components, output, stats, centroids = cv2.connectedComponentsWithStats(edges,connectivity=8)
    sizes = stats[1:, -1];
    nb_components = nb_components - 1

    #remove small and large connected components
    final_labels = np.array([])
    edges_filtered = np.zeros((output.shape),np.uint8)
    for i in range(0, nb_components):
        if sizes[i] >= MIN_CC_SIZE and sizes[i] <= MAX_CC_SIZE:
            edges_filtered[output == i + 1] = 255

    cv2.imshow("edges_filtered",edges_filtered)
    cv2.waitKey()
  • Can you add your code with the attempts you've made? – T A Dec 06 '19 at 13:51
  • I don't understand what you mean by "whose first pixel does not coincide with the its last one". Are you expecting the first and last pixel to be in the same location? And what do you mean by "keep only the fully connected ones"? All of the identified components are connected. Are you saying that the code you posted does not work? If so, what is wrong with it? – beaker Dec 07 '19 at 16:45
  • I edited the post, they are called unsevered. I didn't know the exact word, so i troubled you too much...Sorry! – George NeoGeo Dec 08 '19 at 12:36
  • "severed" is not a term I'm familiar with in connection with blob detection, and googling doesn't return any definitions for it. I wouldn't use it and expect people to understand what you mean. – beaker Dec 08 '19 at 17:21

1 Answers1

0

To answer my own question, after some search i found that what i wanted to do has already been done. Here is the post.