mirror of
https://github.com/opencv/opencv.git
synced 2024-11-24 03:00:14 +08:00
Merge pull request #10258 from savuor:fix/kmeans_channels
* kmeans: number of channels in _centers fixed * fixedType() is checked now
This commit is contained in:
parent
28b19d6e3e
commit
bab86d65cb
@ -458,7 +458,12 @@ double cv::kmeans( InputArray _data, int K,
|
||||
{
|
||||
best_compactness = compactness;
|
||||
if( _centers.needed() )
|
||||
centers.copyTo(_centers);
|
||||
{
|
||||
Mat reshaped = centers;
|
||||
if(_centers.fixedType() && _centers.channels() == dims)
|
||||
reshaped = centers.reshape(dims);
|
||||
reshaped.copyTo(_centers);
|
||||
}
|
||||
_labels.copyTo(best_labels);
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ int main( int /*argc*/, char** /*argv*/ )
|
||||
Mat points(sampleCount, 1, CV_32FC2), labels;
|
||||
|
||||
clusterCount = MIN(clusterCount, sampleCount);
|
||||
Mat centers;
|
||||
std::vector<Point2f> centers;
|
||||
|
||||
/* generate random sample from multigaussian distribution */
|
||||
for( k = 0; k < clusterCount; k++ )
|
||||
@ -65,9 +65,9 @@ int main( int /*argc*/, char** /*argv*/ )
|
||||
Point ipt = points.at<Point2f>(i);
|
||||
circle( img, ipt, 2, colorTab[clusterIdx], FILLED, LINE_AA );
|
||||
}
|
||||
for (i = 0; i < centers.rows; ++i)
|
||||
for (i = 0; i < (int)centers.size(); ++i)
|
||||
{
|
||||
Point2f c = centers.at<Point2f>(i);
|
||||
Point2f c = centers[i];
|
||||
circle( img, c, 40, colorTab[i], 1, LINE_AA );
|
||||
}
|
||||
cout << "Compactness: " << compactness << endl;
|
||||
|
Loading…
Reference in New Issue
Block a user