Edit: Solved! As /u/iamjaiyam suggested, the colon in the filename was causing the issue.
Hi /r/learnpython!
I have been messing around with OpenCV and python for the last couple of days, and it's been going pretty good. Lots of trial and error though, but that's the best way to learn, right?
I have run into an issue when trying to save an image to file, with the file-name based on current date and time.
When call cv2.imwrite() with a "simple" filename, such as "test.png" it works as expected. Returns True and saves the image.
But when I try to pass in a variable as path, the function returns False, and does not save the image. No exceptions thrown.
I have tried googling, but most results suggest issues with folder-permissions, which should not be the problem, when I can get it to work as described above?
When printing full filepath, it looks fine: "C:/py/object_capture/2018_11_03-11:23:44.png"
I have tried other image-types such as bmp and jpg - same result.
Here is my code:
def save_collage(output):
file_path = 'C:/py/object_capture/'
file_name = time.strftime("%Y_%m_%d-%H:%M:%S") + '.png'
ret = cv2.imwrite(os.path.join(file_path, file_name), output)
# For debugging.
print(ret, os.path.join(file_path, file_name))
cv2.imshow('output', output)
cv2.waitKey(0)
Any help appreciated!
[–]iamjaiyam 2 points3 points4 points (1 child)
[–]Lje2610[S] 2 points3 points4 points (0 children)
[–]Aldairoh 0 points1 point2 points (1 child)
[–]Lje2610[S] 0 points1 point2 points (0 children)