Example: Dashcam optic flow using Computer Vision Toolbox
Updated 16 Aug 2021
- Each frame of the video was extracted as a jpg image using "Free Video to JPG Converter" (30 fps). Alternatively, each frame could be read into Matlab using VideoReader but I found this to be slower than having the image frames available on file.
- Each jpg frame was read into Matlab using read and was converted to grayscale using im2gray.
- The motion between grayscale image n and image n-1 was computed using vision.BlockMatcher (Computer Vision Toolbox), set up to return the horizontal and vertical components of motion for each flow vector spaced along a grid.
- Any flow vectors with a magnitude of less than 2 were eliminated for each frame to reduce noise. If all flow vectors had 0 magnitude, the frame was a duplicate and was removed.
- The remaining optic flow vectors were plotted to the original colored jpg image frames using quiver and the updated image was stored to memory using getframe.
- The final updated frames were written to video using VideoWriter.
Adam Danz (2021). Example: Dashcam optic flow using Computer Vision Toolbox (https://www.mathworks.com/matlabcentral/fileexchange/97652-example-dashcam-optic-flow-using-computer-vision-toolbox), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!