1

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

> *** 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)

我是一个有指针和内存分配的新手,所以任何帮助都将不胜感激。提前致谢。

4

1 回答 1

0

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

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

并且分段错误消失了。

(注意:由于此处的答案,我找到了解决方案:OpenCV/C++ - 如何释放指针

于 2013-07-01T12:31:57.533 回答