Reputation: 533
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
Upvotes: 7
Views: 5135
Reputation: 459
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])
Upvotes: 11