Cv2.CalcHist doesn't return histogram
See original GitHub issueI calculate histogram of RGB image with this func:
static void calc_hist_bgr(Mat bgr, Mat hist)
{
int[] channels = new int[3] {0, 1, 2};
const int b_bins = 8;
const int g_bins = 8;
const int r_bins = 8;
int[] hist_size = {b_bins, g_bins, r_bins};
float[] branges = {0, 256};
float[] granges = {0, 256};
float[] rranges = {0, 256};
float[][] ranges = {branges, granges, rranges};
Mat mask = new Mat();
const int dims = 3;
Mat[] srcs = {bgr};
Cv2.CalcHist(srcs, channels, mask, hist, dims, hist_size, ranges, true, false);
}
My bgr image is: Mat [77x59xCV_8UC3,…] But i got hist image: Mat [-1x-1xCV_32FC1…]
What was i wrong ? Thanks
Sorry, i have tried to insert the code format but i couldn’t. I don’t know why
Issue Analytics
- State:
- Created 7 years ago
- Comments:5
Top Results From Across the Web
calcHist() doesn't return green histogram as expected
I am using OpenCV on Ubuntu 12.04. No fancy IDEs. Just compiling and running from the command-line. This is my code for calculating...
Read more >cv2.calcHist - sum of histogram does not equal pixel count
I just observed a strange behaviour of cv2.calcHist. When calculating the sum of all bin-values it sometimes does not add up to the...
Read more >Get value from histogram - vision
I have a lot of images to threshold. The correct threshold seems to be where the histogram of the image dies out a...
Read more >3 : 2D Histograms
2D Histogram in OpenCV. It is quite simple and calculated using the same function, cv.calcHist(). For color histograms, we need to convert the...
Read more >Python OpenCV - cv2.calcHist method
calcHist () function to calculate the image histograms. ... Return: It returns an array of histogram points of dtype float32.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You might want to look at HistSample.cs and KAZESample2.cs for tips. When I had to use it, I modeled mine off HistSample.cs (below) and it worked fine.
It did not work !
Just simple sample:
Mat src = new Mat(@"C:\desert.jpg", ImreadModes.Color); Mat hist = new Mat(); int[] hdims = {256,256,256}; Rangef[] ranges = {new Rangef(0,256),new Rangef(0,256),new Rangef(0,256) }; Cv2.CalcHist(new Mat[]{src}, new int[]{0,1,2}, null, hist, 3, hdims, ranges);
I got the hist with size of (-1,-1);But if with one channel, it works:
Mat src = new Mat(@"C:\desert.jpg"); Mat hist = new Mat(); int[] hdims = {256}; Rangef[] ranges = {new Rangef(0,256),}; Cv2.CalcHist(new Mat[]{src}, new int[]{0}, null, hist, 1, hdims, ranges);
I got the hist with size of (256,1)