【问题标题】:Finding camera and distortion matrix usinc cvCalibrateCamera2( )寻找相机和失真矩阵 usa inc cv CalibrateCamera 2( )
【发布时间】:2013-06-09 09:53:22
【问题描述】:

我试图使用cvCalibrateCamera2 找出相机矩阵和失真系数。没有编译错误,但是当我尝试执行它给出的程序时:

OpenCV 错误:在 cvConvertPointsHomogenous,文件 /build/buildd/opencv-2.3.1/modules/calib3d/src/fundam.cpp 中输入参数的大小不匹配(两个矩阵必须具有相同的点数)

存储对象点的矩阵大小为 4 x 3,存储图像点的矩阵大小为 4 X2,有什么问题?

现在我对我的代码进行了某些更改。 这是我正在使用的代码:

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/calib3d/calib3d.hpp"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
//function to call cvCalibrateCamera2()
void calibrate(CvMat* object_points, CvMat* image_points, CvMat* intrinsic,CvMat* distortion)
{
const int point_count= object_points->rows;
const int image_count=object_points->rows/point_count;
CvMat* const full_object_points = cvCreateMat(image_count*point_count,3,CV_32FC1);
CvMat* const point_counts= cvCreateMat(image_count,1,CV_32SC1);
for(int i =0; i<image_count;i++)
{
CV_MAT_ELEM(*point_counts,float , i,0)= point_count;
    for(int j=0;j<point_count;j++)
    {
        for(int k=0; k<3;k++){
        CV_MAT_ELEM(*full_object_points,float,i*point_count+j,k)=CV_MAT_ELEM(*object_points,float,j,k);
        }
    }
}
cvCalibrateCamera2(full_object_points,image_points,point_counts,cvSize(1,1),intrinsic, distortion,NULL,NULL,0);
}
int main()
{
const float points[][2]={{1,2},{0,0},{3,5},{5,2}};
const int image_count=5;
const int point_count=sizeof(points)/sizeof(points[1]);
CvMat* const object_points=cvCreateMat(point_count,3,CV_32FC1);
for(int i=0; i<point_count;i++)
{
CV_MAT_ELEM(*object_points, float, i,0)=points[i][0];
CV_MAT_ELEM(*object_points, float, i,1)=points[i][1];
CV_MAT_ELEM(*object_points, float, i,2)=0;
}
CvMat* const image_points=cvCreateMat(image_count*point_count,2,CV_32FC1);
CvMat* const intrinsic=cvCreateMat(3,3,CV_32FC1);
CvMat* const distortion=cvCreateMat(5,1,CV_32FC1);
calibrate(object_points,image_points,intrinsic,distortion);
}

执行时出现以下错误:

OpenCV 错误:cvReshape,文件 /build/buildd/opencv-2.3.1/modules/core/src/array.cpp 中的参数错误(矩阵元素的总数不能被新的行数整除),第 2755 行 在抛出 'cv::Exception' 的实例后调用终止 what():/build/buildd/opencv-2.3.1/modules/core/src/array.cpp:2755:错误:(-5)矩阵元素的总数不能被函数中的新行数整除cvReshape

中止(核心转储)

【问题讨论】:

    标签: opencv camera-calibration calibration


    【解决方案1】:

    错误消息的确切含义。对象需要与图像点相同数量的点。如果您尝试使用 10 组图像点进行计算,但使用 9 组对象点,则会返回此错误。

    我建议使用 c++ openCV,因为它接受带有点和矩阵的向量作为输入。检查此类向量的长度比检查矩阵要容易得多。

    【讨论】:

    • 我正在这样做,取 4 个共面(非共线)点(对象和图像)。还是一样的错误,我应该增加点数吗?
    • 校准应至少使用 10 组图像和对象点。每组得分越多越好。我通常以每组 48 个点进行校准,并使用 20> 组。有几个关于如何执行此校准的教程(即使提供了工作代码)。
    • 好的,我会试试的。感谢您的回复。
    猜你喜欢
    • 2012-10-11
    • 1970-01-01
    • 2016-03-05
    • 2013-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-15
    • 1970-01-01
    相关资源
    最近更新 更多