【发布时间】: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。此命令是否适用于任何其他(更简单的)上下文?