From 35cedd0907267d251e210d58bfacd2f8ce7d1934 Mon Sep 17 00:00:00 2001 From: Vividha Date: Fri, 14 May 2021 20:00:48 +0530 Subject: [PATCH] To solve the "too many values to unpack" error In some opencv versions cv2.findContours returns 2 variables i.e contours, hierarchy or 3 variables i.e image, contours, hierarchy. Hence to avoid this version problem added list slicing which would always return the last two values so whether it returns 2 or 3 values it won't give an error. --- leaf sampler/leafdetectionALLmix.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/leaf sampler/leafdetectionALLmix.py b/leaf sampler/leafdetectionALLmix.py index a794c49..19bf437 100644 --- a/leaf sampler/leafdetectionALLmix.py +++ b/leaf sampler/leafdetectionALLmix.py @@ -134,7 +134,7 @@ def printProgressBar (iteration, total, prefix = '', suffix = '', decimals = 1, #contour to find leafs bordered = cv2.cvtColor(canny,cv2.COLOR_BGR2GRAY) - contours,hierarchy = cv2.findContours(bordered, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE) + contours,hierarchy = cv2.findContours(bordered, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)[-2:] maxC = 0 for x in range(len(contours)): @@ -203,7 +203,7 @@ def printProgressBar (iteration, total, prefix = '', suffix = '', decimals = 1, #Finding contours for all infected regions - contours,heirarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE) + contours,heirarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)[-2:] Infarea = 0 for x in range(len(contours)):