我有一个最简单的C ++应用程序,可以使用OpenCV显示照片:
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
int main(int argc, char** argv) {
cv::Mat img = cv::imread("photo.jpg");
cv::imshow("image", img);
cv::waitKey();
return 0;
}
...然后我在Linux,gcc 7.2.0上针对OpenCV 3.2.0(ubuntu存储库版本)进行编译,如下所示:
$ g++ -c -o example_opencv.o example_opencv.cpp
$ g++ -o example_opencv example_opencv.o -lopencv_core -lopencv_imgcodecs -lopencv_highgui
该程序显然可以正常运行。但是,由Valgrind检查时,会产生疯狂错误数量:
$ valgrind ./example_opencv
(... lengthy error report ...)
==14665== LEAK SUMMARY:
==14665== definitely lost: 34,152 bytes in 434 blocks
==14665== indirectly lost: 0 bytes in 0 blocks
==14665== possibly lost: 1,024 bytes in 14 blocks
==14665== still reachable: 64,144 bytes in 1,328 blocks
==14665== suppressed: 0 bytes in 0 blocks
==14665== Rerun with --leak-check=full to see details of leaked memory
==14665==
==14665== For counts of detected and suppressed errors, rerun with: -v
==14665== Use --track-origins=yes to see where uninitialised values come from
==14665== ERROR SUMMARY: 105422 errors from 1000 contexts (suppressed: 0 from 0)
如果我在具有与内存相关的实际错误的程序上使用相同的方法,则其错误将在这种混乱中完全消失。
是否有可能使用Valgrind调试OpenCV程序?