Reputation: 31
I'm trying to calculate an histogram from an image with OpenCV for C# (EmguCV).
This is my code:
VectorOfMat bgr_planes = new VectorOfMat();
CvInvoke.Split(myImage, bgr_planes);
int[] dim = new int[] { 0 };
int[] histSize = new int[] { 256 };
float[] range = new float[] { 0f, 255f };
bool accumulate = false;
Mat b_hist = new Mat();
Mat g_hist = new Mat();
Mat r_hist = new Mat();
CvInvoke.CalcHist(bgr_planes, dim, new Mat(), b_hist, histSize, range, accumulate);
CvInvoke.CalcHist(bgr_planes, dim, new Mat(), g_hist, histSize, range, accumulate);
CvInvoke.CalcHist(bgr_planes, dim, new Mat(), r_hist, histSize, range, accumulate);`
But I do not get Data b_hist
, g_hist
and r_hist
. I can't address the specific channels bgr_planes[0]
, because those are of type Mat
and it throws an error.
How can I adjust the parameters dim
, histSize
and range
to get a color histogram?
Thank you so much for your help!
Upvotes: 0
Views: 1563
Reputation: 31
I solved it myself (of course right after posting the question...):
Here is what I changed:
Mat x = bgr_planes[0];
Mat[] bVals = new Mat[1] { x };
VectorOfMat colorChannelB = new VectorOfMat();
colorChannelB.Push(bVals);
This separates one single color channel of the bgr_planes
. In VectorOfMat colorChannelB
is now only one color channel. Do that separately for every channel and keep the parameters.
Upvotes: 0