How to fix this error "IndexError: image index out of range"?

The main task is to display img with the .obj format

here is my code :

from PIL import Image
import re

scr_x = 800
scr_y = scr_x
half_scr_x = int(scr_x / 2)
half_scr_y = int(scr_y / 2)
img = Image.new('RGB', (scr_x+1, scr_y+1) , 'black')
canvas_pixels = img.load()
color = (255,255,255)
f = open('male_head.obj','r')
lines = f.read()
for line in lines.split('\n'):
    try:
        v, x, y, z, = re.split('\s+', line)
    except:
        continue
    if v == 'v':
        x = int((float(x) + 1) * half_scr_x)
        y = scr_y - int((float(y) + 1) * half_scr_y)
        canvas_pixels[x, y] = color
img.show()

error :

canvas_pixels[x, y] = colour
IndexError: image index out of range

the male_head.obj file is located in the project folder


Ответы (0 шт):