Possible to see Optical Flow output?

asked 2014-07-08 11:00:00 -0600

abelis gravatar image

I hope this doesn't sound too crazy, but I want to see what the optical flow looks like to make sure I know what it is seeing in a sense. The following doesn't work because opt_flow is a 2 channel float Mat. Is opt_flow even a Mat that you can visually display?

cv::Mat opt_flow;
cv::Mat gray, prevGray;
cv::Ptr<cv::DenseOpticalFlow> tvl1 = cv::createOptFlow_DualTVL1();

cv::cvtColor(image, gray, cv::COLOR_BGR2GRAY);
if(prevGray.empty()){
   gray.copyTo(prevGray);
}

tvl1->calc(prevGray,gray,opt_flow);
cv::imshow("Opt Flow", opt_flow);
cv::swap(prevGray, gray);
edit retag flag offensive close merge delete

Comments

  • i think you can re-use the drawing code from the farneback example (idea there is to sample a grid from the of-Mat and draw lines for the corner points)

  • another would be: split() it into seperate x and y channels, multiply by some factor, then imshow()

berak gravatar imageberak ( 2014-07-08 11:17:59 -0600 )edit

Thanks! That is a great example to work with. Extremely slow but a good start for me! Next step is to move it to the GPU! Just wanted to see it work before I did that.

abelis gravatar imageabelis ( 2014-07-08 12:42:54 -0600 )edit