2019年7月16日15:55:11

感觉虚拟视点也是视觉slam里头一个重要的需求和应该实现的功能,但是好像

没看到什么资料。

百度的全景地图,或者有些公司网站上的3d装修效果图,可以用鼠标拖动查看不同视角,但是

图片看起来很奇怪,那不是虚拟视点,只是对图片做了变换。

虚拟视点的一些资料:

https://www.cnblogs.com/riddick/p/8511960.html

https://www.zhihu.com/question/40793359/answer/130155294

其他有点关联的方向:

https://zhuanlan.zhihu.com/p/73599241

谷歌也有篇文章把短基线变成长基线的文章,也有点虚拟视点的意思。

这里利用sfmlearner的设施做了个简单的demo:

原始图:

相机沿着Z轴往前移动0.5m,注意红框处和上图的对比,的确是往前移动了,这里没做插值,所以

不是太好看  pose = np.array([0, 0,  -0.5,   0, 0, 0])   # tx, ty, tz,   rx, ry, rz -- [B, 6]  弧度制!!!

下面是pose = np.array([0, -0.5,  0,   0, 0, 0],相机往下走了,y=-0.5

注意depth图红框处,原本从上往下拍时被桌面或者凳子挡住的部分现在看的到了,但是对应的深度图

在之前的角度是测不到的,相机往下移动之后这部分的深度图就显示为空缺了,对应的color1部分也

是黑色的。

下面是代码:

 # -*- coding: utf-8 -*-
"""
Created on Tue Jul 16 11:57:48 2019 @author: scj project test https://pytorch.org/docs/stable/nn.html?highlight=f%20grid_sample#torch.nn.functional.grid_sample https://blog.csdn.net/chamber_of_secrets/article/details/83512540 https://blog.csdn.net/houdong1992/article/details/88122682 """ import torch import numpy as np
import cv2
import matplotlib.pyplot as plt #depth = cv2.imread('/media/scj/work/depth/joinMap/depth/1.pgm', -1)
depth = cv2.imread('D:\\depth\\joinMap\\depth\\1.pgm', -1)
depth = depth/1000 depth_copy = depth.copy() #fig = plt.subplots(1)
#plt.imshow( depth_copy )
#plt.title("depth") #color = cv2.imread('/media/scj/work/depth/joinMap/color/1.png')
color = cv2.imread('D:\\depth\\joinMap\\color\\1.png') #fig = plt.subplots(1)
#plt.imshow( cv2.cvtColor(color, cv2.COLOR_BGR2RGB) )
#plt.title("color") #####################
fig=plt.figure() plt.subplot(121)
plt.imshow(cv2.cvtColor(color, cv2.COLOR_BGR2RGB))
plt.title("color") plt.subplot(122)
plt.imshow(depth_copy)
plt.title("depth") plt.show() ##################### #color = np.transpose(color, (2, 0, 1)) # print(depth.shape, color.shape) # (480, 640) (3, 480, 640) depth = depth[np.newaxis, :].astype(np.float64)
depth = torch.from_numpy(depth) #print(depth.size() ) # torch.Size([1, 480, 640]) cx = 325.5
cy = 253.5
fx = 518.0
fy = 519.0 intrinsics = np.array([
[fx, 0, cx],
[0, fy, cy],
[0, 0, 1],
]).astype(np.float64) intrinsics = intrinsics[np.newaxis, :] intrinsics = torch.from_numpy(intrinsics)
#print( intrinsics.size() ) # (1, 3, 3) ##########
from inverse_warp import pixel2cam # uv2xyz cam_coords = pixel2cam(depth, intrinsics.inverse() ) #print(cam_coords.size() ) xyz1 = cam_coords.detach().numpy().squeeze()
#print(xyz1.shape)
#
#fig = plt.subplots(1)
#plt.imshow( xyz1[0, :, :] )
#plt.title("x")
#
#fig = plt.subplots(1)
#plt.imshow( xyz1[1, :, :] )
#plt.title("y")
#
#fig = plt.subplots(1)
#plt.imshow( xyz1[2, :, :] )
#plt.title("z") # tx, ty, tz, rx, ry, rz -- [B, 6] 弧度制!!!
pose = np.array([0, -0.5, 0, 0, 0, 0]).astype(np.float64)
pose = pose[np.newaxis, :]
pose = torch.from_numpy(pose) from inverse_warp import pose_vec2mat
pose_mat = pose_vec2mat(pose, rotation_mode='euler') # [B,3,4] print(pose_mat) proj_cam_to_src_pixel = intrinsics @ pose_mat # [B, 3, 4] K*T_21
#print(proj_cam_to_src_pixel) from inverse_warp import cam2pixel
# cam2pixel 多传了一个Z出来
src_pixel_coords, Z2 = cam2pixel(cam_coords, # XYZ
proj_cam_to_src_pixel[:,:,:3], # R
proj_cam_to_src_pixel[:,:,-1:], # t
padding_mode='zeros') # [B,H,W,2] print(src_pixel_coords.size() ) uv2 = src_pixel_coords.detach().numpy().squeeze() #fig = plt.subplots(1)
#plt.imshow( uv2[:, :, 0] )
#plt.title("u2")
#
#fig = plt.subplots(1)
#plt.imshow( uv2[:, :, 1] )
#plt.title("v2") #################
b = color[:, :, 0]
g = color[:, :, 1]
r = color[:, :, 2] b = b.reshape(307200, 1)
g = g.reshape(307200, 1)
r = r.reshape(307200, 1) u2 = uv2[:, :, 0].reshape(307200, 1)
v2 = uv2[:, :, 1].reshape(307200, 1) color1 = np.zeros_like(color) zz = Z2.detach().numpy().squeeze() # (307200, ) #zz[133, 182] - depth_copy[133, 182] # 深度的确有变化 相差0.5 depth1 = np.zeros((480, 640)) for i in range(307200):
uu = u2[i]
vv = v2[i] if uu>-1 and uu < 1 and vv>-1 and vv<1:
xx = int(0.5*(uu+1)*639)
yy = int(0.5*(vv+1)*479) color1[yy, xx, 0] = b[i]
color1[yy, xx, 1] = g[i]
color1[yy, xx, 2] = r[i] depth1[yy, xx] = zz[i] #fig = plt.subplots(1)
#plt.imshow( cv2.cvtColor(color1, cv2.COLOR_BGR2RGB) )
#plt.title("color1")
#
#
#fig = plt.subplots(1)
#plt.imshow( depth1 )
#plt.title("depth1") fig=plt.figure() plt.subplot(121)
plt.imshow(cv2.cvtColor(color1, cv2.COLOR_BGR2RGB))
plt.title("color1") plt.subplot(122)
plt.imshow(depth1)
plt.title("depth1") plt.show()

当然,上图的效果不行,还要做插值才能好看点。

最新文章

  1. phongap、APICloud、ionic等app开发平台你都知道吗?
  2. 基于Metronic的Bootstrap开发框架总览
  3. 关于主机FTP连接不上,无法列出目录,列表错误,上传速度慢,掉速的解决办法
  4. LeetCode 453 Minimum Moves to Equal Array Elements
  5. ch2-4:遇到嵌套列表进行缩进打印
  6. 转载 sqlserver 锁的概念
  7. IIS 10.0 无法安装 URL rewrite重写模块 2.0解决办法
  8. (六)学习CSS之color属性
  9. AVAudioPlayer 播放音频
  10. C# Dll动态链接库
  11. poj 2533 Longest Ordered Subsequence(线性dp)
  12. 复杂透视表的SQL生成方法
  13. 一个基于netty的websocket聊天demo
  14. odoo开发基础--模型之基本字段类型
  15. 【docker】关于docker 中 镜像、容器的关系理解
  16. 【loj6041】「雅礼集训 2017 Day7」事情的相似度 后缀自动机+STL-set+启发式合并+离线+扫描线+树状数组
  17. Delphi APP 開發入門(十)REST Client 開發
  18. 使用xunit对asp.net core webapi进行集成测试
  19. OpenPAI:大规模人工智能集群管理平台介绍及任务提交指南
  20. Spring 配置RMI远程调用

热门文章

  1. Python如何将字符和Unicode编码转变
  2. vc 网络编程(socket)
  3. 安卓开发之利用XmlPullParser解析XML文件
  4. 【转】Delphi货币类型转中文大写金额
  5. TCP-HTTP ___UDP 应用场景
  6. PAT Basic 1083 是否存在相等的差 (20 分)
  7. C#中设置double类型数据的小数长度
  8. h5 特效
  9. SQLite3学习笔记(2)
  10. [Educational Codeforces Round 63 ] D. Beautiful Array (思维+DP)