Monday, 26 August 2013

Saving vectors in a Mat opencv

Saving vectors in a Mat opencv

I am trying to save 4 Matrix inside a Matrix.But I was not sure if we can
do that.So I converted my 4matrix to 4 vectors. Now I want to insert the 4
vectors in the matrix. My code is:
Mat hist_TL = Mat::zeros(20,1, CV_32F);
Mat hist_TR = Mat::zeros(20,1, CV_32F);
Mat hist_BL = Mat::zeros(20,1, CV_32F);
Mat hist_BR = Mat::zeros(20,1, CV_32F);
for(int i=1;i<=21;i++)
{
for(int k=0;k<TL_k_stats.rows;k++)
{
float angl_TL=TL_k_stats.at<float>(k,3);
float angl_TR=TR_k_stats.at<float>(k,3);
float angl_BL=BL_k_stats.at<float>(k,3);
float angl_BR=BR_k_stats.at<float>(k,3);
if((angl_TL<=bins[i]) && (angl_TL>bins[i-1]))
{
hist_TL.at<float>(i-1,0)+=TL_k_stats.at<float>(k,4);
}
if((angl_TR<=bins[i]) && (angl_TR>bins[i-1]))
{
hist_TR.at<float>(i-1,0)+=TR_k_stats.at<float>(k,4);
}
if((angl_BL<=bins[i]) && (angl_BL>bins[i-1]))
{
hist_BL.at<float>(i-1,0)+=BL_k_stats.at<float>(k,4);
}
if((angl_BR<=bins[i]) && (angl_BR>bins[i-1]))
{
hist_BR.at<float>(i-1,0)+=BR_k_stats.at<float>(k,4);
}
}
hist_TL=hist_TL.inv();
hist_TR=hist_TR.inv();
hist_BL=hist_BL.inv();
hist_BR=hist_BR.inv();
std::vector<float> vhist_TL;
std::vector<float> vhist_TR;
std::vector<float> vhist_BL;
std::vector<float> vhist_BR;
hist_TL.copyTo(vhist_TL);
hist_TR.copyTo(vhist_TR);
hist_BL.copyTo(vhist_BL);
hist_BR.copyTo(vhist_BR);
So I want to copy the the 4 vectors to one Matrix. If there is any way i
can do it without the conversion of matrix to vector.Please let me know.In
matlab we can directly store it into an array and return it like this
features[] = {hist_TL', hist_TR', hist_BL', hist_BR'};
So how can I achieve this in opencv??

No comments:

Post a Comment