我正在为俄罗斯方块编写一些颜色检测,但当我尝试运行代码时,我得到了这个错误:
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我猜是从这里来的,但我不知道:
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]))有什么问题吗?
发布于 2020-09-21 13:07:32
您的错误消息准确地指出了原因:
ValueError: ...
but along dimension 0
the array at index 0 has size 168 and
the array at index 1 has size 1080这个错误实际上发生在np.hstack中,因为您试图水平堆叠具有不同行数的数组。
https://stackoverflow.com/questions/63982426
复制相似问题