This is another sparse post that I’ll fill back in with more details shortly. In the meantime, check out my GitHub for the project associated with this post, optFlowTest. It tests measuring optical flow in a short film clip.
Here’s a sample of the program running:
Farneback flow is an algorithm in OpenCV that measures the frame-by-frame motion for each pixel in an image sequence. In the clip above, you can see that the program visualizes the motion as a flow field (the white lines over the video). Each line’s direction and magnitude corresponds to the amount of motion measured at that pixel, compared to the previous frame of the clip.
I’ve also added some visualizations of the average motion. The red line over the video shows the magnitude and direction of the average motion of the current frame, and the red line on the left show the average motion of the whole clip so far. The light blue dot travels along a path generated by the average flow, to give a sense of how the motion changes over of the course of the shot.
There are many reasons for measuring motion in film. For one, it’s used commercially in video-stabilization algorithms, and it can even be used to generate a 3D model of a scene from 2D images.
For my own purposes, I want to build out a database of film movement. This may involve separating the motion of the camera from the motion of the characters and objects within the frame. You can see that the clip I chose from Rear Window contains both camera movement and character motion – so the average motion is a combination of the two.
Often, films are edited with motion in mind: when an shot is cut on the motion of a character or an object, and the motion continues in the next shot (but from a different camera angle), this is called a match-on-action edit, and it creates a seamless impression of movement and space over time. Using optical flow could be one way of measuring, and even generating this type of edit.
Today’s project soundtrack is brought to you by xzayoso
a.k.a. Udit Mahajan
Next I plan to start applying feature matching and tracking, as well as optical flow detection to building out a database. We’ll see how that goes!