无法定义cv2.findContours()值错误显示

时间:2018-12-08 10:44:30

标签: python opencv

我知道cv2.findCountours()需要3个值并返回3个值,但是由于某种原因,我的代码无法通过初始化变量的方式工作 这是我的代码:

def findPossibleCharsInScene(imgThresh):
  listOfPossibleChars = []                # this will be the return value

  intCountOfPossibleChars = 0

  imgThreshCopy = imgThresh.copy()

  imgContours, contours, npaHierarchy = cv2.findContours(imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)   # find all contours

  height, width = imgThresh.shape
  imgContours = np.zeros((height, width, 3), np.uint8)

  for i in range(0, len(contours)):                       # for each contour

      if Main.showSteps == True: # show steps ###################################################
          cv2.drawContours(imgContours, contours, i, Main.SCALAR_WHITE)
      # end if # show steps #####################################################################

      possibleChar = PossibleChar.PossibleChar(contours[i])

      if DetectChars.checkIfPossibleChar(possibleChar):                   # if contour is a possible char, note this does not compare to other chars (yet) . . .
          intCountOfPossibleChars = intCountOfPossibleChars + 1           # increment count of possible chars
          listOfPossibleChars.append(possibleChar)                        # and add to list of possible chars
      # end if
  # end for

  if Main.showSteps == True: # show steps #######################################################
      print("\nstep 2 - len(contours) = " + str(len(contours)))  # 2362 with MCLRNF1 image
      print("step 2 - intCountOfPossibleChars = " + str(intCountOfPossibleChars))  # 131 with MCLRNF1 image
      cv2.imshow("2a", imgContours)
  # end if # show steps #########################################################################

  return listOfPossibleChars

0 个答案:

没有答案