c++ - Using OpenCV cv::kmeans() with one-dimensional input -


Although one-dimensional data uses, I can not do this with the C ++ interface:

< Pre> integer size = 100; Std :: vector & lt; Float & gt; Data (size); {Data for [i] = (float) i; (for size_t i = 0; i

This fails with internal arguments because cv :: kmeans is expected to be two-dimensional input CV_Assert (N> = K) failed It remains because K is 3 and N is 1. What's my fault

edit :

Tested, it reads:

  // ... Bool isrow = data. Rows == 1 & amp; Amp; Data.channels () & gt; 1; // more one channel int n =! Aero? Data.rows: data.cols; // ... // ... CV_Assert (N> = K);  

Therefore, if you have your data in a row, you need to have more than one channel in your input matrix and more columns than K .


A quick solution: kmeans

Before using your matrix

it does not copy any data Just changes the dimensions of the matrix so if you have: After reshaping with 2 rows:

  [12345678] // mat 1 x 8  

  [1234 | // one matte 2x4 5678]  

You should be able to call kmeans then. (Do not forget to reshape it)


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -