gpt4 book ai didi

c++ - OpenCV 免费(): invalid pointer:

转载 作者:太空宇宙 更新时间:2023-11-04 14:05:05 24 4
gpt4 key购买 nike

我在运行从文件中读取一些数据、提取图像特征并使用一组预训练分类器预测结果的应用程序时遇到下一个错误:

> *** glibc detected *** ./SVMread: free(): invalid pointer: 0xbfeb2670 ***
> ======= Backtrace: ========= /lib/i386-linux-gnu/libc.so.6(+0x75ee2)[0xb5fe8ee2]
> /usr/lib/i386-linux-gnu/libstdc++.so.6(_ZdlPv+0x1f)[0xb61e451f]
> ./SVMread(_ZN2cv17FlannBasedMatcherD0Ev+0x1c)[0x804b214]
> ./SVMread[0x804ca96] ./SVMread[0x804c0e1]
> ./SVMread(_ZN2cv3PtrINS_17DescriptorMatcherEED1Ev+0x11)[0x804b6e9]
> ./SVMread[0x804a8cc]
> /lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf3)[0xb5f8c4d3]
> ./SVMread[0x8049ef1]
> ======= Memory map: ======== 08048000-08050000 r-xp 00000000 00:14 101213 /home/srt/OpenCV-2.4.2/samples/cpp/SVMread
> 08050000-08051000 r--p 00007000 00:14 101213
> /home/srt/OpenCV-2.4.2/samples/cpp/SVMread 08051000-08052000 rw-p
> 00008000 00:14 101213 /home/srt/OpenCV-2.4.2/samples/cpp/SVMread
> ...

我认为冲突部分在代码的下一部分中,但我真的无法在网络上或 OpenCV 文档中找到解决方案。

     SurfDescriptorExtractor extractor1;
Ptr<DescriptorExtractor> extractor = &extractor1;
FlannBasedMatcher matcher1;
Ptr<DescriptorMatcher> matcher = &matcher1;

BOWImgDescriptorExtractor bowide(extractor,matcher);

或在:

CvFileStorage* storage = cvOpenFileStorage( "svm1.yml", 0, CV_STORAGE_READ );

const char * c;
string clase;
CvFileNode* cFN;

for (unsigned int i = 0; i<Vclases.size(); i++) {
clase = Vclases[i];
c = (clase).c_str();
cFN = cvGetFileNodeByName( storage , 0, c );
cout << "reading " << clase << endl;
classes_classifiers[clase].read(storage, cFN );

}

编辑:valgrind 输出确认存在问题:

CvFileStorage* storage = cvOpenFileStorage( "svm1.yml", 0, CV_STORAGE_READ );

瓦尔格林德:

> Conditional jump or move depends on uninitialised value(s)
> ==23398== at 0x56585C0: ____strtod_l_internal (strtod_l.c:1659)
> ==23398== by 0x5653FAE: strtod (strtod.c:70)
> ==23398== by 0x41425B1: icv_strtod(CvFileStorage*, char*, char**) (in /usr/local/lib/libopencv_core.so.2.4.2)
> ==23398== by 0x415875F: icvYMLParseValue(CvFileStorage*, char*, CvFileNode*, int, int) (in /usr/local/lib/libopencv_core.so.2.4.2)
> ==23398== by 0x804A377: main (SVMread.cpp:64)
> ==23398== Uninitialised value was created by a stack allocation
> ==23398== at 0x56575E4: ____strtod_l_internal (strtod_l.c:424)

我是指针和内存分配方面的新手,因此我们将不胜感激。提前致谢。

最佳答案

我找到了解决方案:问题是 cv:Ptr 与动态分配的对象一起工作,这就是为什么在尝试释放通过引用初始化的指针时发生错误的原因。所以,正确的指针声明是:

 Ptr<DescriptorMatcher > matcher = new FlannBasedMatcher;
Ptr<DescriptorExtractor > extractor(new SurfDescriptorExtractor());

段错误消失了。

(注:感谢这里的回答,我找到了解决方案:OpenCV/C++ - How to free pointers

关于c++ - OpenCV 免费(): invalid pointer:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17389471/

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