- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我正在尝试使用单应性在 Blender 3d 中校准和查找单个虚拟相机的位置和旋转。我正在使用 Blender,以便在进入更困难的现实世界之前仔细检查我的结果。
我在我的固定相机的视野中渲染了十张棋盘在不同位置和旋转的图片。使用 OpenCV 的 Python,我使用 cv2.calibrateCamera
从十幅图像中检测到的棋盘角找到内在矩阵,然后在 cv2.solvePnP
中使用它来查找外部参数(平移和旋转)。
然而,虽然估计的参数接近实际参数,但还是有一些可疑之处。我对翻译的初步估计是 (-0.11205481,-0.0490256,8.13892491)
。实际位置是 (0,0,8.07105)
。很接近吧?
但是,当我稍微移动和旋转相机并重新渲染图像时,估计的平移变得更远了。估计:(-0.15933154,0.13367286,9.34058867)
。实际:(-1.7918,-1.51073,9.76597)
。 Z 值接近,但 X 和 Y 不接近。
我完全糊涂了。如果有人能帮我解决这个问题,我将不胜感激。这是代码(它基于 OpenCV 提供的 Python2 校准示例):
#imports left out
USAGE = '''
USAGE: calib.py [--save <filename>] [--debug <output path>] [--square_size] [<image mask>]
'''
args, img_mask = getopt.getopt(sys.argv[1:], '', ['save=', 'debug=', 'square_size='])
args = dict(args)
try: img_mask = img_mask[0]
except: img_mask = '../cpp/0*.png'
img_names = glob(img_mask)
debug_dir = args.get('--debug')
square_size = float(args.get('--square_size', 1.0))
pattern_size = (5, 8)
pattern_points = np.zeros( (np.prod(pattern_size), 3), np.float32 )
pattern_points[:,:2] = np.indices(pattern_size).T.reshape(-1, 2)
pattern_points *= square_size
obj_points = []
img_points = []
h, w = 0, 0
count = 0
for fn in img_names:
print 'processing %s...' % fn,
img = cv2.imread(fn, 0)
h, w = img.shape[:2]
found, corners = cv2.findChessboardCorners(img, pattern_size)
if found:
if count == 0:
#corners first is a list of the image points for just the first image.
#This is the image I know the object points for and use in solvePnP
corners_first = []
for val in corners:
corners_first.append(val[0])
np_corners_first = np.asarray(corners_first,np.float64)
count+=1
term = ( cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_COUNT, 30, 0.1 )
cv2.cornerSubPix(img, corners, (5, 5), (-1, -1), term)
if debug_dir:
vis = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
cv2.drawChessboardCorners(vis, pattern_size, corners, found)
path, name, ext = splitfn(fn)
cv2.imwrite('%s/%s_chess.bmp' % (debug_dir, name), vis)
if not found:
print 'chessboard not found'
continue
img_points.append(corners.reshape(-1, 2))
obj_points.append(pattern_points)
print 'ok'
rms, camera_matrix, dist_coefs, rvecs, tvecs = cv2.calibrateCamera(obj_points, img_points, (w, h))
print "RMS:", rms
print "camera matrix:\n", camera_matrix
print "distortion coefficients: ", dist_coefs.ravel()
cv2.destroyAllWindows()
np_xyz = np.array(xyz,np.float64).T #xyz list is from file. Not shown here for brevity
camera_matrix2 = np.asarray(camera_matrix,np.float64)
np_dist_coefs = np.asarray(dist_coefs[:,:],np.float64)
found,rvecs_new,tvecs_new = cv2.solvePnP(np_xyz, np_corners_first,camera_matrix2,np_dist_coefs)
np_rodrigues = np.asarray(rvecs_new[:,:],np.float64)
print np_rodrigues.shape
rot_matrix = cv2.Rodrigues(np_rodrigues)[0]
def rot_matrix_to_euler(R):
y_rot = asin(R[2][0])
x_rot = acos(R[2][2]/cos(y_rot))
z_rot = acos(R[0][0]/cos(y_rot))
y_rot_angle = y_rot *(180/pi)
x_rot_angle = x_rot *(180/pi)
z_rot_angle = z_rot *(180/pi)
return x_rot_angle,y_rot_angle,z_rot_angle
print "Euler_rotation = ",rot_matrix_to_euler(rot_matrix)
print "Translation_Matrix = ", tvecs_new
最佳答案
我认为您可能将 tvecs_new
视为相机位置。有点令人困惑,事实并非如此!事实上,它是世界原点在相机坐标中的位置。要在对象/世界坐标中获得相机姿势,我相信你需要
-np.matrix(rotation_matrix).T * np.matrix(tvecs_new)
您可以使用 cv2.decomposeProjectionMatrix(P)[-1]
获得欧拉角,其中 P
是 [r|t]
3 x 4 外部矩阵。
我找到了 this成为一篇关于内在和外在的很好的文章......
关于Python Opencv SolvePnP 产生错误的翻译向量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14515200/
我正在尝试借助 OpenCV 的 solvePNP() 获取相机的姿势。 运行程序后出现以下错误: OpenCV Error: Assertion failed (npoints >= 0 && np
我有一个非常简单的任务:获取平面三角形的欧拉角。图案看起来像 this 因此,算法: 1) 从网络摄像头获取图像 -- 完成 2) 转换为灰阶、滤镜等——完成 3) 获取所有连接组件的质量中心,并过滤
有人可以帮助我计算相机的 Y 轴旋转吗?我使用 SolvePnP 来获取 rvec。从这个 rvec 我想知道我的相机绕着它自己的 Y 轴旋转了多少。 PointF[] ImagePointsCam
我正在使用运动结构进行多 View 几何重建。到目前为止,我有以下内容 两张图片作为初始输入相机参数和畸变系数初始输入图像的工作校正流水线创建视差图通过遍历视差图并将值作为 z(x 和 y 是视差图中
我正在使用函数 solvePnP 通过视觉标记来估计我的机器人的姿势。有时我在两个连续的帧中得到错误的结果。在文件 problem.cpp 中,您可以看到其中一个结果。 点集对应于两个连续帧中的相同标
我在使用OpenCV中的cv2.solvePnP函数时遇到问题。此功能用于获取棋盘的姿势估计。在以下代码之后,我得到一个错误: for fname in glob.glob('Images/Calib
我对 OpenCV 中 solvePnP 函数的使用有一点困惑。 我有相机内部参数的矩阵,我已经确定了图像中的一些关键点,我正在尝试估计校准的外部参数。 solvePnP 的文档说: cv2.solv
我目前正在尝试通过获取两个摄像头都可以看到的跟踪模式的位置来获取两个 Kinect v2 的相对位置。不幸的是,我似乎无法获得图案原点的正确位置。 这是我当前获取图案相对于相机位置的代码: std::
我正在像这样使用 solvePnP.. import cv2 import numpy as np # Read Image im = cv2.imread("headPose.jpg"); size
我无法理解 Perspective-n-Point问题。几个问题: s 有什么用?为什么我们需要图像点的比例因子? K[R|T] 是一个“坐标变换矩阵”,它将同质世界点 p_w 移动到 2D 的坐标空
我有一个类似于 this 的不对称圆点图案.我使用 opencv solvePnP 函数根据 a) 已知的 3D 图案点来估计图案的姿态; b) 二维图像中检测到的图案点 我发现在某些情况下(当图案正
我正在尝试在一张照片上构建静态增强现实场景,其中平面和图像上的共面点之间有 4 个定义的对应关系。 这是一个分步流程: 用户使用设备的相机添加图像。假设它包含一个以某种视角捕获的矩形。 用户定义矩形的
我正在尝试使用单应性在 Blender 3d 中校准和查找单个虚拟相机的位置和旋转。我正在使用 Blender,以便在进入更困难的现实世界之前仔细检查我的结果。 我在我的固定相机的视野中渲染了十张棋盘
这是错误: cv2.solvePnP(obj_points, image_points, mtx, dist) cv2.error: OpenCV(4.2.0) C:\projects\opencv-
是否可以将 OpenCV 的 solvePNP 与 equirectangular 图像一起使用?我有一个 equirectangular 图像,我在这个图像中有四个点(红点)和它们的像素坐标,然后我
我想获得高架摄像机的姿势(翻译:x、y、z 和旋转:世界坐标系中的 Rx、Ry、Rz)。通过用机械臂移动 ChArUco 校准板,我得到了许多物点和图像点(像这样 https://www.youtub
我正在使用棋盘来获取外部矩阵。findChessboardCorners 正确找到图像点,并且应该正确设置对象点。但是当捕捉相同的场景时,我得到了非常奇怪的结果。 我正在使用 OpenCV 2.1.0
我使用以下代码对图像进行地理配准 有输入 grid = "for example a utm grid" img_raw = cv2.imread(filename) mtx, dist = "
在过去的几周里,我尝试学习纠正图像,并且在这里的人们的帮助下,我已经设法更好地理解它。大约一周前,我设置了一个我想纠正的测试示例(查看上图)。使用函数 T = cv2.getPerspectiveTr
我有一个校准过的相机(固有矩阵和失真系数),我想知道相机位置,知道图像中的一些 3d 点及其对应点(2d 点)。 我知道 cv::solvePnP 可以帮助我,并且在阅读 this 之后和 this我
我是一名优秀的程序员,十分优秀!