OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Sat, 21 Jan 2017 08:02:25 -0600Calculate Eigen Vector and Eigen Value for PCAhttp://answers.opencv.org/question/123382/calculate-eigen-vector-and-eigen-value-for-pca/I want to get eigenvalue and eigenvector. But it breaks.
this is my part of code.
Mat covmat=((matdev*matdev.t())/3); //data float matrix 5*5, this's working. but when I add with PCA function. It's break.
PCA pt_pca(covmat, Mat(), CV_PCA_DATA_AS_ROW, 0);
Mat pt_eig_vals = pt_pca.eigenvalues;
for (int i = 0; i < 4; ++i)
cout << pt_eig_vals.at<float>(i, 0) <<endl;
This is the error.
OpenCV error: Assertion Failed <data.channerls<> ==1> in unknown function, file ..\..\..\src\opencv\modules\core\src\matmul.cpp
Please somebody help me :(. ThanksFri, 20 Jan 2017 21:45:22 -0600http://answers.opencv.org/question/123382/calculate-eigen-vector-and-eigen-value-for-pca/Comment by belan for <p>I want to get eigenvalue and eigenvector. But it breaks.
this is my part of code.</p>
<pre><code>Mat covmat=((matdev*matdev.t())/3); //data float matrix 5*5, this's working. but when I add with PCA function. It's break.
PCA pt_pca(covmat, Mat(), CV_PCA_DATA_AS_ROW, 0);
Mat pt_eig_vals = pt_pca.eigenvalues;
for (int i = 0; i < 4; ++i)
cout << pt_eig_vals.at<float>(i, 0) <<endl;
</code></pre>
<p>This is the error.
OpenCV error: Assertion Failed <data.channerls&lt;&gt; =="1"> in unknown function, file ......\src\opencv\modules\core\src\matmul.cpp</p>
<p>Please somebody help me :(. Thanks</p>
http://answers.opencv.org/question/123382/calculate-eigen-vector-and-eigen-value-for-pca/?comment=123387#post-id-123387matdev is matrix data from txtfile like this.
%YAML:1.0
Point: !!opencv-matrix
rows: 5
cols: 5
dt: "2f"
data: [ 0., 0., 1., 0., -1., 0., 0., 0., 0., 0., 0., 0., -1., 0., -1.,
0., 0., 0., -1., 0., 0., 0., 0., 0., 1., 0., -1., 0., 0., 0., 1.,
0., 1., 0., -1., 0., 0., 0., -1., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0. ]Sat, 21 Jan 2017 01:14:45 -0600http://answers.opencv.org/question/123382/calculate-eigen-vector-and-eigen-value-for-pca/?comment=123387#post-id-123387Comment by belan for <p>I want to get eigenvalue and eigenvector. But it breaks.
this is my part of code.</p>
<pre><code>Mat covmat=((matdev*matdev.t())/3); //data float matrix 5*5, this's working. but when I add with PCA function. It's break.
PCA pt_pca(covmat, Mat(), CV_PCA_DATA_AS_ROW, 0);
Mat pt_eig_vals = pt_pca.eigenvalues;
for (int i = 0; i < 4; ++i)
cout << pt_eig_vals.at<float>(i, 0) <<endl;
</code></pre>
<p>This is the error.
OpenCV error: Assertion Failed <data.channerls&lt;&gt; =="1"> in unknown function, file ......\src\opencv\modules\core\src\matmul.cpp</p>
<p>Please somebody help me :(. Thanks</p>
http://answers.opencv.org/question/123382/calculate-eigen-vector-and-eigen-value-for-pca/?comment=123436#post-id-123436The data is vector x y -> 25 data. and I change/ reshape it to nxn = 5x5 (this is int). after that I convert to 32F. and that the result. any i idea for change it to 1 channel matrix with row n column same . thank youSat, 21 Jan 2017 08:02:25 -0600http://answers.opencv.org/question/123382/calculate-eigen-vector-and-eigen-value-for-pca/?comment=123436#post-id-123436Comment by berak for <p>I want to get eigenvalue and eigenvector. But it breaks.
this is my part of code.</p>
<pre><code>Mat covmat=((matdev*matdev.t())/3); //data float matrix 5*5, this's working. but when I add with PCA function. It's break.
PCA pt_pca(covmat, Mat(), CV_PCA_DATA_AS_ROW, 0);
Mat pt_eig_vals = pt_pca.eigenvalues;
for (int i = 0; i < 4; ++i)
cout << pt_eig_vals.at<float>(i, 0) <<endl;
</code></pre>
<p>This is the error.
OpenCV error: Assertion Failed <data.channerls&lt;&gt; =="1"> in unknown function, file ......\src\opencv\modules\core\src\matmul.cpp</p>
<p>Please somebody help me :(. Thanks</p>
http://answers.opencv.org/question/123382/calculate-eigen-vector-and-eigen-value-for-pca/?comment=123394#post-id-123394maybe it helps, if you could also explain, how you got this, and what is inside your data ?Sat, 21 Jan 2017 01:41:45 -0600http://answers.opencv.org/question/123382/calculate-eigen-vector-and-eigen-value-for-pca/?comment=123394#post-id-123394Comment by berak for <p>I want to get eigenvalue and eigenvector. But it breaks.
this is my part of code.</p>
<pre><code>Mat covmat=((matdev*matdev.t())/3); //data float matrix 5*5, this's working. but when I add with PCA function. It's break.
PCA pt_pca(covmat, Mat(), CV_PCA_DATA_AS_ROW, 0);
Mat pt_eig_vals = pt_pca.eigenvalues;
for (int i = 0; i < 4; ++i)
cout << pt_eig_vals.at<float>(i, 0) <<endl;
</code></pre>
<p>This is the error.
OpenCV error: Assertion Failed <data.channerls&lt;&gt; =="1"> in unknown function, file ......\src\opencv\modules\core\src\matmul.cpp</p>
<p>Please somebody help me :(. Thanks</p>
http://answers.opencv.org/question/123382/calculate-eigen-vector-and-eigen-value-for-pca/?comment=123386#post-id-123386what is `matdev` ? (please show, how you construct that)
can you try again to retrieve the correct error msg ? `data.channels()==1` would make sense, `data.channels<>==1` is a syntax error.Sat, 21 Jan 2017 01:02:51 -0600http://answers.opencv.org/question/123382/calculate-eigen-vector-and-eigen-value-for-pca/?comment=123386#post-id-123386Answer by berak for <p>I want to get eigenvalue and eigenvector. But it breaks.
this is my part of code.</p>
<pre><code>Mat covmat=((matdev*matdev.t())/3); //data float matrix 5*5, this's working. but when I add with PCA function. It's break.
PCA pt_pca(covmat, Mat(), CV_PCA_DATA_AS_ROW, 0);
Mat pt_eig_vals = pt_pca.eigenvalues;
for (int i = 0; i < 4; ++i)
cout << pt_eig_vals.at<float>(i, 0) <<endl;
</code></pre>
<p>This is the error.
OpenCV error: Assertion Failed <data.channerls&lt;&gt; =="1"> in unknown function, file ......\src\opencv\modules\core\src\matmul.cpp</p>
<p>Please somebody help me :(. Thanks</p>
http://answers.opencv.org/question/123382/calculate-eigen-vector-and-eigen-value-for-pca/?answer=123389#post-id-123389unfortunately, opencv's PCA (as well as eigen()) can only handle Mat's with a single channel as input, your matdev has 2.
(then, also note, that the covariance Matrix is already calculated internally, so you would not have to do that manually before using PCA)Sat, 21 Jan 2017 01:24:31 -0600http://answers.opencv.org/question/123382/calculate-eigen-vector-and-eigen-value-for-pca/?answer=123389#post-id-123389Comment by belan for <p>unfortunately, opencv's PCA (as well as eigen()) can only handle Mat's with a single channel as input, your matdev has 2.</p>
<p>(then, also note, that the covariance Matrix is already calculated internally, so you would not have to do that manually before using PCA)</p>
http://answers.opencv.org/question/123382/calculate-eigen-vector-and-eigen-value-for-pca/?comment=123431#post-id-123431Ok, thank you, I will try it.Sat, 21 Jan 2017 06:14:26 -0600http://answers.opencv.org/question/123382/calculate-eigen-vector-and-eigen-value-for-pca/?comment=123431#post-id-123431Comment by berak for <p>unfortunately, opencv's PCA (as well as eigen()) can only handle Mat's with a single channel as input, your matdev has 2.</p>
<p>(then, also note, that the covariance Matrix is already calculated internally, so you would not have to do that manually before using PCA)</p>
http://answers.opencv.org/question/123382/calculate-eigen-vector-and-eigen-value-for-pca/?comment=123393#post-id-123393you could either split it into 2 planes, and handle those seperately:
Mat planes[2];
split(matdev, planes);
PCA pca1(planes[0],...);
PCA pca2(planes[1],...);
or try to reshape it to a 1channel, [10x5] mat:
Mat matdev1 = matdev.reshape(1,5);
but i have no idea, if any of this makes sense with your data. maybe you have to go back, andfind out, why matdev looks like it is, and if this is really the desired format.Sat, 21 Jan 2017 01:40:22 -0600http://answers.opencv.org/question/123382/calculate-eigen-vector-and-eigen-value-for-pca/?comment=123393#post-id-123393Comment by belan for <p>unfortunately, opencv's PCA (as well as eigen()) can only handle Mat's with a single channel as input, your matdev has 2.</p>
<p>(then, also note, that the covariance Matrix is already calculated internally, so you would not have to do that manually before using PCA)</p>
http://answers.opencv.org/question/123382/calculate-eigen-vector-and-eigen-value-for-pca/?comment=123391#post-id-123391So, how to make it, to be single channel? I'm a beginner in opencv.Sat, 21 Jan 2017 01:30:11 -0600http://answers.opencv.org/question/123382/calculate-eigen-vector-and-eigen-value-for-pca/?comment=123391#post-id-123391