https://github.com/opencv/opencv/blob/master/samples/cpp/stitching_detailed.cpp에 정의 된 CameraParams를 저장했습니다. 나는 다음과 같은 스크립트를 사용하여 파일을 YML이 카메라 매개 변수를 쓴intialize yml 파일의 카메라 매개 변수 opencv C++
struct CV_EXPORTS CameraParams
{
CameraParams();
CameraParams(const CameraParams& other);
const CameraParams& operator =(const CameraParams& other);
Mat K() const;
double focal; // Focal length
double aspect; // Aspect ratio
double ppx; // Principal point X
double ppy; // Principal point Y
Mat R; // Rotation
Mat t; // Translation
};
: 여기처럼 카메라 매개 변수 구조가 어떻게 보이는지 여기
<cameraParams> cameras;
FileStorage fs(fileName, FileStorage::WRITE);
fs << "K" << cameras.K();
fs << "R" << cameras.R;
fs << "t" << cameras.t;
fs << "ppx" << cameras.ppx;
fs << "ppy" << cameras.ppy;
fs << "focal" << cameras.focal;
fs << "aspect" << cameras.aspect;
fs.release();
및이를 파일 내용은 같이 방법 :
%YAML:1.0
---
K: !!opencv-matrix
rows: 3
cols: 3
dt: d
data: [ 2.4125938056164614e+003, 0., 447., 0.,
2.4125938056164614e+003, 3.3550000000000000e+002, 0., 0., 1. ]
R: !!opencv-matrix
rows: 3
cols: 3
dt: f
data: [ -9.67408061e-001, 7.91518241e-002, -2.40534484e-001,
-4.17553373e-002, -9.86752093e-001, -1.56770796e-001,
-2.49756604e-001, -1.41617730e-001, 9.57896829e-001 ]
t: !!opencv-matrix
rows: 3
cols: 1
dt: d
data: [ 0., 0., 0. ]
ppx: 447.
ppy: 3.3550000000000000e+002
focal: 2.4125938056164614e+003
aspect: 1.
이제이 동일한 매개 변수를 사용하여 다시 읽으 려하지만이 방법이 작동하지 않습니다 (런타임 오류가 발생 함). 다음은 사용 된 읽기 함수입니다.
Mat K, R, t;
double ppx, ppy, focal, aspect;
FileStorage fs(fileName, FileStorage::READ);
fs["K"] >> K;
fs["R"] >> R;
fs["t"] >> t;
fs["ppx"] >> ppx;
fs["ppy"] >> ppy;
fs["focal"] >> focal;
fs["aspect"] >> aspect;
camerasTest[i].K() = (Mat)K;
camerasTest[i].R = R;
camerasTest[i].t = t;
camerasTest[i].ppx = (double)ppx;
camerasTest[i].ppy = (double)ppy;
camerasTest[i].focal = (double)focal;
camerasTest[i].aspect = (double)aspect;
fs.release()
어떻게 해결할 수 있습니까?
은 올바른 파일 이름입니까? 줄 때 런타임 오류가 발생합니까? 또한 나는 당신이 "ppx"를 두 번 읽었다는 것을 안다. – Alexander
예 파일 이름이 정확합니다. ppx를 읽는 것은 실수였습니다. 나는 그것을 바로 잡았다. 감사합니다 – deathracer