Я пытался выяснить матрицу камеры и коэффициенты искажения, используя cvCalibrateCamera2
. Там не было никаких ошибок компиляции, но когда я пытаюсь запустить программу она дает:Поиск матрицы матрицы и искажений usinc cvCalibrateCamera2()
OpenCV error: Sizes of input arguments do not match(both matrices must have the same number of points) in cvConvertPointsHomogenous, file /build/buildd/opencv-2.3.1/modules/calib3d/src/fundam.cpp
размер матрицы хранения точек объекта в 4 х 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 Error: Bad argument (The total number of matrix elements is not divisible by the new number of rows) in cvReshape, file /build/buildd/opencv-2.3.1/modules/core/src/array.cpp, line 2755 terminate called after throwing an instance of 'cv::Exception' what(): /build/buildd/opencv-2.3.1/modules/core/src/array.cpp:2755: error: (-5) The total number of matrix elements is not divisible by the new number of rows in function cvReshape
Aborted (core dumped)
Я делаю это, беря 4 копланарных (не коллинеарных) точки (объект и изображение). По-прежнему получать ту же ошибку, следует ли увеличить количество очков? –
Калибровка должна выполняться по меньшей мере с 10 наборами точек изображения и объекта. Больше очков за комплект лучше. Я обычно откалибрую с 48 очками за комплект и использую 20 наборов. Существует несколько руководств по выполнению этой калибровки (даже с указанием рабочего кода). – Nallath
Хорошо, я попробую это. Спасибо за ответ. –