2024-05-23 19:48:44 发布
网友
我看到了这个例子:OpenCV MSER detect text areas - Python
我试着用那个代码,但没用。 错误是:
hulls = [cv2.convexHull(p.reshape(-1, 1, 2)) for p in regions] AttributeError: 'list' object has no attribute 'reshape'
变量p来自哪里?在
p
整个结构[cv2.convexHull(p.reshape(-1, 1, 2)) for p in regions]称为“列表理解”。你可以在很多地方读到更多关于它们的文章。在
[cv2.convexHull(p.reshape(-1, 1, 2)) for p in regions]
在您所引用的代码中,regions是某种可编排的,例如列表。这意味着当您编写for p in regionsp时,假设regions中的每个值,一次一个。这就是p的来源。在
regions
for p in regions
由于p参与了列表理解,因此可以在表达式中使用它。在本例中,表达式是cv2.convexHull(p.reshape(-1, 1, 2))。因此,整个构造的值是cv2.convexHull(p.reshape(-1, 1, 2))中每个p的值。在
cv2.convexHull(p.reshape(-1, 1, 2))
整个结构
[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))
中每个p
的值。在相关问题 更多 >
编程相关推荐