Ask Your Question

# How to use calcHist

I am sorry to ask such simple question here,but the documentation fool me.I want to use the calcHist to deal with 2 images.This is my code

#include <opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;

int main(){
Mat fruits=imread("fruits.jpg",IMREAD_GRAYSCALE), lena= imread("lena.jpg", IMREAD_GRAYSCALE);
Mat inputs[] = { fruits,lena }, hist;
float range[] = { 0,256 };
float * histRange = {range};
int histSize = 255, channels = 0;

calcHist(*inputs, 2, &channels, Mat(), hist, 1, &histSize, *histRange);
return 0;
}


But it cannot be compile by my vs2015.Anybody can help to tunning?

edit retag close merge delete

## Comments

1

apart from the syntax problems, you probably should calculate a seperate histogram per (single channel) image for whatever you're doing later.

( 2017-09-03 00:14:12 -0500 )edit

@berak I know how to calculate one image,but I want to calculate two or more images such as my question.

( 2017-09-03 00:16:40 -0500 )edit

to achieve what ? (if may ask)

( 2017-09-03 00:29:45 -0500 )edit

@berak To learning how to use calcHist.Because the second parameter show it can calculate two or more images

( 2017-09-03 00:32:46 -0500 )edit

ok, ok. still, your use-case looks like a silly idea.

( 2017-09-03 00:49:43 -0500 )edit

## 1 answer

Sort by » oldest newest most voted

what you're trying here still does not make any sense to me, anyway, here's the corrected code:

Mat inputs[] = { fruits,lena }, hist;
float range[] = { 0,256 };
const float * histRange[] = {range,range}; // one per image/channel
int histSize[] = {255};
int channels[] = {0,1}; //one per image (count up)

calcHist(inputs, 2, channels, Mat(), hist,2, histSize, histRange);

more

## Comments

Thanks..and is there any simple method can show the hist?I saw some code use Line.little complecated..

( 2017-09-03 00:51:13 -0500 )edit

yes, it is complicated, and you made it even more so !

here's the drawingcode

( 2017-09-03 00:57:15 -0500 )edit

Official site

GitHub

Wiki

Documentation

## Stats

Asked: 2017-09-02 07:56:35 -0500

Seen: 597 times

Last updated: Sep 03 '17