
我们通过一个没有景深的摄像机来获取视频资源,我们通过视频资源在 AE 或者视频编辑软件中可以反推测摄像机,以及在拍摄时候的摄像机的参数。通过影像资料来还原周围的环境。当然最后是双摄像头。

做个 3D 相关工作,例如将游戏中人物的进行 UV 拆分,所以对于 UV 坐标并不会感到陌生。在用 Vray 渲染效果图时候也接触过摄像机的基本原理。如图在真实世界中的 p 点会投射到视觉平面上 UV 的点。F 为照相机的点。
在图像测量过程以及机器视觉应用中,为确定空间物体表面某点的三维几何位置与其在图像中对应点之间的相互关系,必须建立相机成像的几何模型,这些几何模型参数就是相机参数。

其中R 为 3*3 的旋转矩阵,t 为3*1的平移矢量,(xc,yc,zc,1)T(xc,yc,zc,1)T为相机坐标系的齐次坐标,(xw,yw,zw,1)T(xw,yw,zw,1)T为世界坐标系的齐次坐标。
在大多数条件下这些参数必须通过实验与计算才能得到,这个求解参数的过程就称之为相机标定(或摄像机标定)。这里我们可以根据图像来获取摄像机
我们需要查找图像的特征值(features), 所谓特征值是可以描述一张图片,可能是边,拐角部分。
orb = cv2.ORB_create()
kp1, des1 = orb.detectAndCompute(img,None)
for p in kp1:
u,v = map(lambda x: int(round(x)),p.pt)
print(u,v)
cv2.circle(img,(u,v),3,(0,255,0),1)

使用 opencv 我们可以得到一些图片的特征也就是树的边缘的特征。不过这些特征值并不能很好表现也可以说是描述这张图我们需要进一步进行优化来找到能够正确反映这张图的特征。
class Extracrator(object):
GX = 16 // 2
GY = 12 // 2
def __init__(self):
self.orb = cv2.ORB_create(1000)
def extract(self,img):
sy = img.shape[0] // self.GY
sx = img.shape[1] // self.GX
for ry in range(0,img.shape[0],sy):
for rx in range(0,img.shape[1],sx):
img_chuck = img[ry:ry+sy,rx:rx+sx]
kp = self.orb.detect(img_chuck,None)
print(p)
我们将图片进行切分成 16 x 12 个小格,然后对每一个小格进行特征点的侦测。
def extract(self,img):
sy = img.shape[0] // self.GY
sx = img.shape[1] // self.GX
akp = []
for ry in range(0,img.shape[0],sy):
for rx in range(0,img.shape[1],sx):
img_chuck = img[ry:ry+sy,rx:rx+sx]
kp = self.orb.detect(img_chuck,None)
for p in kp:
p.pt = (p.pt[0] + rx, p.pt[1] + ry)
akp.append(p)
p.pt = (p.pt[0] + rx, p.pt[1] + ry)
将位置补偿回去,以便可以在原图像(未分割前图像)上观察到检测的特征点。
def process_frame(img):
img = cv2.resize(img,(W,H))
kp = ex.extract(img)
for p in kp:
u, v = map(lambda x: int(round(x)),p.pt)
cv2.circle(img,(u,v),color=(0,255,0),radius=3)
display.paint(img)
虽然有所改善,不过我们效果不算好,跟踪点还是以一簇一簇的。

def extract(self,img):
feats = cv2.goodFeaturesToTrack(np.mean(img,axis=2).astype(np.uint8),3000,qualityLevel=0.01,minDistance=3)
print(feats)
return feats
kp = ex.extract(img)
for p in kp:
u, v = map(lambda x: int(round(x)),p[0])
cv2.circle(img,(u,v),color=(0,255,0),radius=3)

def extract(self,img):
feats = cv2.goodFeaturesToTrack(np.mean(img,axis=2).astype(np.uint8),3000,qualityLevel=0.01,minDistance=3)
kps = [cv2.KeyPoint(x=f[0][0],y=f[0][1],_size=20) for f in feats]
des = self.orb.compute(img,kps)
return kps,des
kps, des = ex.extract(img)
for p in kps:
u, v = map(lambda x: int(round(x)),p.pt)
cv2.circle(img,(u,v),color=(0,255,0),radius=3)
网友评论