cv2.imwrite() SystemError: <built-in function imwrite> returned NULL without setting an error
cv2.imwrite() SystemError: <built-in function imwrite> returned NULL without setting an error
我正在尝试将 np 数组保存为图像。问题是,如果我在 imwrite 函数中写入路径,它可以工作,但如果我将它存储在一个变量中,然后将此变量用作路径,它就不起作用并且 returns 一个错误。
这个有效:
cv2.imwrite('my/path/to/image.png', myarray[...,::-1])
这行不通
new_image_path = path/'{}+.png'.format(np.random.randint(1000))
cv2.imwrite(new_image_path, myarray[...,::-1])
它 returns 这个错误:
SystemError: <built-in function imwrite> returned NULL without setting an error
方法cv2.imwrite
不适用于路径对象。只需在调用方法时将其转换为字符串即可:
cv2.imwrite(str(new_image_path), myarray[...,::-1])
我正在尝试将 np 数组保存为图像。问题是,如果我在 imwrite 函数中写入路径,它可以工作,但如果我将它存储在一个变量中,然后将此变量用作路径,它就不起作用并且 returns 一个错误。
这个有效:
cv2.imwrite('my/path/to/image.png', myarray[...,::-1])
这行不通
new_image_path = path/'{}+.png'.format(np.random.randint(1000))
cv2.imwrite(new_image_path, myarray[...,::-1])
它 returns 这个错误:
SystemError: <built-in function imwrite> returned NULL without setting an error
方法cv2.imwrite
不适用于路径对象。只需在调用方法时将其转换为字符串即可:
cv2.imwrite(str(new_image_path), myarray[...,::-1])