首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Numpy Hstack ValueError

Numpy Hstack ValueError
EN

Stack Overflow用户
提问于 2020-09-21 02:39:09
回答 1查看 69关注 0票数 0

我正在为俄罗斯方块编写一些颜色检测,但当我尝试运行代码时,我得到了这个错误:

代码语言:javascript
复制
Traceback (most recent call last):
  File "C:\Users\hampus.ramsten\Desktop\Detection - test.py", line 49, in <module>
    cv2.imshow("virtual_board", np.hstack([resize, output]))
  File "<__array_function__ internals>", line 5, in hstack
  File "C:\Users\hampus.ramsten\AppData\Local\Programs\Python\Python38-32\lib\site-packages\numpy\core\shape_base.py", line 346, in hstack
    return _nx.concatenate(arrs, 1)
  File "<__array_function__ internals>", line 5, in concatenate
ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 0, the array at index 0 has size 168 and the array at index 1 has size 1080

我猜是从这里来的,但我不知道:

代码语言:javascript
复制
boundaries = (104, 120, 164)
boundaries1 = (106, 122, 166)

for (boundaries) in boundaries:
    lower = np.array(boundaries, dtype = "uint8")
    upper = np.array(boundaries1, dtype = "uint8")

    board_mask = cv2.inRange(image, lower, upper)
    output = cv2.bitwise_and(image, image, mask = board_mask)

    contours, _ = cv2.findContours(board_mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
    print(contours)
    contours = sorted(contours, key=lambda x: cv2.contourArea(x), reverse=True)

    resize = ResizeWithAspectRatio(image, width=300)
    cv2.imshow("virtual_board", np.hstack([resize, output]))

有什么问题吗?

EN

回答 1

Stack Overflow用户

发布于 2020-09-21 13:07:32

您的错误消息准确地指出了原因:

代码语言:javascript
复制
ValueError: ...
but along dimension 0
the array at index 0 has size 168 and
the array at index 1 has size 1080

这个错误实际上发生在np.hstack中,因为您试图水平堆叠具有不同行数的数组。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63982426

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档