我对这个Python代码有一个问题:代码和其他东西
错误是:
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'
我试着用opencv来学习巨蟒。这个项目是为了预测年龄,但由于这个错误的到来,我的日子都白白浪费了,所以请帮帮我。要运行代码: python、.\predict_age.py、/tmp或一些新的错误
发布于 2022-01-14 08:06:45
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()
似乎您的错误发生在这里,因为img是None,所以它没有要调用的方法copy()。
你说过你是这样运行代码的:
.\predict_age.py /tmp
我可以看到,代码用input_path初始化img,后者作为sys.argv1传递。嗯,/tmp并不是一个真正的图像,您能尝试传递一个像.\predict_age.py /tmp/my_image.png这样的图像吗?
发布于 2022-01-14 08:05:19
这个错误意味着来自cv2.imread(input_path)
的cv2.imread(input_path)
变量是None
。也就是说,从input_path
读取图像时出了点问题。
在您的主要代码中,您可以编写
import sys
image_path = sys.argv[1]
predict_age(image_path)
因此图像路径是由程序的第一个参数给出的。您是否以python predict_age.py 3-people.jpg
的形式运行代码?
https://stackoverflow.com/questions/70707573
复制相似问题