【发布时间】:2021-03-25 18:36:38
【问题描述】:
主要任务是显示.obj格式的图片
这是我的代码:
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()
错误:
canvas_pixels[x, y] = colour
IndexError: image index out of range
male_head.obj 文件位于项目文件夹中。
【问题讨论】:
-
请edit 并将小样本 .obj 图像文件的数据添加到您的问题中,使其成为可运行的minimal reproducible example。
标签: python image import python-imaging-library