[英]I am getting the path of an newly added image to directory, but cv2.imread() printing type <class 'NoneType'> in python
import os
import cv2
path = 'C:\\Users\\rishi\\Documents\\Sudoky-Solver\\Sudoky-Solver\\test'
list = os.listdir(path)
def newest(path):
files = os.listdir(path)
paths = [os.path.join(path, basename) for basename in files]
return max(paths, key=os.path.getctime)
while True:
list2 = os.listdir(path)
if list2 != list:
imgpath = newest(path)
img = cv2.imread(str(imgpath).replace('\\', '/'))
print(type(img))
list = list2
When I run the code, the code gives error当我运行代码时,代码出错
Output: Output:
<class 'NoneType'>
You get <class 'NoneType'> only when the path is incorrect.只有当路径不正确时,您才会得到 <class 'NoneType'>。 Also, sometimes you have to pass your image path as raw input (r'D:.....') because you may have a /t or so in the path.此外,有时您必须将图像路径作为原始输入 (r'D:.....') 传递,因为路径中可能有 /t 左右。 Just print the paths and check them first.只需打印路径并先检查它们。 :) :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.