增强现实的简单实现(立方体、茶壶)
目前对于增强现实有两种通用的定义。一是北卡大学罗纳德·阿祖玛(Ronald Azuma)于1997年提出的,他认为增强现实包括三个方面的内容:
1.将虚拟物与现实结合
2.即时互动
3.三维
而另一种定义是1994年保罗·米尔格拉姆(Paul Milgram)和岸野文郎(Fumio Kishino)提出的现实-虚拟连续统(Milgram’s Reality-Virtuality Continuum)。他们将真实环境和虚拟环境分别作为连续系统的两端,位于它们中间的被称为“混合实境”。其中靠近真实环境的是增强现实(Augmented Reality),靠近虚拟环境的则是扩增虚境。
一、立方体
1.代码:from pylab import *
from PIL import Image
from OpenGL.GLUT import *
If you have PCV installed, these imports should work
from PCV.geometry import homography, camera
from PCV.localdescriptors import sift
“”"
This is the augmented reality and pose estimation cube example from Section 4.3.
“”"
def draw_teapot(size):
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0)
def cube_points(c, wid):
“”" Creates a list of points for plotting
a cube with plot. (the first 5 points are
the bottom square, some sides repeated). “”"
p = []
# bottom
p.append([c[0]-wid, c[1]-wid, c[2]-wid])
p.append([c[0]-wid, c[1]+wid, c[2]-wid])
p.append([c[0]+wid, c[1]+wid, c[2]-wid])
p.append([c[0]+wid, c[1]-wid, c[2]-wid])
p.append([c[0]-wid, c[1]-wid, c[2]-wid]) #same as first to close plot
def my_calibration(sz):
“”"
Calibration function for the camera (iPhone4) used in this example.
“”"
row, col = sz
fx = 2555col/2592
fy = 2586row/1936
K = diag([fx, fy, 1])
K[0, 2] = 0.5col
K[1, 2] = 0.5row
return K