0

I saw this example: OpenCV MSER detect text areas - Python

and I tried to use that code but it's not working. The error is:

hulls = [cv2.convexHull(p.reshape(-1, 1, 2)) for p in regions] AttributeError: 'list' object has no attribute 'reshape'

Where does the variable p come from?

4

1 回答 1

0

整个结构[cv2.convexHull(p.reshape(-1, 1, 2)) for p in regions]称为“列表理解”。您可以在许多地方阅读更多关于它们的信息。

在您提到的代码中regions是一些可迭代的,例如列表。这意味着当您编写时for p in regions p假定 中的每个值regions,一次一个。所以这就是p从哪里来的。

由于p参与列表理解,因此可以在表达式中使用。在这种情况下,表达式是cv2.convexHull(p.reshape(-1, 1, 2))。因此,整个构造的值是cv2.convexHull(p.reshape(-1, 1, 2))for each pin的值regions

于 2018-01-08T22:51:07.870 回答