[英]opencv imshow and imwrite give realloc error
我有一個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)我卸載了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有關。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.