- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用棋盘来获取外部矩阵。findChessboardCorners
正确找到图像点,并且应该正确设置对象点。但是当捕捉相同的场景时,我得到了非常奇怪的结果。
+2,2267e+35 -1,8254e+00 -1,4695e+07 +3,8279e+08 +1,5230e+19 -1,5452e+00 -1,4752e-21 +3,5204e+16 -1,3286e+13 +1,7682e+00 -2,9379e-15 +2,6464e-34 +0,0000e+00 +0,0000e+00 +0,0000e+00 +1,0000e+00 -nan -1,7778e+00 +5,9374e-20 +3,4842e+17 +2,5102e+36 +1,6198e+00 -1,1908e-31 +2,6853e+16 -4,1601e+13 +1,8132e+00 +1,7271e+27 +7,3568e-01 +0,0000e+00 +0,0000e+00 +0,0000e+00 +1,0000e+00
So I'm obviously doing something wrong. What?
Code:
#include <cv.h>
#include <highgui.h>
#include <vector>
#include <iostream>
#include <cstdio>
class Camera
{
cv::VideoCapture* cam;
cv::Mat_<float> intr, extr;
public:
Camera (int n = 0)
{
intr = cv::Mat_<float>(3, 3, 0.f);
intr.at<float>(0, 0) = 2.7105506628580332e+02;
intr.at<float>(0, 1) = 0;
intr.at<float>(0, 2) = 1.5950000000000000e+02;
intr.at<float>(1, 0) = 0;
intr.at<float>(1, 1) = 2.7105506628580332e+02;
intr.at<float>(1, 2) = 1.1950000000000000e+02;
intr.at<float>(2, 0) = 0;
intr.at<float>(2, 1) = 0;
intr.at<float>(2, 2) = 1;
cam = new cv::VideoCapture(n);
if(!cam->isOpened())
std::cerr << "arg\n";
}
void calib_extrinsic ()
{
cv::namedWindow("w");
std::vector<cv::Point3f> obj_points;
std::vector<cv::Point2f> img_points;
std::vector<cv::Point2f> corners;
cv::Size size(4, 3);
float cell_size = 1;
for(int i = 0; i < size.height; ++i)
for(int j = 0; j < size.width; ++j)
obj_points.push_back(cv::Point3f(float(j*cell_size),
float(i*cell_size), 0.f));
cv::Mat img, gray;
while(1) {
*cam >> img;
cv::cvtColor(img, gray, CV_BGR2GRAY);
img_points.clear();
corners.clear();
bool found = cv::findChessboardCorners(gray, size, corners,
CV_CALIB_CB_ADAPTIVE_THRESH
| CV_CALIB_CB_FILTER_QUADS);
if(found) {
// cv::cornerSubPix(gray, corners,
// cv::Size(11, 11),
// cv::Size(-1, -1),
// cv::TermCriteria(CV_TERMCRIT_EPS
// | CV_TERMCRIT_ITER, 30, 0.1));
cv::drawChessboardCorners(img, size, cv::Mat(corners), found);
}
cv::imshow("w", img);
int key = cv::waitKey(15) & 0xff;
//std::cout << found << " " << key << "\n";
if(key == ' ' && found) {
cv::Mat_<float> distCoeffs (4, 1, 0.f);
cv::Mat_<float> r (3, 3, 0.f);
cv::Mat_<float> rvecs (3, 1, 0.f);
cv::Mat_<float> tvecs (3, 1, 0.f);
cv::solvePnP(cv::Mat(obj_points), cv::Mat(corners), intr, distCoeffs, rvecs, tvecs);
cv::Rodrigues(rvecs, r);
extr = cv::Mat_<float>(4, 4, 0.f);
for(int y = 0; y < 3; y++) {
for(int x = 0; x < 3; x++)
extr.at<float>(y, x) = r.at<float>(y, x);
extr.at<float>(y, 3) = tvecs.at<float>(y, 0);
}
extr.at<float>(3, 0) = 0.f;
extr.at<float>(3, 1) = 0.f;
extr.at<float>(3, 2) = 0.f;
extr.at<float>(3, 3) = 1.f;
for(int y = 0; y < 4; y++) {
for(int x = 0; x < 4; x++) {
printf("%+.4e ", extr.at<float>(y, x));
}
putchar('\n');
}
putchar('\n');
//break;
}
}
}
};
int main ()
{
Camera cam;
cam.calib_extrinsic();
}
最佳答案
这是一个类型问题。 SolvePNP 创建 double 矩阵,而不是 float 。
关于c++ - 我想要使用棋盘的外在矩阵,我用 solvePnP 得到了奇怪的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15095739/
我正在尝试借助 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我
我是一名优秀的程序员,十分优秀!