I need to use a Queue to keep rotation and translation matrices generated (using cvFindExtrinsicCameraParams2()
) for each contour.
But when I pop elements from the queue all I can get is copies of the same pair of rotation and translation.
I doubt it has something to do with pointers, but when I tried to avoid pointers in the struct
, the cvFindExtrinsicCameraParams2()
threw an Exception. How to fix this?
//------------A.h------------------
struct RotMat{
CvMat *rotation_;
CvMat *translation_;
};
//-----------B.h-------------------
class B {
private:
CvMat *rotation;
CvMat *translation;
}
//-----------B.cpp-----------------
#include "A.h"
#include "B.h"
void functionx(){
queue<RotMat> rtq;
// start loop
// cvFindExtrinsicCameraParams2(&object_points,&image_points,
// intrinsic,distortion,
// rotation,translation);
RotMat rt = {rotation, translation};
rtq.push(rt);
// end loop
while(!rtq.empty()) { //assume rtq has n elements
RotMat rt_ = rtq.front();
rtq.pop();
cout<< rt_.translation_->data.fl[1]; // the same value pair is
cout<< rt_.rotation->data.fl[1]; // printed in all n iterations
}
}
Test Results
Total markers detected = 2
Marker 1: Translation: -249.227
Rotation: -0.0124926
Marker 2: Translation: -249.227
Rotation: -0.0124926