Ask Your Question
0

Conditional jump or move depends on uninitialised value(s) from Valgrind for calcOpticalFlowPyrLK call

asked 2015-11-10 13:22:19 -0500

pviewer gravatar image

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 ...
(more)
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-11-20 12:26:27 -0500

pviewer gravatar image

I found my own error--the status vector needs to be of type unsigned char, not bool. Read the docs.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2015-11-10 13:21:39 -0500

Seen: 291 times

Last updated: Nov 20 '15