【发布时间】:2019-06-05 17:15:38
【问题描述】:
我找到了一些应该可以工作的代码,但没有。我做错了什么/丢失了?
来源:How to find table like structure in image
def find_table_in_boxes(boxes, cell_threshold=10, min_columns=2):
for box in boxes:
(x, y, w, h) = box
print(box)
col_key = x // cell_threshold
if __name__ == '__main__':
text_boxes = [
{
'x': 123,
'y': 512,
'w': 100,
'h': 150
},
{
'x': 500,
'y': 512,
'w': 100,
'h': 150
}
]
cells = find_table_in_boxes(text_boxes)
错误
# python test.py
{'x': 123, 'w': 100, 'y': 512, 'h': 150}
Traceback (most recent call last):
File "test.py", line 22, in <module>
cells = find_table_in_boxes(text_boxes)
File "test.py", line 5, in find_table_in_boxes
col_key = x // cell_threshold
TypeError: unsupported operand type(s) for //: 'str' and 'int'
【问题讨论】:
-
阅读错误——上面写着
unsupported operand types(s) for //: 'str' and 'int'。这意味着您正在尝试将字符串和整数相除。 -
做
print(x, y, w, h)看看你在那里做什么。 -
将
(x, y, w, h) = box更改为(x, y, w, h) = box["x"], box["y"], box["w"], box["h"] -
您正在尝试在 int 和 string 上进行除法
-
查看这个可爱的debug 博客寻求帮助。 “看代码”并不是一个特别详细或准确的调试策略。去过那里,做到了,用所有的T恤做了被子......
标签: python