ich eine Matte Objekt, das mit einer Schleife erstellt:OpenCV: nicht Mat Elemente zugreifen
cluster_centre = cv::Mat(num_clusters,num_dimensions,cv::DataType<double>::type)
// <double> is essential
for (j = 0; j < num_clusters; j++) {
for (k = 0; k < num_dimensions; k++) {
...
cluster_centre.at<double>(j,k) = ...
}
}
// rounding numbers 0...255
cluster_centre.convertTo(cluster_centre, CV_32S);
Die Ausgabe von cout << cluster_centre << endl
ist OK:
[79, 99, 148;
73, 29, 14;
254, 254, 254;
171, 70, 3;
178, 189, 211]
Und es scheint, dass Umbildung hat offenbar keine Wirkung (cols
und rows
gleich bleiben):
cluster_centre.reshape(3,1); // storing as 1-D array of 3-channel vectors
cout << cluster_centre.cols //output 3;
und wenn ich tr y auf meine Elemente zuzugreifen und BGR Farbe malen weiter ich:
cout << Scalar(
mycolors.at<uchar>(0,0),
mycolors.at<uchar>(0,1),
mycolors.at<uchar>(0,2))<<endl;
[79, 0, 0, 0] // ??
cout << Scalar(
mycolors.at<uchar>(0,0),
mycolors.at<uchar>(1,0),
mycolors.at<uchar>(2,0))<<endl;
[79, 73, 254, 0] //vertical
EDIT: Die Matrix isContinuous
, geprüft.
Es ist nicht sehr klar ... Aber werfen Sie einen Blick auf das zweite Schnipsel [hier] (http://Stackoverflow.com/a/34734939/5008845). Für mich scheint es, dass Sie versuchen, etwas sehr ähnliches zu tun – Miki
@Miki Die Ausgabe von 'cout << mycolors.at (0) << endl;' ist das gleiche: '[(erster Wert), 0,0 ] ' –
Slowpoke
@Miki Es scheint, dass die Floats zugänglich waren vor dem Runden' cluster_centre.convertTo (cluster_centre, CV_32S); ' – Slowpoke