cv2.imread() gives None, but the path/cwd is correct
Hello,
I had this problem already and it was solved without any clear reason. I had my Jupyter Notebook tab open and didn't change anything and then it worked. I already read articles and other threads on this, but couldn't find a solution for this; just look at my screenshot:
PATH = "savefig/plotXBIC_singlecell/01.png"
img = cv2.imread(PATH)
print(img)
print(path.exists(PATH))
None True
On a PyImageSearch blog post I read that this can happen with bad compiling, such as JPEGs. But this doesn't make sense: It already worked a few hours ago and I could display the img with plt.imshow(). (Not with cv2.imshow(), that leads to my kernel crashing.)
Check also is path is regular file and can be read. Also as you talking about Jupyter Notebook - this is not a "regular" enviroment. Most likely the cause is there.
be so kind to us, and replace the screenshot with a text version of your code, thank you.
also, relative paths are relative to where you start your program, that's not nessecarily, where your script is.
try with an absolute path instead. also check your image with another program (maybe it's a misnamed .gif)
I changed the PATH to the absolute path and nothing changed. os.path.isfile(PATH) gives me True.
If it worked a couple of hours ago, but not now, something has changed - perhaps crashed. It is not uncommon to debug a problem for hours only to see the problem disappear when the computer is restarted...
I restarted the computer, I restarted the kernel... I also placed the 01.png at my cwd... what else can I try?
please check if it is really a valid png image
maybe:
head 01.png
and see if the file magic is correct (again, gif ? svg ?)seriously, .....
Sorry, I don't understand your comment. Could you rephrase it, please? Something about your syntax is confusing. (Dots after comma, citation of mvuori's comment, but only part of it, and what do you mean by "valid png"? Do you mean if it is an actual png and not just its file name? Yes, it is, I created it with matplotlib's savepng.)
??? I still didn't solve this problem...
Can nobody here help? :-(