灰色模型python_python(pygame和pyopenGL)转换3D模型(。obj文件)变成一个灰色图像序列...

目前我正在研究对象识别系统,这需要大量的训练数据。在

我试图将一个三维模型转换成一系列灰色图像,旋转模型并以一定的时间间隔对二维图像进行采样。在

因为我主要是在python上工作,所以我试图基于pygame和pyopenGL来解决这个问题,我找到了this example来加载一个.obj文件,但是一开始它就不起作用了,我花了很长时间才弄清楚问题出在哪里。在

现在,核心问题可以归结为:

类Point3D:def __init__(self, x = 0, y = 0, z = 0):

self.x, self.y, self.z = float(x), float(y), float(z)

def rotateX(self, angle):

""" Rotates the point around the X axis by the given angle in degrees. """

rad = angle * math.pi / 180

cosa = math.cos(rad)

sina = math.sin(rad)

y = self.y * cosa - self.z * sina

z = self.y * sina + self.z * cosa

return Point3D(self.x, y, z)

def rotateY(self, angle):

""" Rotates the point around the Y axis by the given angle in degrees. """

rad = angle * math.pi / 180

cosa = math.cos(rad)

sina = math.sin(rad)

z = self.z * cosa - self.x * sina

x = self.z * sina + self.x * cosa

return Point3D(x, self.y, z)

def rotateZ(self, angle):

""" Rotates the point around the Z axis by the given angle in degrees. """

rad = angle * math.pi / 180

cosa = math.cos(rad)

sina = math.sin(rad)

x = self.x * cosa - self.y * sina

y = self.x * sina + self.y * cosa

return Point3D(x, y, self.z)

def project(self, win_width, win_height, fov, viewer_distance):

""" Transforms this 3D point to 2D using a perspective projection. """

factor = fov / (viewer_distance + self.z)

x = self.x * factor + win_width / 2

y = -self.y * factor + win_height / 2

return Point3D(x, y, self.z)

课堂模拟:

^{pr2}$

如果名称==“main”:

模拟().run()

上面的例子画了一个立方体并不断地旋转它,那么我怎样才能直接得到像素数据呢?

什么样的库或包可以提供我的能力,直接获取二维项目的像素数据。(IPL?还是pyopenGL?)在

泰铢

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值