-1

I am having an issue with this Python code: Code And Other Things

The Error Is:

Traceback (most recent call last): File "C:\Users\thaku\Desktop\projects\pythoncode-tutorials-master\machine-learning\face-age-prediction\predict_age.py", line 156, in <module> predict_age(image_path) File "C:\Users\thaku\Desktop\projects\pythoncode-tutorials-master\machine-learning\face-age-prediction\predict_age.py", line 113, in predict_age frame = img.copy() AttributeError: 'NoneType' object has no attribute 'copy' 

I Was trying opencv as learning python. the project was to predict age but as this error came my days are wasted so please help me.. To Run The Code: python .\predict_age.py /tmp or some new errors come

2
  • 1
    You should paste your code here in the question instead of linking to it. Commented Jan 14, 2022 at 8:02
  • Welcome back to Stack Overflow. As a refresher, please read How to Ask. We can only tell you what is wrong with code that you show in the question itself. Commented Jan 14, 2022 at 8:07

2 Answers 2

2
def predict_age(input_path: str): """Predict the age of the faces showing in the image""" # Read Input Image img = cv2.imread(input_path) # Take a copy of the initial image and resize it frame = img.copy() 

Seems your error happens here because img is None, so it has no method copy() to call.

You said you are running the code like this:

 .\predict_age.py /tmp 

I can see that the code initialises img with the input_path which is passed as sys.argv[1]. well, /tmp is not really an image, could you try passing an image like .\predict_age.py /tmp/my_image.png

Sign up to request clarification or add additional context in comments.

Comments

0

The error means that the img variable from cv2.imread(input_path) is None. I.e., something went wrong with reading the image from input_path.

In your main code, you write

import sys image_path = sys.argv[1] predict_age(image_path) 

So the image path is given by the first argument to the program. Are you running the code as python predict_age.py 3-people.jpg?

2 Comments

Hey Lucas, seems like we've seen the same thing and replied at the same time, haha
yes it doesn't work

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.