I'm tring to save an np array as an image. The problem is that, if I write the path in the imwrite function it works, but if i store it in a variable and then use this variable as path it doesn't work and returns an error.
This works:
cv2.imwrite('my/path/to/image.png', myarray[...,::-1])
This doesn't work
new_image_path = path/'{}+.png'.format(np.random.randint(1000))
cv2.imwrite(new_image_path, myarray[...,::-1])
And it returns this error:
SystemError: <built-in function imwrite> returned NULL without setting an error
The method cv2.imwrite
does not work with the Path object. Simply convert it to string when you call the method:
cv2.imwrite(str(new_image_path), myarray[...,::-1])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.