gpt4 book ai didi

c++ - opencv代码断言失败错误

转载 作者:行者123 更新时间:2023-11-28 07:17:05 25 4
gpt4 key购买 nike

我正在尝试计算 Histogram 帧的 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");
}

最佳答案

您可能忘记设置 v hist 大小?

我觉得

int histSize[] = { h_bins, s_bins };

应该是这样的

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

关于c++ - opencv代码断言失败错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20064823/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com