From 601b7d1dd3a3ec9e8af5df461d43632d98ed3a7a Mon Sep 17 00:00:00 2001 From: Nghia Ho Date: Mon, 6 Jan 2014 20:19:07 +1100 Subject: [PATCH 1/2] Fixed a valgrind 'Conditional jump or move depends on uninitialised value(s)' on cv::kmeans(...). The original code used points(sampleCount, 1, CV_32FC2), which confused generateCentersPP into thinking it is a 1 dimensional center, instead of 2. As a result it would set only the x variable and leave y unitialised. --- samples/cpp/kmeans.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/cpp/kmeans.cpp b/samples/cpp/kmeans.cpp index 97de6a0a48..b742112059 100644 --- a/samples/cpp/kmeans.cpp +++ b/samples/cpp/kmeans.cpp @@ -33,7 +33,7 @@ int main( int /*argc*/, char** /*argv*/ ) { int k, clusterCount = rng.uniform(2, MAX_CLUSTERS+1); int i, sampleCount = rng.uniform(1, 1001); - Mat points(sampleCount, 1, CV_32FC2), labels; + Mat points(sampleCount, 2, CV_32F), labels; clusterCount = MIN(clusterCount, sampleCount); Mat centers(clusterCount, 1, points.type()); From bf4994554df10e9c070da5490b5c274fa152fe84 Mon Sep 17 00:00:00 2001 From: Nghia Ho Date: Thu, 9 Jan 2014 21:04:17 +1100 Subject: [PATCH 2/2] Removed unecessary initialisation of Mat centers. --- samples/cpp/kmeans.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/cpp/kmeans.cpp b/samples/cpp/kmeans.cpp index b742112059..19e998379d 100644 --- a/samples/cpp/kmeans.cpp +++ b/samples/cpp/kmeans.cpp @@ -36,7 +36,7 @@ int main( int /*argc*/, char** /*argv*/ ) Mat points(sampleCount, 2, CV_32F), labels; clusterCount = MIN(clusterCount, sampleCount); - Mat centers(clusterCount, 1, points.type()); + Mat centers; /* generate random sample from multigaussian distribution */ for( k = 0; k < clusterCount; k++ )