Issue with Reading a File Using Relative Path in Python

37 Views Asked by At

I'm currently working on a Python script named bilin_intpol.py which is located in the /HW directory on my system. The script needs to read an image file named lenna.png that is located in the /code directory.

I attempted to load the image using OpenCV with the following line of code:

img = cv2.imread('../code/lenna.png')

However, I'm encountering an issue where the image cannot be read using this relative path. I'm not sure why this is happening.

Following is my directory:

enter image description here

And here is the code:

enter image description here

Has anyone faced a similar issue or does anyone know why the relative path might not be working in this context? Any insights or suggestions would be greatly appreciated.

0

There are 0 best solutions below