目前我正在研究对象识别系统,这需要大量的训练数据。在
我试图将一个三维模型转换成一系列灰色图像,旋转模型并以一定的时间间隔对二维图像进行采样。在
因为我主要是在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?)在
泰铢