I am getting a file not found error for my basic python script that interprets an image as a 2d array. This is the source code
import os
from PIL import Image
import numpy as np
def image_to_array(image_path):
# Open an image file
with Image.open(image_path) as img:
# Convert the image to grayscale (optional, for simplicity)
img = img.convert('L')
# Convert the image to a numpy array
img_array = np.array(img)
return img_array
def main():
script_dir = os.path.dirname(__file__)
image_path = os.path.join(script_dir, 'retro_Image', 'Example.jpg')
img_array = image_to_array(image_path)
print(img_array)
if __name__ == '__main__':
main()
`
I tried to use os to join the file path and have it be the correct path but it did not work