Opencv处理AttributeError: ‘NoneType‘ object has no attribute ‘copy‘

在做一个答题卡识别的项目中,遇到了此问题,
报错的代码如下:

image = cv2.imread(args["image"])
contours_img = image.copy()

AttributeError如下:

  File "E:/Python/python_user/Practice_codes/second/answer sheet/get_answer.py", line 78, in <module>
    contours_img = image.copy()
AttributeError: 'NoneType' object has no attribute 'copy'

最终找到错误代码端为配置部分如下:

ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
	help="path to the input image")

修改为:

`ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=False, default='文件位置/test_01.png',

总结:个人此情况主要是两个方面,第一个是配置原因,第二个是文件路径的问题,检查文件路径以及 ‘_’, 文件路径不要中文,具体路径要写明测试图像名称。

你可能感兴趣的:(计算机视觉,opencv,计算机视觉,python)