Ask Your Question

Revision history [back]

how to find supported format for findContours?

/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

click to hide/show revision 2
None

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

berak gravatar image

how to find supported format for findContours?

/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

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

/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'

'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

contours