OpenCV running kmeans algorithm on an image

后端 未结 1 1211
情话喂你
情话喂你 2021-02-15 23:23

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: Assertio         


        
相关标签:
1条回答
  • 2021-02-16 00:03

    The error says all: Assertion failed (data.dims <= 2 && type == CV_32F && K > 0)

    These are very simple rules to understand, the function will work only if:

    • mImage.depth() is CV_32F

    • if mImage.dims is <= 2

    • and if K > 0. In this case, you define K as 6.

    From what you stated on the question, it seems that:

    IplImage* iplImage = cvLoadImage("C:/TestImages/rainbox_box.jpg");` 
    

    is loading the image as IPL_DEPTH_8U by default and not IPL_DEPTH_32F. This means that mImage is also IPL_DEPTH_8U, which is why your code is not working.

    0 讨论(0)
提交回复
热议问题