2017-02-12 2 views
0

Ich habe eine 640 x 480 CV_8UC3Mat image und möchte die K-Means-Segmentierung durchführen. Also muss ich es in CV_32F umwandeln (kein Problem hier), umgestalten und k-means ausführen.OpenCV: Mat :: reshape() tut nichts

Das Problem ist reshape() tut nichts:

cv::Mat colorMat; 
image.convertTo (colorMat, CV_32FC3); 
std::cout << colorMat.size() << "; ch: " << colorMat.channels() << std::endl; // [640 x 480]; ch: 3 
colorMat.reshape (1, colorMat.rows * colorMat.cols); // Here I expect it to become [307200 x 3], 1 channel - each column representing a color component 
std::cout << colorMat.size() << "; ch: " << colorMat.channels() << std::endl; // [640 x 480]; ch: 3 

Bin ich etwas falsch?

Antwort

1

Sie müssen das Ergebnis der reshape zu einer Matrix zuzuordnen:

colorMat = colorMat.reshape (1, colorMat.rows * colorMat.cols); 

Sie sehen here (zweite Snippet) kann ein vollständiges Beispiel.

+0

Ja, ich habe gerade eine ähnliche Antwort geschrieben, nachdem ich [diese Frage] gelesen habe (http://stackoverflow.com/questions/13400239/reshaping-a-matrix-failed-in-opencv-2-4-3). Ihnen fehlt offensichtlich die Rückgabewertbeschreibung in der Dokumentation ... – Alex

+0

Tatsächlich zeigt der [doc] (http://docs.opencv.org/master/d3/d63/classcv_1_1Mat.html#a4eb96e3251417fa88b78e2abd6cfd7d8), dass der Rückgabewert ein 'ist Mat', aber wahrscheinlich ist es nicht klar genug. – Miki