Skip to content

Conversation

savuor
Copy link
Contributor

@savuor savuor commented Dec 7, 2017

resolves #10174

@@ -458,7 +458,11 @@ double cv::kmeans( InputArray _data, int K,
{
best_compactness = compactness;
if( _centers.needed() )
{
if(_centers.channels() == dims)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the function allow to pass complex configuration of input points since in L239 int dims = (isrow ? 1 : data0.cols)*data0.channels(). IMHO it should be possible for the user to provide the same configuration for the OutputArray _centers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense, will be implemented

@savuor savuor force-pushed the fix/kmeans_channels branch from 153cda1 to fb21538 Compare December 11, 2017 14:02
@savuor savuor force-pushed the fix/kmeans_channels branch from fb21538 to 9a912ce Compare December 11, 2017 14:55
centers.copyTo(_centers);
{
Mat reshaped = centers;
if(_centers.rows() == 1 && _centers.channels() == dims)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the fix is incorrect. The function behavior should not be dependent on the current shape of the output array. Instead, you should check whether the output array (_centers) has the fixed type (e.g. when _centers is std::vector<someT>) or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.
But we need to check actual channels() number (which shouldn't depend on current shape of array).

@alalek alalek merged commit bab86d6 into opencv:master Dec 15, 2017
@savuor savuor deleted the fix/kmeans_channels branch December 16, 2017 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

samples/cpp/kmeans.cpp: Invalid layout of "center"
4 participants