title: Dense optical flow with masking
body: <p>I need to compute dense optical flow of vehicles between two consecutive frames recorded from an overhead camera. I am using an object detector for vehicle detection and Farneback algorithm for optical flow estimation in Python. Presently, the optical flow is computed for the entire image. However, I need to create a mask around the vehicles detected and compute dense optical flow only around the selected region. This will help to speed up optical flow estimation significantly. I can use any other form of dense optical flow estimation too, but not sparse optical flow (e.g., Lucas-Kanade method). One option can be to extract vehicle regions and input each vehicle region individually for optical flow estimation, but I am looking for a better solution.</p>
  
  <pre><code>flow = cv2.calcOpticalFlowFarneback(prvs,next, None, 0.5, 3, 15, 3, 5, 1.2, 0)
  </code></pre>
  
  <p>The expected optical flow result will be zero for non-vehicle masked region without any optical flow computation.</p>