Код: Выделить всё
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()
Я пытался использовать os, чтобы присоединиться к пути к файлу и сделать его правильным, но это не сработало
Подробнее здесь: https://stackoverflow.com/questions/787 ... hon-script