Unusual behavior of Matx
Hi!
I have this piece of code where before and after reading the intensity of an image, the last element(initially non zero, say 100) of a 3x3 matrix Matx33f becomes zero.
Matx33f woah;
woah(1,1) = 0.0;
woah(1,2) = 0.0;
woah(1,3) = 0.0;
woah(2,1) = 0.0;
woah(2,2) = 0.0;
woah(2,3) = 0.0;
woah(3,1) = 0.0;
woah(3,2) = 10.0;
woah(3,3) = 10.0;
cout << "what" <<woah(3,2)<< " "<<woah(3,3)<<endl;
Scalar intensity = image.at<uchar>(1, 1);
cout << "this" <<woah(3,2)<< " "<<woah(3,3)<<endl;
and weirdly enough, the output is
what10 10
this10 0
This happens with the last element of Matx44f too! but not with Matx22f.
For completion, i'll copy the whole code below:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <sstream>
#include <fstream>
#include <ctime>
#define PIXEL_LENGTH 0.000006
#define FOCAL_LENGTH 611.739321
#define CAM_DIST_X -0.079115608
#define CAM_DIST_Y -0.000558381
#define CAM_DIST_Z 0.000922792
#define Uo 343.228336
#define Vo 244.798311
using namespace cv;
using namespace std;
string convertInt(int number)
{
stringstream ss;//create a stringstream
ss << number;//add number to the stream
return ss.str();//return a string with the contents of the stream
}
void eular2rotmatx(vector<float> & data, Matx33f & rot){
float alpha,beta,gamma;
alpha = data[5];
beta = data[6];
gamma = data[7];
rot(1,1) = cos(gamma)*cos(beta)*cos(alpha) - sin(gamma)*sin(alpha);
rot(1,2) = cos(gamma)*cos(beta)*sin(alpha) + sin(gamma)*cos(alpha);
rot(1,3) = - cos(gamma)*sin(beta);
rot(2,1) = - sin(gamma)*cos(beta)*cos(alpha) - cos(gamma)*sin(alpha);
rot(2,2) = - sin(gamma)*cos(beta)*sin(alpha) + cos(gamma)*cos(alpha);
rot(2,3) = sin(gamma)*sin(beta);
rot(3,1) = sin(beta)*cos(alpha);
rot(3,2) = sin(beta)*sin(alpha);
rot(3,3) = cos(beta);
}
bool camOrientation(string & data_line, Point3f & translation, Matx33f & rotation){
stringstream lineStream(data_line);
string cell;
vector<float> data;
while(getline(lineStream,cell,','))
{
data.push_back(::atof(cell.c_str()));
}
//cout << data[1] << " " << data[2]<<" "<< data[1] + data[2]<< endl;
if(data[2] == data[3] && data[3] == data[4] && data[4] == 0){
cout <<"No position: Vicon not initialized"<<endl;
return false;
}else{
translation.x = data[2];
translation.y = data[3];
translation.z = data[4];
eular2rotmatx(data,rotation);
return true;
}
}
int main( int argc, char** argv )
{
ofstream myfile;
ifstream viconFile;
//myfile.open ("/home/bharat/opencv_trial/dataset/loc.txt");
string imageName,pathToImage,imageExt,pathToPointFolder,pointFileName, pathToViconFile, viconFileName;
pathToImage = "/home/bharat/opencv_trial/dataset/";
imageExt = ".png";
pathToPointFolder = "/home/bharat/opencv_trial/dataset/Points/";
pathToViconFile = "/home/bharat/opencv_trial/dataset/";
viconFileName = pathToViconFile + "log1.csv";
viconFile.open(viconFileName.c_str());
Point3f cam_trans;
Matx33f cam_rot;
int i = 0;
Mat image;
string camLine;
getline(viconFile,camLine);//see off the first field line
while(i<22){
if(getline(viconFile,camLine)){
int start_s=clock();
cout << camLine<<endl;
if(camOrientation(camLine, cam_trans, cam_rot)){
cout << cam_rot(1,1) <<" "<< cam_rot(1,2) <<" "<< cam_rot(1,3) <<"\n";
cout << cam_rot(2,1 ...
please also look at Rodrigues , you don't have to roll your own eular2rotmat()