Skip to content
This repository has been archived by the owner on Mar 17, 2020. It is now read-only.

Commit

Permalink
findContours correct handle
Browse files Browse the repository at this point in the history
As stated in issue #1, the findContours is throwing a error in the new versions of opencv. To handle this error created an if to handle the opencv version in use.
  • Loading branch information
BlueDi committed Feb 25, 2019
1 parent 0d4fa05 commit 0e73b6f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion color_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ def filter_color(rgb_image, lower_bound_color, upper_bound_color):

def getContours(binary_image):
"""Calculates the contours of the image"""
_, contours, hierarchy = cv2.findContours(binary_image, cv2.RETR_TREE,
(opencv_version, _, _) = cv2.__version__.split(".")
if int(opencv_version) < 4:
_, contours, hierarchy = cv2.findContours(mask, cv2.RETR_TREE,
cv2.CHAIN_APPROX_SIMPLE)
else:
contours, hierarchy = cv2.findContours(mask, cv2.RETR_TREE,
cv2.CHAIN_APPROX_SIMPLE)
return contours

Expand Down
7 changes: 6 additions & 1 deletion video_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ def hand_detection(frame, lower_bound_color, upper_bound_color, left):
mask = cv2.erode(mask, kernel, iterations=3)
mask = cv2.GaussianBlur(mask, (5, 5), 90)

_, contours, hierarchy = cv2.findContours(mask, cv2.RETR_TREE,
(opencv_version, _, _) = cv2.__version__.split(".")
if int(opencv_version) < 4:
_, contours, hierarchy = cv2.findContours(mask, cv2.RETR_TREE,
cv2.CHAIN_APPROX_SIMPLE)
else:
contours, hierarchy = cv2.findContours(mask, cv2.RETR_TREE,
cv2.CHAIN_APPROX_SIMPLE)
try:
cnt = max(contours, key=lambda x: cv2.contourArea(x))
Expand Down

0 comments on commit 0e73b6f

Please sign in to comment.