簡體   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