I'm running into an interesting error with opencv 2.4.3 on python 2.7.3 on Windows. When attempting to use drawContours I get a "TypeError: contours data type = 5 is not supported" error unless I pickle/unpickle the contours first.
This doesn't work (I get the "TypeError: contours data type = 5 is not supported"):
noBg = cv2.blur(src, (5,5))
noBg = cv2.inRange(noBg, np.array([80, 0, 200], np.uint8), np.array([255, 50, 255], np.uint8))
noBg = np.invert(noBg)
contours, hierarchy = cv2.findContours(noBg, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(src, contours, -1, (0,255,0), 3)
But this does work:
noBg = cv2.blur(src, (5,5))
noBg = cv2.inRange(noBg, np.array([80, 0, 200], np.uint8), np.array([255, 50, 255], np.uint8))
noBg = np.invert(noBg)
contours, hierarchy = cv2.findContours(noBg, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
tmp = cPickle.dumps(contours)
contours = cPickle.loads(tmp)
cv2.drawContours(src, contours, -1, (0,255,0), 3)
Has anyone else seen this behavior or am I missing something obvious? I'm new to python/opencv so that may very well be the case.
Edit: Just tested this on my Mac, and both cases work fine. Maybe just a Windows problem?
If you downgrade to opencv 2.4.2 this will work. It appears to be a bug with 2.4.3 which was just released two weeks ago.
I have just experienced the same problem after getting OpenCV 2.4.3 when using contours from findContours and convexHull. As I did not want to downgrade, casting the contours array elements to int temporarily solves the problem.
contours, _ = cv2.findContours(noBg,cv2.RETR_LIST ,cv2.CHAIN_APPROX_SIMPLE,offset = (0,0))
hull_contour = cv2.convexHull(contours[0].astype('int'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With