calcOpticalFlowPyrLK segmentation fault
Hi!
I am using the calcOpticalFlowPyrLK in combination with object detection.
But sometimes this function causes a segmentation fault. I still don't figure it out why.
It happens often in the third or forth step of the loop So:
Detect and get points to track
Calculate the flow and get new points P_new
Use p_new to calculate the next points in the next frame.
I am using it with a webcam such that each 5. Frame the object will be detected and then tracked for the next 4 frames
I already checked that the points which I pass to the function are not empty
The frames are not empty as well.
The error and status a configurares like in the example
But still it causes an segmentation fault.
Does anybody what could cause the seg fault?
There is no error message. It just crashes
auto & prev = track->prev_points;
auto & cur = track->cur_points;
auto & orig = track->orig_points;
std::vector<cv::Point2f> curP;
//cur.clear();
std::vector<uchar> status;
std::vector<float> err;
try{
cv::calcOpticalFlowPyrLK(lastFrame,currentFrame, track->prev_points,track->cur_points,status,err);
}
catch(cv::Exception& e ){
const char* err_msg = e.what();
std::cerr << "exception caught: " << err_msg << std::endl;
}
size_t i, k ;
auto it_1 = cur.begin();
auto it_2 = prev.begin();
auto it_3 = orig.begin();
for (i = k = 0; i < cur.size(); i++)
{
if (!status[i])
continue;
cur[k] = cur[i] ;
std::cerr << cur[k] <<std::endl;
prev[k] = prev[i];
orig[k] = orig[i];
k++;
}
cur.resize(k);
prev.resize(k);
orig.resize(k);
prev = cur;
not enough information here.
code? opencv/os version ? exact errormsg ?
auto
is far from helpful, without seing any context.please explain the
for (i = k = 0; i < cur.size(); i++)
loop.prev=cur
should be acv::swap()
see here (aliasing problem)it will loose points over time, be prepared to reinitialize them from gftt or similar