OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Wed, 05 Jun 2013 15:13:02 -0500From Matlab to Chttp://answers.opencv.org/question/14638/from-matlab-to-c/
i have to translate this line from Matlab to C
for i_orient=1:chrOrient
stack = cat(3,resp{i_orient,:});
inComp=reshape(stack,r*c,chrScales);
Tsquared=whitening_sqr_meanDistance(inComp);
what I did is this, but I have to translate the cat function and I don t know why. resp is a MAt object in C
for(int i_orient=1;i_orient<=achrOrient;i_orient++){
//stack = cat(3,rpad{i_orient,:});
inCompImg = stack.reshape(numColComp,rows*cols*achrScales);
Tsquared=whitening_sqr_meanDistance(inCompImg);
conspic = Tsquared.reshape(numColComp,rows*cols);
Tue, 04 Jun 2013 09:37:02 -0500http://answers.opencv.org/question/14638/from-matlab-to-c/Answer by StevenPuttemans for <p>i have to translate this line from Matlab to C</p>
<pre><code>for i_orient=1:chrOrient
stack = cat(3,resp{i_orient,:});
inComp=reshape(stack,r*c,chrScales);
Tsquared=whitening_sqr_meanDistance(inComp);
</code></pre>
<p>what I did is this, but I have to translate the cat function and I don t know why. resp is a MAt object in C</p>
<pre><code> for(int i_orient=1;i_orient<=achrOrient;i_orient++){
//stack = cat(3,rpad{i_orient,:});
inCompImg = stack.reshape(numColComp,rows*cols*achrScales);
Tsquared=whitening_sqr_meanDistance(inCompImg);
conspic = Tsquared.reshape(numColComp,rows*cols);
</code></pre>
http://answers.opencv.org/question/14638/from-matlab-to-c/?answer=14640#post-id-14640cat isn't a standard function in C or C++ like it is in Matlab, you will have to implement the functionality yourself to match your needs. However, it is already weird that you only have two arguments for your matlab function, since documentation clearly states that min 3 arguments are needed.
I will explain the basics.
**MATLAB**
Cat function takes in account the number of dimensions and the matrices that need to be concatenated. 3 means you will use several 2D matrices into a 3D matrix structure.
**C/C++ - OpenCV**
Easiest way to do this is to create a 3D Mat structure, which can be done by using vectors. You can then copy each Mat that needs to be concatenated into the specified vector.
*Example code:*
Mat matrix_1;
Mat matrix_2;
vector<Mat> result;
result.push_back(matrix_1);
result.push_back(matrix_2);
If you want it for an arbitrary number of matrices, create a for loop structure.Tue, 04 Jun 2013 09:54:40 -0500http://answers.opencv.org/question/14638/from-matlab-to-c/?answer=14640#post-id-14640Comment by residentelvio for <p>cat isn't a standard function in C or C++ like it is in Matlab, you will have to implement the functionality yourself to match your needs. However, it is already weird that you only have two arguments for your matlab function, since documentation clearly states that min 3 arguments are needed.</p>
<p>I will explain the basics.</p>
<p><strong>MATLAB</strong></p>
<p>Cat function takes in account the number of dimensions and the matrices that need to be concatenated. 3 means you will use several 2D matrices into a 3D matrix structure.</p>
<p><strong>C/C++ - OpenCV</strong></p>
<p>Easiest way to do this is to create a 3D Mat structure, which can be done by using vectors. You can then copy each Mat that needs to be concatenated into the specified vector.</p>
<p><em>Example code:</em></p>
<pre><code>Mat matrix_1;
Mat matrix_2;
vector<Mat> result;
result.push_back(matrix_1);
result.push_back(matrix_2);
</code></pre>
<p>If you want it for an arbitrary number of matrices, create a for loop structure.</p>
http://answers.opencv.org/question/14638/from-matlab-to-c/?comment=14644#post-id-14644Thanks to explain. Maybe as I don t know a lot about Matlab I didn t explain that resp become from this line
resp{i_orient,i_scale}=abs(logGabor(imfft,sz2filt,r_o,theta_o,sigma_theta,radius,theta,sigma_r,padSize));
Maybe is important to explain the line of before. I searched something about {} and I did not understand what it do wellTue, 04 Jun 2013 10:28:26 -0500http://answers.opencv.org/question/14638/from-matlab-to-c/?comment=14644#post-id-14644Comment by StevenPuttemans for <p>cat isn't a standard function in C or C++ like it is in Matlab, you will have to implement the functionality yourself to match your needs. However, it is already weird that you only have two arguments for your matlab function, since documentation clearly states that min 3 arguments are needed.</p>
<p>I will explain the basics.</p>
<p><strong>MATLAB</strong></p>
<p>Cat function takes in account the number of dimensions and the matrices that need to be concatenated. 3 means you will use several 2D matrices into a 3D matrix structure.</p>
<p><strong>C/C++ - OpenCV</strong></p>
<p>Easiest way to do this is to create a 3D Mat structure, which can be done by using vectors. You can then copy each Mat that needs to be concatenated into the specified vector.</p>
<p><em>Example code:</em></p>
<pre><code>Mat matrix_1;
Mat matrix_2;
vector<Mat> result;
result.push_back(matrix_1);
result.push_back(matrix_2);
</code></pre>
<p>If you want it for an arbitrary number of matrices, create a for loop structure.</p>
http://answers.opencv.org/question/14638/from-matlab-to-c/?comment=14665#post-id-14665My advice, before translating matlab code to C/C++ using OpenCV, is to understand the actual matlab algorithm. Else there is litteraly no beginning. Also, problems about Matlab code shouldn't be adressed at this forum... read the [FAQ](http://answers.opencv.org/questions) to know why.Wed, 05 Jun 2013 01:56:30 -0500http://answers.opencv.org/question/14638/from-matlab-to-c/?comment=14665#post-id-14665Comment by residentelvio for <p>cat isn't a standard function in C or C++ like it is in Matlab, you will have to implement the functionality yourself to match your needs. However, it is already weird that you only have two arguments for your matlab function, since documentation clearly states that min 3 arguments are needed.</p>
<p>I will explain the basics.</p>
<p><strong>MATLAB</strong></p>
<p>Cat function takes in account the number of dimensions and the matrices that need to be concatenated. 3 means you will use several 2D matrices into a 3D matrix structure.</p>
<p><strong>C/C++ - OpenCV</strong></p>
<p>Easiest way to do this is to create a 3D Mat structure, which can be done by using vectors. You can then copy each Mat that needs to be concatenated into the specified vector.</p>
<p><em>Example code:</em></p>
<pre><code>Mat matrix_1;
Mat matrix_2;
vector<Mat> result;
result.push_back(matrix_1);
result.push_back(matrix_2);
</code></pre>
<p>If you want it for an arbitrary number of matrices, create a for loop structure.</p>
http://answers.opencv.org/question/14638/from-matlab-to-c/?comment=14719#post-id-14719Ok I understand what is a Cell. In my case I think I can use the vector Mat in a loop to obtain what I needWed, 05 Jun 2013 15:13:02 -0500http://answers.opencv.org/question/14638/from-matlab-to-c/?comment=14719#post-id-14719