Ask Your Question

it_master's profile - activity

2020-11-07 12:49:49 -0600 received badge  Student (source)
2019-12-11 04:41:05 -0600 commented question How to associate a color value to a number?

Alright, I'm really sorry for this. (Also, can you go back to the Dominant color thread, it seems that the reshape didn

2019-12-11 04:26:17 -0600 commented answer Finding Dominant colors in an image in c++

I still need to know as to how do I exclude a articular color

2019-12-11 03:44:29 -0600 commented question How to associate a color value to a number?

I wasn't able to get the answer, so yes. Then there's the fact that I wasn't able to respond in time.

2019-12-11 03:44:11 -0600 commented question How to associate a color value to a number?

I wasn't able to get the answer, so yes.

2019-12-11 02:21:36 -0600 asked a question How to associate a color value to a number?

How to associate a color value to a number? I'm creating a module that would associate the average color value to a valu

2019-12-11 02:10:51 -0600 commented question How to associate a Mat color value to an int/float value?

Can anyone answer this question?

2019-12-11 02:01:48 -0600 received badge  Enthusiast
2019-12-09 07:14:25 -0600 commented question How to associate a Mat color value to an int/float value?

Yeah, I know. And I'm really sorry about that. Speaking of which, can anyone help me in this regard? The last got who an

2019-12-09 04:35:14 -0600 asked a question How to associate a Mat color value to an int/float value?

How to associate a Mat color value to an int/float value? I'm trying to create a color range module where if the average

2019-12-09 01:06:59 -0600 commented answer How to associate a Mat color value to an int/float value?

And how would this work, I suppose?

2019-12-08 23:14:18 -0600 commented question How to associate a Mat color value to an int/float value?

I'm lost in this... Still new with these kind of things.

2019-12-07 03:08:37 -0600 edited question How to associate a Mat color value to an int/float value?

How to associate color to a value? I'm trying to create a color range module where if the average color is of a particul

2019-12-07 03:07:58 -0600 asked a question How to associate a Mat color value to an int/float value?

How to associate color to a value? I'm trying to create a color range module where if the average color is of a particul

2019-12-06 04:13:26 -0600 commented answer Finding Dominant colors in an image in c++

I think I got it. Thanks a bunch! Last minor thing, how do I exclude a particular color from the array, for example, a

2019-12-06 04:13:18 -0600 commented answer Finding Dominant colors in an image in c++

I think I got it. Thanks a bunch! Last minor thing, how do I exclude a particular color from the array, for example, a b

2019-12-06 04:11:41 -0600 commented answer Finding Dominant colors in an image in c++

I think I got it. Thanks a bunch!

2019-12-06 04:11:15 -0600 received badge  Supporter (source)
2019-12-06 04:11:13 -0600 marked best answer Finding Dominant colors in an image in c++

I have been scouring the net for quite some time in regards to finding the same answer, but in c++. So far, nothing yielded any usable sample codes or guides in regards to this topic. And the only thing I have found for this subject is through an old forum answer just nearly 2 years ago (See this for reference), but the result from that was still erroneous.

With that being said, I have to ask.

How to find dominant colors in OpenCV in C++?

Edit: I have managed to make the program from the reference work, but all I'm left is a simplified image. It may make things easier, but I'm still looking for a way to find the dominant color in the image. (Akin similar to the resulting cluster color bar displayed in the sample program in this site: OpenCV and Python K-Means Color Clustering

Here is the snippet code I'm currently using for the program:

Mat ocv = resulthsv; //resulthsv is the image made after converting to hsv and masking.

    // convert to float & reshape to a [3 x W*H] Mat 
    //  (so every pixel is on a row of it's own)
Mat data;
ocv.convertTo(data, CV_32F);
data = data.reshape(1, data.total());

// do kmeans
Mat labels, centers;
kmeans(data, 8, labels, TermCriteria(CV_TERMCRIT_ITER, 10, 1.0), 3,
    KMEANS_PP_CENTERS, centers);

// reshape both to a single row of Vec3f pixels:
centers = centers.reshape(3, centers.rows);
data = data.reshape(3, data.rows);

// replace pixel values with their center value:
Vec3f *p = data.ptr<Vec3f>();
for (size_t i = 0; i<data.rows; i++) {
    int center_id = labels.at<int>(i);
    p[i] = centers.at<Vec3f>(center_id);
}

// back to 2d, and uchar:
ocv = data.reshape(3, ocv.rows);
ocv.convertTo(ocv, CV_8U);

imshow(windowName, resulthsv); 
imwrite("t1.png", resulthsv);
imshow("Dominant color", ocv);
waitKey(0); 
destroyWindow(windowName); 

return 0;

Here is the initial image (after masking):

image description

And here is the image after K-means:

image description

2019-12-06 04:11:13 -0600 received badge  Scholar (source)
2019-12-06 03:45:04 -0600 commented answer Finding Dominant colors in an image in c++

For some reason, I can only see black and white after the code execution.

2019-12-06 03:05:03 -0600 commented question Finding Dominant colors in an image in c++

After the display of the 3 most dominant colors in the window, that's about it. probably save those colors as images? (t

2019-12-06 03:04:46 -0600 commented question Finding Dominant colors in an image in c++

After the display of the 3 most dominant colors in the window, that's about it. probably save those colors? (that might

2019-12-06 03:00:40 -0600 commented question Finding Dominant colors in an image in c++

Yeah, that seems to be the case. And I'm just looking for just the 3 most dominant colors in the image, so hopefully it

2019-12-06 03:00:30 -0600 commented question Finding Dominant colors in an image in c++

Yeah, that seems to be the case. And I'm just looking for just the 3 most dominant colors in the image, so hopefully it

2019-12-06 02:59:07 -0600 commented question Finding Dominant colors in an image in c++

Yeah, that seems to be the case. And I'm just looking for just the 3 most dominant colors in the image, so hopefully it

2019-12-06 02:58:29 -0600 commented question Finding Dominant colors in an image in c++

Yeah, that seems to be the case. And I'm just looking for just the 3 most dominant colors in the image, so hopefully it

2019-12-06 02:57:45 -0600 commented question Finding Dominant colors in an image in c++

Yeah, that seems to be the case. And I'm just looking for just the 3 most dominant colors in the image, so hopefully it

2019-12-06 02:56:26 -0600 commented question Finding Dominant colors in an image in c++

Yeah, that seems to be the case. And I'm just looking for just the 2 most dominant colors in the image, so hopefully it

2019-12-06 02:53:35 -0600 commented question Finding Dominant colors in an image in c++

I have edited the question.

2019-12-06 02:53:14 -0600 edited question Finding Dominant colors in an image in c++

Finding Dominant colors in an image in c++ I have been scouring the net for quite some time in regards to finding the sa

2019-12-06 02:51:05 -0600 edited question Finding Dominant colors in an image in c++

Finding Dominant colors in an image in c++ I have been scouring the net for quite some time in regards to finding the sa

2019-12-06 02:50:23 -0600 edited question Finding Dominant colors in an image in c++

Finding Dominant colors in an image in c++ I have been scouring the net for quite some time in regards to finding the sa

2019-12-06 02:46:13 -0600 edited question Finding Dominant colors in an image in c++

Finding Dominant colors in an image in c++ I have been scouring the net for quite some time in regards to finding the sa

2019-12-06 02:28:36 -0600 received badge  Editor (source)
2019-12-06 02:28:36 -0600 edited question Finding Dominant colors in an image in c++

Finding Dominant colors in an image in c++ I have been scouring the net for quite some time in regards to finding the sa

2019-12-06 02:15:02 -0600 received badge  Organizer (source)