将obj文件放在pygame中的网络摄像头视频上

时间:2019-03-01 18:03:04

标签: opengl pygame augmented-reality wavefront

我正在使用pygame创建一个AR项目,现在我想通过网络摄像头加载obj对象文件。我正在使用此代码,但该对象在网络摄像头中消失了。可以在摄像头框架上添加3d对象吗?

filename = "WhiteFrameobj.obj"
pygame.init()
pygame.camera.init()

screen = pygame.display.set_mode((640,480))
cam = pygame.camera.Camera("/dev/video0", (640, 480))
cam.start()

viewport = (640, 480)
hx = viewport[0]/2
hy = viewport[1]/2
glEnable(GL_DEPTH_TEST)
glClearColor(0.3,1.0,1.0,0.0)

glEnable(GL_COLOR_MATERIAL)
glLightfv(GL_LIGHT0, GL_POSITION,  (0, 1, 1, 0))
glLightfv(GL_LIGHT0, GL_AMBIENT, (0.2, 0.2, 0.2, 1.0))
glLightfv(GL_LIGHT0, GL_DIFFUSE, (0.5, 0.5, 0.5, 1.0))
glEnable(GL_LIGHT0)
glEnable(GL_LIGHTING)

glShadeModel(GL_SMOOTH)
obj = OBJ(filename, swapyz=True)

glMatrixMode(GL_PROJECTION)
glLoadIdentity()
width, height = viewport
gluPerspective(140.0, width/float(height), 5, 1000.0)
glEnable(GL_DEPTH_TEST)
glMatrixMode(GL_MODELVIEW)

rx, ry = (0,0)
tx, ty = (0,-100)
zpos = 405
rotate = move = False

while 1:
    image = cam.get_image()
    screen.blit(image, (0,0))
    pygame.display.update()

    for e in pygame.event.get():
         if e.type == pygame.QUIT:
         sys.exit()

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()

# RENDER OBJECT
glTranslate(tx/20., ty/20., - zpos)
glRotate(ry, 1, 0, 0)
glRotate(rx, 0, 1, 0)

glCallList(obj.gl_list)

0 个答案:

没有答案