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
new_image_pathis aPath…?! Perhapsimwriterequires it to be a string…?cv2.imwritecannot be aPath. Wrap yourPathobject instr()and it shall work.