{"id":325,"date":"2022-08-30T14:59:28","date_gmt":"2022-08-30T14:59:28","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/06\/opencv-running-kmeans-algorithm-on-an-image-collection-of-common-programming-errors\/"},"modified":"2022-08-30T14:59:28","modified_gmt":"2022-08-30T14:59:28","slug":"opencv-running-kmeans-algorithm-on-an-image-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/opencv-running-kmeans-algorithm-on-an-image-collection-of-common-programming-errors\/","title":{"rendered":"OpenCV running kmeans algorithm on an image-Collection of common programming errors"},"content":{"rendered":"<p>I am trying to run kmeans on a 3 channel color image, but every time I try to run the function it seems to crash with the following error:<\/p>\n<pre><code>OpenCV Error: Assertion failed (data.dims  0) in unknown function, file ..\\..\\..\\OpenCV-2.3.0\\modules\\core\\src\\matrix.cpp, line 2271\n<\/code><\/pre>\n<p>I&#8217;ve included the code below with some comments to help specify what is being passed in. Any help is greatly appreciated.<\/p>\n<pre><code>\/\/ Load in an image\n\/\/ Depth: 8, Channels: 3\nIplImage* iplImage = cvLoadImage(\"C:\/TestImages\/rainbox_box.jpg\");\n\n\/\/ Create a matrix to the image\ncv::Mat mImage = cv::Mat(iplImage);\n\n\/\/ Create a single channel image to create our labels needed\nIplImage* iplLabels = cvCreateImage(cvGetSize(iplImage), iplImage-&gt;depth, 1);\n\n\/\/ Convert the image to grayscale\ncvCvtColor(iplImage, iplLabels, CV_RGB2GRAY);\n\n\/\/ Create the matrix for the labels\ncv::Mat mLabels = cv::Mat(iplLabels);\n\n\/\/ Create the labels\nint rows = mLabels.total();\nint cols = 1;\ncv::Mat list(rows, cols, mLabels .type());\nuchar* src;\nuchar* dest = list.ptr(0);\nfor(int i=0; i<\/code><\/pre>\n<p id=\"rop\"><small>Originally posted 2013-11-06 03:07:56. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I am trying to run kmeans on a 3 channel color image, but every time I try to run the function it seems to crash with the following error: OpenCV Error: Assertion failed (data.dims 0) in unknown function, file ..\\..\\..\\OpenCV-2.3.0\\modules\\core\\src\\matrix.cpp, line 2271 I&#8217;ve included the code below with some comments to help specify what is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-325","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/325","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=325"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/325\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=325"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=325"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=325"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}