Ask Your Question
0

how to find supported format for findContours?

asked 2020-03-13 05:50:54 -0600

updated 2020-03-13 06:43:23 -0600

berak gravatar image

/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:248: UserWarning: /content/drive/My Drive/deskew.png is a low contrast image

---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-23-0ba3ae2fa94a> in <module>()
    529 for image in arr:
    530   #print(image)
--> 531   process_image(image,'drive/My Drive/myfolder/'+str(count)+'.png')
    532   count=count+1
    533 

1 frames
<ipython-input-23-0ba3ae2fa94a> in find_components(edges, max_components)
    361         n += 1
    362         dilated_image = dilate(edges, N=3, iterations=n)
--> 363         contours, hierarchy = cv2.findContours(dilated_image, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
    364         count = len(contours)
    365     #print dilation

error: OpenCV(4.1.2) /io/opencv/modules/imgproc/src/contours.cpp:19

7: error: (-210:Unsupported format or combination of formats) [Start]FindContours supports only CV_8UC1 images when mode != CV_RETR_FLOODFILL otherwise supports CV_32SC1 images only in function 'cvStartFindContours_Impl'

code::

def find_components(edges, max_components=16):
    """Dilate the image until there are just a few connected components.
    Returns contours for these components."""
    # Perform increasingly aggressive dilation until there are just a few
    # connected components.
    count = 21
    dilation = 5
    n = 1
    while count > 16:
        n += 1
        dilated_image = dilate(edges, N=3, iterations=n)
        contours, hierarchy = cv2.findContours(dilated_image, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
        count = len(contours)
    #print dilation
    #Image.fromarray(edges).show()
    #Image.fromarray(255 * dilated_image).show()
    return contours
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-03-13 06:44:04 -0600

berak gravatar image

updated 2020-03-13 06:58:39 -0600

please check np.dtype(dilate_image)

in other words, you need a numpy array with dtype=np.uint8

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-03-13 05:50:54 -0600

Seen: 9,637 times

Last updated: Mar 13 '20