0

I am trying to compute HSV histogram of frames of a Histogram . My code gives Assertion failed error. Error is in function hsv_histogram. If i do it for 2 dimensional histogram it works perfectly for me but when i add third dimension value it gives me assertion failed error.

    // newproject.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include "highgui.h"
#include <stdio.h>
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
#include <conio.h>
#include <opencv2/imgproc/imgproc.hpp>  // Gaussian Blur
#include <opencv2/core/core.hpp>        // Basic OpenCV structures (cv::Mat, Scalar)
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <conio.h>

using namespace cv;
using namespace std;

class frameprocessing{

Mat hsv_base;
Mat hist_base;

public:
    void hsv_histogram(Mat Frame)
    {
        cvtColor( Frame, hsv_base, CV_BGR2HSV );
        int h_bins = 50; 
        int s_bins = 32;
        int v_bins = 10;

        int histSize[] = { h_bins, s_bins };

        float h_ranges[] = { 0, 256 };
        float s_ranges[] = { 0, 180 };
        float v_ranges[] = { 0, 256 };

        const float* ranges[] = { h_ranges, s_ranges ,v_ranges};
        int channels[] = { 0, 1 ,2};
        calcHist( &hsv_base, 1, channels, Mat(), hist_base, 3, histSize, ranges, true, false );
    }
};

class video{    

    Mat frame;
    string filename;
    double dWidth;
    double dHeight;

public:
    video()
    {

    }

    video(string videoname)
    {
        vector<Mat> videoframes;
        filename = videoname;
        VideoCapture capture(filename); 

        if( !capture.isOpened() )
        {
            exit(0);
        }

        dWidth   = capture.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
        dHeight = capture.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video
        frameprocessing obj;

        for( ; ; )
        {
            capture >> frame;
            if(frame.empty())
                break;

    //      Mat tmp=frame.clone();
            obj.hsv_histogram(frame);
    //      videoframes.push_back(tmp);
        }
        //displayvideo(videoframes);
        //writer(videoframes);
    }
};

int _tmain(int argc, _TCHAR* argv[])
{
    video obj("video.avi");
}
1
  • Your code working fine in my PC. Commented Nov 19, 2013 at 10:08

1 Answer 1

1

May be you forgot to set v hist size?

I suppose that

int histSize[] = { h_bins, s_bins };

should be something like

int histSize[] = { h_bins, s_bins, v_bins };
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.