MCPcopy Create free account
hub / github.com/PyImageSearch/imutils / grab_contours

Function grab_contours

imutils/convenience.py:154–175  ·  view source on GitHub ↗
(cnts)

Source from the content-addressed store, hash-verified

152 return edged
153
154def grab_contours(cnts):
155 # if the length the contours tuple returned by cv2.findContours
156 # is '2' then we are using either OpenCV v2.4, v4-beta, or
157 # v4-official
158 if len(cnts) == 2:
159 cnts = cnts[0]
160
161 # if the length of the contours tuple is '3' then we are using
162 # either OpenCV v3, v4-pre, or v4-alpha
163 elif len(cnts) == 3:
164 cnts = cnts[1]
165
166 # otherwise OpenCV has changed their cv2.findContours return
167 # signature yet again and I have no idea WTH is going on
168 else:
169 raise Exception(("Contours tuple must have length 2 or 3, "
170 "otherwise OpenCV changed their cv2.findContours return "
171 "signature yet again. Refer to OpenCV's documentation "
172 "in that case"))
173
174 # return the actual contours array
175 return cnts
176
177def is_cv2(or_better=False):
178 # grab the OpenCV major version number

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…