Regarding python practice data analysis 100 knock knocks 81s

Asked 2 years ago, Updated 2 years ago, 139 views

If you enter the code below, you will receive the error "NoneType object has no attribute "shape", opencv has already been installed and the image has been uploaded.Please let me know if there are any mistakes.Thank you for your cooperation.

My environment is Jupiter Notebook.

import cv2
img=cv2.imread("img/img01.jpg")
height,width=img.shape [:2]
print("Image width:" + str(width))
print("Image Height:" + str(height))
cv2.imshow("img", img)
cv2.waitkey(0)

python opencv jupyter-notebook

2022-09-30 20:16

1 Answers

This is probably because the img directory under the current directory of JupiterNotebook, or the img01.jpg file under it does not exist.
For example, the directory in which the notebook file resides may not be the current directory.

If they do not exist or are not loaded properly, the cv2.imread() return value is None and subsequent operations result in a question-like error.

Please refer to this article.
[OpenCV] When you want to check if it's loaded properly in imread

Also, please refer to this article to check and move the current directory.
Directory operations in the Jupiter Notebook

You can retrieve the current directory in %pwd.

You can move the current directory with the %cd command.


2022-09-30 20:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.