OpenCV 3.0 Python findContours fails (Bug #3809)


Added by T Nguyen over 10 years ago. Updated over 10 years ago.


Status:Done Start date:2014-07-12
Priority:Normal Due date:
Assignee:T Nguyen % Done:

0%

Category:imgproc, video
Target version:3.0
Affected version:branch 'master' (3.0-dev) Operating System:Mac OSX
Difficulty: HW Platform:x64
Pull request:

Description

OpenCV Error: Assertion failed (_contours.kind() _InputArray::STD_VECTOR_VECTOR && _contours.channels() 2 && _contours.depth() CV_32S) in findContours, file /Users/dora/devzone/opencv/modules/imgproc/src/contours.cpp, line 1708

cv2.error: /Users/dora/devzone/opencv/modules/imgproc/src/contours.cpp:1708: error: (-215) _contours.kind() _InputArray::STD_VECTOR_VECTOR && _contours.channels() 2 && _contours.depth() CV_32S in function findContours


History

Updated by Daniil Osokin over 10 years ago

Hi, thanks for response! Looks like this isn't a bug: assertion failed means, that you pass wrong arguments for some step in function. If there is really bug, please preovide a code sample to reproduce that (feel free to reopen the ticket).

  • Assignee set to T Nguyen
  • Category set to imgproc, video
  • Status changed from New to Cancelled

Updated by dpk 3062 over 10 years ago

The Python tutorial has the following code that triggers this issue (requires a test.jpg):

import numpy as np
import cv2

im = cv2.imread('test.jpg')
imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(imgray,127,255,0)
contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)

Here's a standalone version

import numpy as np
import cv2

im = np.zeros((10,10))
contours, hierarchy = cv2.findContours(im,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)

I'm on Windows 7 x64, but am using Python 3.4.1 32bit. If the bug isn't in the code, then the tutorial needs updating.

Python tutorial: http://docs.opencv.org/trunk/doc/py_tutorials/py_imgproc/py_contours/py_contours_begin/py_contours_begin.html
Related question on StackOverflow: http://stackoverflow.com/questions/24716122/opencv-python-contour-assertion-failed
Link to commit which StackOverflow thinks caused the issue: https://github.com/Itseez/opencv/commit/6f2fea7ea5f3f61cee860168700537165f3a77db

  • Status changed from Cancelled to Open

Updated by dpk 3062 over 10 years ago

The section of the assert that is failing is:

_contours.kind() == _InputArray::STD_VECTOR_VECTOR
Unfortunately I'm not able to debug this further.

Updated by T Nguyen over 10 years ago

Hi there,

The sample code is like dpk 3062 suggests and it doesn't work. Following the documentation http://docs.opencv.org/trunk/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html#findcontours

it seems like the sample code isn't coherent with the docs. The docs says the function findContours return 3 values:

Python: cv2.findContours(image, mode, method[, contours[, hierarchy[, offset]]]) → image, contours, hierarchy

However, even when I try as the docs, I still have that issue.

By the way, I confirm the function works fine in C++.

  • Target version set to 3.0

Updated by Sander van Veen over 10 years ago

  • Status changed from Open to Done

Also available in: Atom PDF