解決策。TypeError: cannot unpack non-iterable numpy.int32 object。opencvのcv2.detail.leaveBiggestComponent関連。
エラー
TypeError: cannot unpack non-iterable numpy.int32 object
詳細
↓
Traceback (most recent call last): File "panorama.py", line 84, in <module> conn_images, features, p = largest_connected_subset(all_images) File "panorama.py", line 38, in largest_connected_subset conn_indices = [i for [i] in _conn_indices] File "panorama.py", line 38, in <listcomp> conn_indices = [i for [i] in _conn_indices] TypeError: cannot unpack non-iterable numpy.int32 object
環境
windows10
python3.7
opencv-python 4.6.0
エラーにあったコード
https://github.com/PacktPublishing/OpenCV-4-with-Python-Blueprints-Second-Edition
解決策
結論
これは、opencv-pythonが4.6.0で、cv2.detail.leaveBiggestComponentのリターンの形が少しだけ変わったからです。
具体的な情報
4.5.3のstitching_detailed.py
indices = cv.detail.leaveBiggestComponent(features, p, conf_thresh) img_subset = [] img_names_subset = [] full_img_sizes_subset = [] for i in range(len(indices)): img_names_subset.append(img_names[indices[i, 0]]) img_subset.append(images[indices[i, 0]]) full_img_sizes_subset.append(full_img_sizes[indices[i, 0]]) images = img_subset
4.6.0のstitching_detailed.py
indices = cv.detail.leaveBiggestComponent(features, p, conf_thresh) img_subset = [] img_names_subset = [] full_img_sizes_subset = [] for i in range(len(indices)): img_names_subset.append(img_names[indices[i]]) img_subset.append(images[indices[i]]) full_img_sizes_subset.append(full_img_sizes[indices[i]]) images = img_subset
ですから
↑ を参考に、ソースを修正して下さい。
コメント
時間があるときに、もう少し、整理したいと思いますが。。。。