Question about histogram output.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Question about histogram output.

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    21

    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?
    Code:
    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;
    }

  2. #2
    Join Date
    Apr 1999
    Posts
    27,418

    Re: Question about histogram output.

    Quote Originally Posted by nihad View Post
    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?
    Code:
    vector<double>three_dimensional_shape_retreival_Hough_Transform:: histogram_creation(vector<double> input_vector)
    Pass vectors by reference or const-reference, not by value.
    Code:
    vector<double>three_dimensional_shape_retreival_Hough_Transform:: histogram_creation(vector<double>&input_vector)
    As to fixing your problem, maybe it is because you passed the vector by value instead of by reference. Otherwise you need to post your entire application, including data that is used. For example, no one knows what a "Mat" is, or what "calcHist" does.

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Feb 2013
    Posts
    21

    Re: Question about histogram output.

    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)

  4. #4
    Join Date
    Apr 1999
    Posts
    27,418

    Re: Question about histogram output.

    Quote Originally Posted by nihad View Post
    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're still passing vectors by value when I stated they should be passed by reference.

    Second, why is that a solution? What difference did it make from making it a vector<float> instead of a vector<double>? You need to explain why making that coding change fixed the problem.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; March 17th, 2013 at 02:47 AM.

  5. #5
    Join Date
    Feb 2013
    Posts
    21

    Re: Question about histogram output.

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center