OpenCV Contours - need more than 2 values to unpack

前端 未结 9 1693
旧时难觅i
旧时难觅i 2020-12-17 10:39

I am trying to implement contours using the following code..

im = cv2.imread(\'C:\\Users\\Prashant\\Desktop\\T.jpg\')
imgray = cv2.cvtColor(im,cv2.COLOR_BGR2         


        
9条回答
  •  一整个雨季
    2020-12-17 10:47

    Python version 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:25:58) [MSC v.1500 64 bit (AMD64)]

    NumPy version: 1.16.1

    argparse version: 1.1

    CV2 version: 4.0.0

    Traceback (most recent call last):
    
      File "omr.py", line 254, in 
    
        main()
    
      File "omr.py", line 237, in main
    
        answers, im = get_answers(args.input)
    
      File "omr.py", line 188, in get_answers
    
        contours = get_contours(im)
    
      File "omr.py", line 26, in get_contours
    
        im2, contours, hierarchy =cv2.findContours(image_gray,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
    
    ValueError: need more than 2 values to unpack
    

    This is resolved by removing 'im2 ,' from line 26.. as in OpenCv version 3.0 or higher, the function 'findContours' returns only 2 values.. so the statement should be

    contours, hierarchy =cv2.findContours(image_gray,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
    

    and also upgrade your OpenCv version

提交回复
热议问题