【问题标题】:opencv imshow and imwrite give realloc erroropencv imshow 和 imwrite 给出 realloc 错误
【发布时间】:2015-05-05 20:00:22
【问题描述】:

我有一个 PixelFormat 为 PF_BYTE_RGBA 的 OGRE::Image img 对象,我使用以下代码将其转换为 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

【问题讨论】:

  • 鉴于Qt5 相关的东西,我想说问题出在imshow。此命令是否适用于任何其他(更简单的)上下文?

标签: c++ opencv ogre


【解决方案1】:

我按照以下步骤操作,效果很好。

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

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 有关。

【讨论】:

    猜你喜欢
    • 2015-02-02
    • 1970-01-01
    • 1970-01-01
    • 2017-04-25
    • 2023-03-21
    • 1970-01-01
    • 2017-06-08
    • 1970-01-01
    • 2015-08-07
    相关资源
    最近更新 更多