繁体   English   中英

断言OpenCV代码失败的错误

[英]Assertion failed error in opencv code

我正在尝试计算直方图的帧的HSV直方图。 我的代码给出断言失败错误。 函数hsv_histogram中存在错误。 如果我对二维直方图执行此操作,则对我来说效果很好,但是当我添加三维值时,它会给我断言失败错误。

    // 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");
}

可能您忘记设置历史尺寸吗?

我想

int histSize[] = { h_bins, s_bins };

应该是这样的

int histSize[] = { h_bins, s_bins, v_bins };

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM