0

I'm using cv2.findcontours() which outputs a variable number of variable length Nx2 tuples.

For example, converting the tuples to a list:

    (array([[[100, 100]], ..., [[200, 200]]], dtype=int32), array([[[50, 50]], ..., [[300, 300]]], dtype=int32))

It's easy when you know the number of outputs to expect:

    a,b = cv2.findcontours()

I've tried awkward arrays, but I can't figure out how to access the arrays individually.

  • first, you would do yourself a favor if you **didn't** call those parts `a` and `b`. say `(contours, hierarchy) = cv.findContours...` -- depending on OpenCV version, findContours may return 2 (usually) or 3 values (v3.x). there's no reason to use anything other than the latest, which is 4.x, so you can safely stick with the 2-tuple return -- then, your perception of types does not match reality. `contours` is a list/tuple of numpy arrays, each of which describes one contour (as points). don't be spooked by it being a "tuple". practically it's a list. – Christoph Rackwitz Jul 16 '22 at 06:52
  • Thanks! I got confused with the indexing notation (list or array or both). I can access each numpy array as contours[idx] – Bob Bobinson Jul 16 '22 at 14:50

0 Answers0