I recieve this error when trying to compile my code.
I know that the .size is an array though, because it would return (1200, 800) for H and W - and I only want one of these. I have looked through syntax examples and tried using parenths and nothing as well. Also, the other answers to this question on StackOverflow do not address my issues.
Please help! I am not usually a Python programmer.
Thank you.
EDIT: I apologize for posting a screenshot instead of code
cv2.imread (check [OpenCV.Docs]: Getting Started with Images ) returns an [SciPy.Docs]: numpy.ndarray . As seen, its size attribute is an int , which is a scalar type, so you can't index it.
If you want to get the image width and height, you should use the shape attribute instead:
>>> img = cv2.imread("c:\\\\valmand.png") >>> type(img) <class 'numpy.ndarray'> >>> img.size 1493331 >>> img.shape (799, 623, 3) >>> img.shape[0], img.shape[1] (799, 623) >>> img.shape[0] * img.shape[1] * img.shape[2] 1493331
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.