160 likes | 338 Views
Optical Flow walk through. Aidean Sharghi Spring 14. Optical Flow. The objective in this assignment is to setup and use Optical Flow This implementation is fast and so you will see it can be used for real-time purposes Required steps to setup and run are provided in this presentation.
E N D
Optical Flow walk through Aidean Sharghi Spring 14
Optical Flow • The objective in this assignment is to setup and use Optical Flow • This implementation is fast and so you will see it can be used for real-time purposes • Required steps to setup and run are provided in this presentation
Contents • OpenCV installation process • Setting Environment Variables • How to run Optical Flow
OpenCV • OpenCV stands for Open-source Computer Vision • It is a library of useful functions used in Computer Vision • To run Optical Flow: • Install OpenCV 2.2 if you have VS 2010 installed on your machine • Install OpenCV 2.4 if you have VS 2012
Install OpenCV2.2 for VS 2010 • Download OpenCV2.2 from http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.2/ • Extract the files in C:\OpenCV2.2 • Set Environment Variables. • If variable ‘path’ exists, just add the C:\OpenCV2.2\bin\ to the end of its value • If ‘path’ does not exist, just add a new variable and name it ‘path’ and set its value to what mentioned above
Install OpenCV2.4 for VS 2012 • Download OpenCV2.4 from http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.4/OpenCV-2.4.4.exe • Extract the files in C:\opencv • Set Environment Variables. • Add the new variable ‘path’ and set its value to “C:\opencv\build\(your VS build x86/x64)\vc11\bin\ “ • E.g. if you have VS x64 version installed on your machine, the value will be: C:\opencv\build\x64\vc11\bin
Building the Project • Just download and build the project using your VS • Open a command prompt and change its directory to your project’s debug folder • Give the input
Command Prompt • Open Command Prompt • To do so, you can hold Ctrl key and press R. Run window will show up. Then write cmd in the box and press enter. • Change Directory to the Debug Folder • cd is the command you need to use. • For example if you enter: • cd C:\Users\’your username’\Desktop This will take you to your desktop
Two ways to use • When you are in the Debug folder, then you have two options • Compute Optical Flow • frames imageFile1 imageFile2 change directory to the debug folder then enter these: > OpticalFlow.exe frames image0.jpg image1.jpg • Find the Optical Flow by webcam • camera or NULL > OpticalFlow.exe camera
Four keys to control • w : increment (by 10) number of corners to track (max = 400) • s : decrement (by 10) number of corners to track (min=10) • d : double pyramid window size (max=64) • a : half pyramid window size (min=2)
Code Analysis Load Image 1 Interest Points KLT Tracker using 2 images
Harris Corner Detector • Compute horizontal and vertical derivatives of image • Compute the matrix • Convolve the matrix with a larger Gaussian window. • Compute the Eigen vector of M • Find local maxima above threshold as interest points
KLT Tracker • Detect Harris corners in the first frame • Build the Optical Flow Pyramid • For each Harris corner compute motion between consecutive frames • Link motion vectors in successive frames to get a track for each Harris point • Introduce new Harris points by applying Harris detector at every m frames
Two useful functions • void cvCalcOpticalFlowPyrLK(constCvArr* prev, constCvArr* curr, CvArr* prevPyr, CvArr* currPyr, const CvPoint2D32f* prevFeatures, CvPoint2D32f* currFeatures, int count, CvSizewinSize, int level, char* status, float* track_error, CvTermCriteria criteria, int flags)
Two useful functions • intbuildOpticalFlowPyramid(InputArrayimg, OutputArrayOfArrayspyramid, Size winSize, intmaxLevel, boolwithDerivatives=true, intpyrBorder=BORDER_REFLECT_101, intderivBorder=BORDER_CONSTANT, booltryReuseInputImage=true)