I have a small test code for LK tracking that I am running with OpenCV 2.4.11
#include <opencv2/core/core.hpp>
#include <opencv2/video/video.hpp>
#include <opencv2/imgproc/imgproc.hpp>
int main(int argc, char ** argv)
{
// Draw two white squares on a black background,
// shift the square slightly in another image,
// track between the two images.
cv::Mat background = cv::Mat::zeros(100,100,CV_8U);
cv::Mat foreground = cv::Mat::ones(10,10,CV_8U)*255;
cv::Mat image1 = background.clone();
cv::Mat image2 = background.clone();
cv::Point2i point1(20,20);
cv::Point2i point2(22,22);
cv::Mat region1 = image1(cv::Rect(point1.x,point1.y,10,10));
cv::Mat region2 = image1(cv::Rect(point1.x+20,point1.y,10,10));
cv::Mat region3 = image2(cv::Rect(point2.x,point2.y,10,10));
cv::Mat region4 = image2(cv::Rect(point2.x+20,point2.y,10,10));
foreground.copyTo(region1);
foreground.copyTo(region2);
foreground.copyTo(region3);
foreground.copyTo(region4);
std::vector<cv::Point2f> image1features;
cv::goodFeaturesToTrack(image1,image1features,100,0.01,2);
std::vector<cv::Point2f> image2features(image1features.size());
std::vector<bool> status(image1features.size(),false);
cv::Mat err = cv::Mat::zeros(image1features.size(),1,CV_32F);
cv::calcOpticalFlowPyrLK(image1,image2,image1features,image2features,
status,err);
return 0;
}
When I run this code with Valgrind by calling
$ valgrind --track-origins=yes ./main
I get two "Conditional jump or move depends on uninitilised value(s)" warnings.
==8978== Memcheck, a memory error detector
==8978== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==8978== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for copyright info
==8978== Command: ./main
==8978==
==8978== Conditional jump or move depends on uninitialised value(s)
==8978== at 0x4F068E5: cv::_OutputArray::create(int, int const*, int, int, bool, int) const (in /---/libopencv_core.so.2.4.11)
==8978== by 0x4F0B2ED: cv::_OutputArray::create(int, int, int, int, bool, int) const (in /---/libopencv_core.so.2.4.11)
==8978== by 0x55F5904: cv::calcOpticalFlowPyrLK(cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, cv::Size_<int>, int, cv::TermCriteria, int, double) (in /---/libopencv_video.so.2.4.11)
==8978== by 0x40669B: main (main.cpp:33)
==8978== Uninitialised value was created by a stack allocation
==8978== at 0x406052: main (main.cpp:5)
==8978==
==8978== Conditional jump or move depends on uninitialised value(s)
==8978== at 0x4F068EB: cv::_OutputArray::create(int, int const*, int, int, bool, int) const (in /---/libopencv_core.so.2.4.11)
==8978== by 0x4F0B2ED: cv::_OutputArray::create(int, int, int, int, bool, int) const (in /---/libopencv_core.so.2.4.11)
==8978== by 0x55F5904: cv::calcOpticalFlowPyrLK(cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, cv::Size_<int>, int, cv::TermCriteria, int, double) (in /---/libopencv_video.so.2.4.11)
==8978== by 0x40669B: main (main.cpp:33)
==8978== Uninitialised value was created by a stack allocation
==8978== at 0x406052: main (main.cpp:5)
==8978==
==8978==
==8978== HEAP SUMMARY:
==8978== in use at exit: 28,448 bytes in 71 blocks
==8978== total heap usage: 237 allocs, 166 frees, 586,330 bytes allocated
==8978==
==8978== LEAK SUMMARY:
==8978== definitely lost: 0 bytes in 0 blocks
==8978== indirectly lost: 0 bytes in 0 blocks
==8978== possibly lost: 28,448 bytes in 71 blocks
==8978== still reachable: 0 bytes in 0 blocks
==8978== suppressed: 0 bytes in 0 blocks
==8978== Rerun with --leak-check=full to see details of leaked memory
==8978==
==8978== For counts of detected and suppressed errors, rerun with: -v
==8978== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
(Irrelevant path information is replaced by dashes.)
I am trying to remove these warnings as a step in debugging a larger problem, in which my code segfaults in calcOpticalFlowPyrLK--sometimes.