在返回Mat对象时出现使用opencv in C ++时出错

时间:2014-06-03 14:53:31

标签: c++ opencv

#include <stdio.h>
#include <vector>
#include <opencv2/opencv.hpp>

// Used for library linking
#ifdef _DEBUG
#pragma comment( lib, "opencv_core249d.lib" )
#pragma comment( lib, "opencv_highgui249d.lib" )
#pragma comment( lib, "opencv_imgproc249d.lib" )
#pragma comment( lib, "opencv_video249d.lib" )
#else
#pragma comment( lib, "opencv_core249.lib" )
#pragma comment( lib, "opencv_highgui249.lib" )
#pragma comment( lib, "opencv_imgproc249.lib" )
#pragma comment( lib, "opencv_video249.lib" )
#endif

// Using namespace
using namespace cv;
using namespace std;

class Histogram
{
    ...
};

class HistogramOfRed : public Histogram
{
private:
    const int MaximumValueOfChannel = 256;

    Mat GetImage(Mat &image)
    {
        vector<Mat> RGBImage;
        split(image, RGBImage);

        return RGBImage[2].clone();
    }

public:
    HistogramOfRed(int bin, Mat image) : Histogram(MaximumValueOfChannel, bin, GetImage(image){};
};

int main( int argc, char* argv[] )
{

    Mat image = imread( "test.jpg" );
    if ( image.empty() )
    {
        // Image is empty - image load error
        printf( "Image load error. Check directory.\n" );
        return 0;
    }

    imshow("original image", image);
    waitKey();

    HistogramOfRed histogramOfRed(256, image);

    return 0;
}

当我调用HistogramOfRed histogramOfRed(256, image)时发生错误。

下面的

是callstack

.exe!std::allocator<cv::Mat>::deallocate(cv::Mat * _Ptr, unsigned int __formal)
.exe!std::_Wrap_alloc<std::allocator<cv::Mat> >::deallocate(cv::Mat * _Ptr, unsigned int _Count)
.exe!std::vector<cv::Mat,std::allocator<cv::Mat> >::_Tidy()
.exe!std::vector<cv::Mat,std::allocator<cv::Mat> >::~vector<cv::Mat,std::allocator<cv::Mat> >()
.exe!HistogramOfRed::GetImage(cv::Mat image)
.exe!HistogramOfRed::HistogramOfRed(int bin, cv::Mat image)
.exe!main(int argc, char * * argv)

1 个答案:

答案 0 :(得分:0)

不知道这是不是真正的错误,或者你刚刚在这里复制了错误,但你在HistogramOfRed(...)构造函数中缺少右括号

HistogramOfRed(int bin, Mat image) : Histogram(MaximumValueOfChannel, bin, GetImage(image) ) {};