cv.findContours()-ValueError:解凍するのに十分な値がありません(予想3、取得2)

アーチェリー

そのため、OpenCVでこのチュートリアルのコードを実行して、画像の輪郭を見つけて境界ボックスを作成する方法を説明しました。コードから(画像のソースファイル名以外は)何も変更しませんでした。チュートリアルとまったく同じです。しかし、私がそれを実行しているとき、それはこのエラーに遭遇します:

Traceback (most recent call last):
  File "contour.py", line 78, in <module>
    thresh_callback(thresh)
  File "contour.py", line 19, in thresh_callback
    _, contours, _ = cv.findContours(canny_output, cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
ValueError: not enough values to unpack (expected 3, got 2)

エラーが何であるかはわかっていると思います。期待値cv.findContours得られないためですが、解決方法がわかりません。何が起こったのですか、どうすればよいですか?私が言ったように、コードはチュートリアルとまったく同じです。

これがコードです。

from __future__ import print_function
import cv2 as cv
import numpy as np
import argparse
import random as rng

rng.seed(12345)

def thresh_callback(val):
    threshold = val

    ## [Canny]
    # Detect edges using Canny
    canny_output = cv.Canny(src_gray, threshold, threshold * 2)
    ## [Canny]

    ## [findContours]
    # Find contours
    _, contours, _ = cv.findContours(canny_output, cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
    ## [findContours]

    ## [allthework]
    # Approximate contours to polygons + get bounding rects and circles
    contours_poly = [None]*len(contours)
    boundRect = [None]*len(contours)
    centers = [None]*len(contours)
    radius = [None]*len(contours)
    for i, c in enumerate(contours):
        contours_poly[i] = cv.approxPolyDP(c, 3, True)
        boundRect[i] = cv.boundingRect(contours_poly[i])
        centers[i], radius[i] = cv.minEnclosingCircle(contours_poly[i])
    ## [allthework]

    ## [zeroMat]
    drawing = np.zeros((canny_output.shape[0], canny_output.shape[1], 3), dtype=np.uint8)
    ## [zeroMat]

    ## [forContour]
    # Draw polygonal contour + bonding rects + circles
    for i in range(len(contours)):
        color = (rng.randint(0,256), rng.randint(0,256), rng.randint(0,256))
        cv.drawContours(drawing, contours_poly, i, color)
        cv.rectangle(drawing, (int(boundRect[i][0]), int(boundRect[i][1])), (int(boundRect[i][0]+boundRect[i][2]), int(boundRect[i][1]+boundRect[i][3])), color, 2)
        cv.circle(drawing, (int(centers[i][0]), int(centers[i][1])), int(radius[i]), color, 2)
    ## [forContour]

    ## [showDrawings]
    # Show in a window
    cv.imshow('Contours', drawing)
    ## [showDrawings]

## [setup]
# Load source image
parser = argparse.ArgumentParser(description='Code for Creating Bounding boxes and circles for contours tutorial.')
parser.add_argument('--input', help='Path to input image.', default='example.png')
args = parser.parse_args()

src = cv.imread(cv.samples.findFile(args.input))
if src is None:
    print('Could not open or find the image:', args.input)
    exit(0)

# Convert image to gray and blur it
src_gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY)
src_gray = cv.blur(src_gray, (3,3))
## [setup]

## [createWindow]
# Create Window
source_window = 'Source'
cv.namedWindow(source_window)
cv.imshow(source_window, src)
## [createWindow]
## [trackbar]
max_thresh = 255
thresh = 100 # initial threshold
cv.createTrackbar('Canny thresh:', source_window, thresh, max_thresh, thresh_callback)
thresh_callback(thresh)
## [trackbar]

cv.waitKey()

ここに同様の質問がありますが、答えは得られませんでした。

ひひこもり

「findContours」は、2つの値のタプルを返します。正しい使用法は次のとおりです。

contours, _ = cv.findContours(canny_output, cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

cv2.findContours使用時のエラー

分類Dev

Why in one code cv2.findContours function is working but not in the other?

分類Dev

cv2.findContoursを呼び出して解凍するには値が多すぎます

分類Dev

Pythonでcv2.findContours関数を使用する場合のValueError

分類Dev

Python 3-ValueError:解凍するのに十分な値がありません(予想3、取得2)

分類Dev

Python ValueError:解凍するのに十分な値がありません(予想3、取得2)

分類Dev

cv2.findContoursは輪郭を検出できません

分類Dev

cv2.findContours()は奇妙に動作しますか?

分類Dev

cv2.findContoursが輪郭を見つけられない

分類Dev

opencvのfindContoursで、cv.RETR_FLOODFILLは何をしますか?

分類Dev

cv2.findContours()の領域を検索(Python、OpenCV)

分類Dev

ValueError:解凍するのに十分な値がありません(予想4、取得3)

分類Dev

Python ValueError:解凍するのに十分な値がありません(予想3、1を取得)

分類Dev

scikit-learn:ValueError:解凍するのに十分な値がありません(予想2、1を取得)

分類Dev

Django ValueError-解凍するのに十分な値がありません(予想2、1を取得)

分類Dev

ValueErrorを解凍するのに十分な値がありません(予想4、2を取得)-Django

分類Dev

How to reliably find checked boxes on an image (with cv2.findContours or another technique)?

分類Dev

cv2.findContoursは、黒い背景に白い長方形を見つけません

分類Dev

python3:解凍するのに十分な値がありません(予想2、0を取得)

分類Dev

ValueError:解凍するのに十分な値がありません(予想される11、1を取得)

分類Dev

Python3はファイルを辞書に作成しますValueError:解凍するのに十分な値がありません(予想2、1を取得)

分類Dev

Django Multiple Record Insert CreateView(解凍するのに十分な値がありません(予想2、1を取得))

分類Dev

画像の輪郭は、cv2findContoursでは非常にずさんなように見えます。改善方法?

分類Dev

ValueError:解凍するのに十分な値がありません(予想2、1を取得)しかし、2つの値を提供します

分類Dev

ValueErrorを与えるPythonのマシュマロ:解凍するのに十分な値がありません(予想2、1を取得)

分類Dev

Python-「ValueError:解凍するのに十分な値がありません(予想2、1を取得)」を修正する方法

分類Dev

「ValueError:解凍するのに十分な値がありません(予想2、1を取得)」を修正する方法

分類Dev

ValueError:解凍するのに十分な値がありません(2、1を取得)NetworkX python 3

分類Dev

scipyを処理する方法ValueErrorを最小化する:解凍するのに十分な値がありません(予想4、3を得ました)?

Related 関連記事

  1. 1

    cv2.findContours使用時のエラー

  2. 2

    Why in one code cv2.findContours function is working but not in the other?

  3. 3

    cv2.findContoursを呼び出して解凍するには値が多すぎます

  4. 4

    Pythonでcv2.findContours関数を使用する場合のValueError

  5. 5

    Python 3-ValueError:解凍するのに十分な値がありません(予想3、取得2)

  6. 6

    Python ValueError:解凍するのに十分な値がありません(予想3、取得2)

  7. 7

    cv2.findContoursは輪郭を検出できません

  8. 8

    cv2.findContours()は奇妙に動作しますか?

  9. 9

    cv2.findContoursが輪郭を見つけられない

  10. 10

    opencvのfindContoursで、cv.RETR_FLOODFILLは何をしますか?

  11. 11

    cv2.findContours()の領域を検索(Python、OpenCV)

  12. 12

    ValueError:解凍するのに十分な値がありません(予想4、取得3)

  13. 13

    Python ValueError:解凍するのに十分な値がありません(予想3、1を取得)

  14. 14

    scikit-learn:ValueError:解凍するのに十分な値がありません(予想2、1を取得)

  15. 15

    Django ValueError-解凍するのに十分な値がありません(予想2、1を取得)

  16. 16

    ValueErrorを解凍するのに十分な値がありません(予想4、2を取得)-Django

  17. 17

    How to reliably find checked boxes on an image (with cv2.findContours or another technique)?

  18. 18

    cv2.findContoursは、黒い背景に白い長方形を見つけません

  19. 19

    python3:解凍するのに十分な値がありません(予想2、0を取得)

  20. 20

    ValueError:解凍するのに十分な値がありません(予想される11、1を取得)

  21. 21

    Python3はファイルを辞書に作成しますValueError:解凍するのに十分な値がありません(予想2、1を取得)

  22. 22

    Django Multiple Record Insert CreateView(解凍するのに十分な値がありません(予想2、1を取得))

  23. 23

    画像の輪郭は、cv2findContoursでは非常にずさんなように見えます。改善方法?

  24. 24

    ValueError:解凍するのに十分な値がありません(予想2、1を取得)しかし、2つの値を提供します

  25. 25

    ValueErrorを与えるPythonのマシュマロ:解凍するのに十分な値がありません(予想2、1を取得)

  26. 26

    Python-「ValueError:解凍するのに十分な値がありません(予想2、1を取得)」を修正する方法

  27. 27

    「ValueError:解凍するのに十分な値がありません(予想2、1を取得)」を修正する方法

  28. 28

    ValueError:解凍するのに十分な値がありません(2、1を取得)NetworkX python 3

  29. 29

    scipyを処理する方法ValueErrorを最小化する:解凍するのに十分な値がありません(予想4、3を得ました)?

ホットタグ

アーカイブ