opencv imshow和imwrite给出realloc错误

时间:2015-05-05 20:00:22

标签: c++ opencv ogre

我有一个OGRE :: Image img对象,其PixelFormat是PF_BYTE_RGBA,我用以下代码将其转换为cv :: Mat

cv::Mat modelImage;
modelImage.create(img.getHeight(), img.getWidth(), CV_8UC3);

int copyChannels[6] = {0,2,1,1,2,0};
cv::Mat ogre2mat(img.getHeight(), img.getWidth(), CV_8UC4, img.getData());
mixChannels(&ogre2mat, 1, &modelImage, 1, copyChannels, 3);

现在,它可以完美地打印出值:

cout << modelImage.row(0) << endl;

但是下面的代码之一给出了realloc()错误

 imwrite("img.png",modelImage);
 imshow("img",modelImage);

另外,我从valgrind得到以下输出。看起来像Qt上的一些错误

==28986== Memcheck, a memory error detector
==28986== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==28986== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for copyright info
==28986== Command: ./run diver.urdf    
==28986== 
==28986== Invalid free() / delete / delete[] / realloc()
==28986==    at 0x4C2CE8E: realloc (in     /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==28986==    by 0xFA26E3D: QListData::realloc(int) (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1)
==28986==    by 0xFA26EF9: QListData::append(int) (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1)
==28986==    by 0xFB13D8B: ??? (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1)
==28986==    by 0xFB0FE28: qRegisterResourceData(int, unsigned char const*, unsigned char const*, unsigned char const*) (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1)
==28986==    by 0xF9B2EB2: ??? (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1)
==28986==    by 0x4010139: call_init.part.0 (dl-init.c:78)
==28986==    by 0x4010222: _dl_init (dl-init.c:36)
==28986==    by 0x4001309: ??? (in /lib/x86_64-linux-gnu/ld-2.19.so)
==28986==    by 0x1: ???
==28986==    by 0xFFEFFFE02: ???
==28986==    by 0xFFEFFFE08: ???
==28986==  Address 0xbf7e840 is 0 bytes inside data symbol "_ZN9QListData11shared_nullE"
==28986== 
terminate called after throwing an instance of 'std::bad_alloc'
what():  std::bad_alloc
==28986== 
==28986== HEAP SUMMARY:
==28986==     in use at exit: 73,525 bytes in 636 blocks
==28986==   total heap usage: 1,557 allocs, 921 frees, 117,760 bytes allocated
==28986== 
==28986== LEAK SUMMARY:
==28986==    definitely lost: 0 bytes in 0 blocks
==28986==    indirectly lost: 0 bytes in 0 blocks
==28986==      possibly lost: 14,005 bytes in 300 blocks
==28986==    still reachable: 59,520 bytes in 336 blocks
==28986==         suppressed: 0 bytes in 0 blocks
==28986== Rerun with --leak-check=full to see details of leaked memory
==28986== 
==28986== For counts of detected and suppressed errors, rerun with: -v
==28986== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
Aborted

1 个答案:

答案 0 :(得分:0)

我按照以下步骤进行操作。

1)我卸载了opencv库。

2)下载版本2.4.10

3)安装依赖项,如

所示

http://robotics.jacobs-university.de/TMP/kaustubh/vision/install_opencv_latest.txt

3)然后遵循http://www.aichengxu.com/view/52596中描述的两种方法(中文版,谷歌翻译将有所帮助)。我用

更新了Gstreamer
sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev 

但它不起作用。

5)第二种方法有效。所以我设置了

WITH_GSTREAMER_0_10=OFF 

WITH_QT=OFF

in

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=OFF -D WITH_OPENGL=ON  WITH_GSTREAMER_0_10 = OFF ..

然后,

make && make install

基本上,错误与Qt有关。