Question about histogram output.

I have following code to create histogram, but it gave wrong output. In the program input_vector read 100 double numbers. I want to create a histogram with bin size=5. Output is [0;0;0;0;0]. Can anybody help me to figure out the problem?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
vector<double>three_dimensional_shape_retreival_Hough_Transform:: histogram_creation(vector<double> input_vector)
{

    long int i;
    long int j;

    Mat histogram_input(input_vector);

    cout<<"Histogram Input Matrix:"<<histogram_input<<endl;

    int histSize =5;

    float max_distance= *max_element(input_vector.begin(), input_vector.end());
    float min_distance= *min_element(input_vector.begin(), input_vector.end());

    cout<<"Max Element:"<<max_distance<<" "<<"Min Element:"<<min_distance<<endl;

    float range[] = { min_distance,max_distance};
    const float* histRange = { range };

    bool uniform = true;
    bool accumulate = false;

    Mat histogram_output;

    calcHist(&histogram_input,1,0, Mat(), histogram_output,1,&histSize,&histRange,uniform,accumulate);

    cout<<"Histogram Output Matrix:"<<histogram_output<<endl;
}
The problem comes from calcHist or your values (are you sure the vector is not empty ?).
Besides, this function should not even compile because its return type is vector<double> but you don't return anything.
Last edited on
Here is the solution:
Function prototype would be
vector<double>three_dimensional_shape_retreival_Hough_Transform:: histogram_creation(vector<float> input_vector) instead of vector<double>three_dimensional_shape_retreival_Hough_Transform:: histogram_creation(vector<double> input_vector)
You didn't understand.
Your function histogram_creation is supposed to return a vector<double> but doesn't return anything.
I am using OpenCV library.
"images – Source arrays. They all should have the same depth, CV_8U or CV_32F"

so vector<double> is not a valid input. vector<float> should do.
Topic archived. No new replies allowed.