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?
That whole construct
[cv2.convexHull(p.reshape(-1, 1, 2)) for p in regions]is called a 'list comprehension'. You can read much more about them in numerous places.In the code you referred to
regionsis some iterrable, such as a list. This means that when you writefor p in regionspassumes each of the values inregions, one at a time. So that's wherepcomes from.Since
pis taking part in a list comprehension it can be used in an expression. In this case, the expression iscv2.convexHull(p.reshape(-1, 1, 2)). Thus the value of the entire construct is the value ofcv2.convexHull(p.reshape(-1, 1, 2))for eachpinregions.