Ask Your Question
-1

How to use calcHist

asked 2017-09-02 07:56:35 -0600

yode gravatar image

updated 2017-09-02 08:31:11 -0600

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 flag offensive 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.

berak gravatar imageberak ( 2017-09-03 00:14:12 -0600 )edit

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

yode gravatar imageyode ( 2017-09-03 00:16:40 -0600 )edit

to achieve what ? (if may ask)

berak gravatar imageberak ( 2017-09-03 00:29:45 -0600 )edit

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

yode gravatar imageyode ( 2017-09-03 00:32:46 -0600 )edit

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

berak gravatar imageberak ( 2017-09-03 00:49:43 -0600 )edit

1 answer

Sort by » oldest newest most voted
2

answered 2017-09-03 00:45:13 -0600

berak gravatar image

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);
edit flag offensive delete link more

Comments

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

yode gravatar imageyode ( 2017-09-03 00:51:13 -0600 )edit

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

here's the drawingcode

berak gravatar imageberak ( 2017-09-03 00:57:15 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 1,104 times

Last updated: Sep 03 '17