Я работаю с os.path в python2 на MacOS 10.15.2 и не могу открыть изображение из моего рабочего каталога. Вот код:
'''
# JDoe_JSmith_1_4_3: Change pixels in an image.
'''
import matplotlib.pyplot as plt
import os.path
import numpy as np # "as" lets us use standard abbreviations
#Read the image data
# Get the directory of this python script
directory = os.path.dirname(os.path.abspath(__file__))
# Build an absolute filename from directory + filename
filename = os.path.join(directory, 'woman.jpg')
# Read the image data into an array
img = plt.imread(filename)
###
# Change a region if condition is True
###
height = len(img)
width = len(img[0])
for r in range(155):
for c in range(width):
if sum(img[r][c])>500: # brightness R+G+B goes up to 3*255=765
img[r][c]=[255,0,255] # R + B = magenta
# if sum(img[r][c])
###
# Show the image data
###
#Show the image data
# Create figure with 1 subplot
fig, ax = plt.subplots(1, 1)
# Show the image data in a subplot
ax.imshow(img, interpolation='none')
# Show the figure on the screen
fig.show()
Есть ли обходные пути для этого или я что-то не так делаю? Любая помощь очень ценится.
Вот изображение ошибки, если оно может помочь: изображение ошибки
Я должен также упомянуть, что он отлично работал на Windows 10; Я получаю только ошибку на MacOS.