Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ OpenCV矩阵构造函数分段错误_C++_Opencv_Histogram - Fatal编程技术网

C++ OpenCV矩阵构造函数分段错误

C++ OpenCV矩阵构造函数分段错误,c++,opencv,histogram,C++,Opencv,Histogram,我在执行时遇到了一个分段错误 cv::Mat hist=cv::Mat(1,no_patterns,CV_32SC1,cv::Scalar(0)); 其中无模式=256 但是,它不会在函数的第一次执行时崩溃,而是在第二次执行时崩溃 如果重要的话,getHistFromLBP和histAVG在它们的类中被声明为静态的 背景: getHistFromLBP函数 cv::Mat LBP::getHistFromLBP(const cv::Mat& lbp_mat,unsigned no_pa

我在执行时遇到了一个分段错误

cv::Mat hist=cv::Mat(1,no_patterns,CV_32SC1,cv::Scalar(0));
其中无模式=256

但是,它不会在函数的第一次执行时崩溃,而是在第二次执行时崩溃

如果重要的话,getHistFromLBP和histAVG在它们的类中被声明为静态的

背景:

getHistFromLBP函数

cv::Mat LBP::getHistFromLBP(const cv::Mat& lbp_mat,unsigned no_patterns, bool normed)
{   
    // It crashes here 
    cv::Mat hist=cv::Mat(1,no_patterns,CV_32SC1,cv::Scalar(0));


for (unsigned i=0;i<no_patterns;i++)
    hist.at<int32_t>(1,i)=0;

for (int i=0;i<lbp_mat.rows;i++)
    for (int j=0;j<lbp_mat.cols;j++)
    {
        uint32_t bin;

        switch (lbp_mat.type())
        {
            case CV_8UC1: bin=static_cast<uint32_t>(lbp_mat.at<uint8_t>(i,j)); break;
            case CV_16UC1: bin=static_cast<uint32_t>(lbp_mat.at<uint16_t>(i,j)); break;
            case CV_32SC1: bin=static_cast<uint32_t>(lbp_mat.at<int32_t>(i,j)); break;
        }

        hist.at<uint32_t>(1,bin)+=1;
    }

if (normed)
{
    unsigned long sum=0;
    for (int i=0;i<hist.cols;i++)
    {
        sum += hist.at<uint32_t>(1, i);
    }
    std::cout << "Found sum = " << sum << std::endl;
    for (int i=0;i<hist.cols;i++)
    {
        std::cout<< "Working on normalizing i= " << i << std::endl;
        std::cout << "Hist(i) = " << hist.at<uint32_t>(1,i) << std::endl;
        hist.at<float>(i) = hist.at<uint32_t>(1, i) * 1.0 / (sum + std::numeric_limits<float>::epsilon());

    }
}


return hist;
}
cv::Mat LBP::getHistFromLBP(const cv::Mat&LBP_Mat,无符号无符号模式,bool normald)
{   
//它在这里坠毁了
cv::Mat hist=cv::Mat(1,无模式,cv_32SC1,cv::Scalar(0));

对于(未签名的i=0;iOpenCV版本?编译器?调试和发布?x64/x86?IDE?显示包含和链接libs@Miki根据stacktrace的说法,我猜是:x64。@Miki添加了链接库和版本。笔记本电脑是基于X86_64 Debian的linux,IDE不应该是相关的,但我使用了sublime,现在切换到了CLion。库的文件夹?-L可选一般来说是I“首先,使用工具查找内存损坏。选项有clang的地址消毒剂(asan)或valgrind。(clang还有其他消毒剂。)OpenCV版本?编译器?调试和发布?x64/x86?IDE?显示包含和链接libs@Miki根据stacktrace的说法,我猜是:x64。@Miki添加了链接库和版本。笔记本电脑是基于X86_64 Debian的linux,IDE应该不相关,但我使用的升华现在切换到了CLion。库的文件夹?-L通常我会从usi开始ng是一个查找内存损坏的工具。选项有clang的地址消毒剂(asan)或valgrind。(clang还有其他消毒剂。)
if (sliding_window_frames.window_full())
{
    // We can calculate the AFF hist and the CF-AFF Chi Square distance
    std::vector<cv::Mat>* cf_mat=sliding_window_frames.getCFMat();
    std::vector<cv::Mat>* front_mat=sliding_window_frames.getFrontMat();
    std::vector<cv::Mat>* back_mat=sliding_window_frames.getBackMat();

    std::vector<double> tmp_diffs;
    for (unsigned i=0;i<cf_mat->size();i++)
    {
        std::cout << "Current block analyzed is: " << i << std::endl;
        // This call of getHistFromLBP executes OK
        cv::Mat histCF=lbp_extractor->getHistFromLBP((*cf_mat)[i],256,normed_histograms);
        // This call fails with a segmentation fault
        cv::Mat histFront=lbp_extractor->getHistFromLBP((*front_mat)[i],256,normed_histograms);
        cv::Mat histBack=lbp_extractor->getHistFromLBP((*back_mat)[i],256,normed_histograms);
        std::cout << "Found Histograms " << std::endl;
        cv::Mat histAFF=lbp_extractor->histAvg(histFront,histBack,normed_histograms);
        std::cout << "Found Hist AFF " << std::endl;
        double chisquared=lbp_extractor->getChiSquaredDistanceFromHist(histCF,histAFF,normed_histograms);
        std::cout << "Found chi squared " << std::endl;
        tmp_diffs.push_back(chisquared);
        std::cout << "Pushed chi squared " << std::endl;
    }
    ...
}
#0  0x00007fffefc1bfff in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1  0x00007fffefc1d42a in __GI_abort () at abort.c:89
#2  0x00007fffefc59c00 in __libc_message (do_abort=do_abort@entry=2, fmt=fmt@entry=0x7fffefd4ed78 "*** Error in `%s': %s: 0x%s ***\n")
at ../sysdeps/posix/libc_fatal.c:175
#3  0x00007fffefc5ffc6 in malloc_printerr (action=3, str=0x7fffefd4b8be "corrupted size vs. prev_size", ptr=<optimized out>, ar_ptr=<optimized out>)
at malloc.c:5049
#4  0x00007fffefc603b8 in malloc_consolidate (av=av@entry=0x7fffeff80b00 <main_arena>) at malloc.c:4221
#5  0x00007fffefc61dfa in _int_malloc (av=av@entry=0x7fffeff80b00 <main_arena>, bytes=bytes@entry=1136) at malloc.c:3488
#6  0x00007fffefc6293e in _int_memalign (av=av@entry=0x7fffeff80b00 <main_arena>, alignment=alignment@entry=64, bytes=bytes@entry=1024)
at malloc.c:4459
#7  0x00007fffefc6435f in _mid_memalign (alignment=64, bytes=1024, address=<optimized out>) at malloc.c:3158
#8  0x00007fffefc65fef in __posix_memalign (memptr=0x7fffffffbd38, alignment=<optimized out>, size=<optimized out>) at malloc.c:5071
#9  0x00007ffff57e967b in cv::fastMalloc(unsigned long) () at /usr/local/lib/libopencv_core.so.3.3
#10 0x00007ffff5930ae6 in cv::Mat::create(int, int const*, int) () at /usr/local/lib/libopencv_core.so.3.3
#11 0x000055555556995e in cv::Mat::create(int, int, int) (this=0x7fffffffbff0, _rows=1, _cols=256, _type=4)
at /usr/local/include/opencv2/core/mat.inl.hpp:784
#12 0x00005555555698b5 in cv::Mat::Mat(int, int, int, cv::Scalar_<double> const&) (this=0x7fffffffbff0, _rows=1, _cols=256, _type=4, _s=...)
at /usr/local/include/opencv2/core/mat.inl.hpp:420
#13 0x0000555555568ccf in LBP::getHistFromLBP(cv::Mat const&, unsigned int, bool) (lbp_mat=..., no_patterns=256, normed=true) at ../src/lbp.cpp:162
#14 0x0000555555572760 in RM_Analyzer::addNewFrame(cv::Mat, bool) (this=0x7fffffffc490, img=..., is_lbp_img=false) at ../src/rm_analyzer.cpp:86
#15 0x00005555555721ff in RM_Analyzer::analyzeVid() (this=0x7fffffffc490) at ../src/rm_analyzer.cpp:25
#16 0x0000555555577241 in main(int, char const**) (argc=15, argv=0x7fffffffe0b8) at ../bin_src/main.cpp:198