[英]<built-in function imread> returned NULL without setting an error
def image_descriptors(file):
img = cv2.imread(file,0)
img = cv2.resize(img, (256, 256))
_ , descriptors = cv2.SIFT().detectAndCompute(img, None)
return descriptors
def folder_descriptors(folder):
cv_img=[]
for img in glob.glob("*.jpg"):
n=cv2.imread(img)
cv_img.append(n)
print("Calculating descriptos. Number of images is", len(cv_img))
return np.concatenate([image_descriptors(file) for file in cv_img])
I am getting the following in output screen: Calculating descriptos.我在 output 屏幕中得到以下信息:计算描述。 Number of images is 274 SystemError: returned NULL without setting an error
图像数量为 274 SystemError: returned NULL 未设置错误
Path.glob
return list of Path
object ( WindowsPath
in windows or PosixPath
in linux). Path.glob
返回Path
object 的列表( PosixPath
中的WindowsPath
或 linux 中的 PosixPath)。 and cv2.imread
expect string .和
cv2.imread
期望字符串。
you can get string of path from Path
object using str
class ( str(path_object)
) or build in magic method from Path
object ( path_object.__str__()
)您可以使用
str
class ( str(path_object)
)从Path
object 获取路径字符串或从Path
object ( path_object.__str__()
)构建魔术方法
def image_descriptors(file):
img = cv2.imread(file,0)
img = cv2.resize(img, (256, 256))
_ , descriptors = cv2.SIFT().detectAndCompute(img, None)
return descriptors
def folder_descriptors(folder):
cv_img=[]
for img in glob.glob("*.jpg"):
# convert `Path` object to string
n=cv2.imread(str(img))
cv_img.append(n)
print("Calculating descriptos. Number of images is", len(cv_img))
return np.concatenate([image_descriptors(file) for file in cv_img])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.