1 /** 2 Module introduces the API that defines Optical Flow utilities in the dcv library. 3 4 Copyright: Copyright Relja Ljubobratovic 2016. 5 6 Authors: Relja Ljubobratovic 7 8 License: $(LINK3 http://www.boost.org/LICENSE_1_0.txt, Boost Software License - Version 1.0). 9 */ 10 module dcv.tracking.opticalflow.base; 11 12 public import mir.ndslice.slice : Slice, SliceKind; 13 14 public import dcv.core.image : Image; 15 public import dcv.core.utils : emptySlice; 16 17 /** 18 Sparse Optical Flow algorithm interface. 19 */ 20 interface SparseOpticalFlow 21 { 22 23 /** 24 Evaluate sparse optical flow method between two consecutive frames. 25 26 Params: 27 f1 = First frame image. 28 f2 = Second frame image. 29 points = points which are tracked. 30 searchRegions = search region width and height for each point. 31 prevflow = displacement values preallocated array. 32 usePrevious = if algorithm should continue iterating by 33 using presented values in the flow array, set this to true. 34 35 Returns: 36 Array of 2 floating point values which represent movement of each given feature point, from f1 to f2. 37 */ 38 float[2][] evaluate(inout Image f1, inout Image f2, in float[2][] points, 39 in float[2][] searchRegions, float[2][] prevflow = null, bool usePrevious = false); 40 } 41 42 /// Alias to a type used to define the dense optical flow field. 43 alias DenseFlow = Slice!(SliceKind.contiguous, [3], float*); 44 45 /** 46 Dense Optical Flow algorithm interface. 47 */ 48 interface DenseOpticalFlow 49 { 50 /** 51 Evaluate dense optical flow method between two consecutive frames. 52 53 Params: 54 f1 = First image, i.e. previous frame in the video. 55 f2 = Second image of same size and type as $(D f1), i.e. current frame in the video. 56 prealloc = Optional pre-allocated flow buffer. If provided, has to be of same size as input images are, and with 2 channels (u, v). 57 usePrevious = Should the previous flow be used. If true $(D prealloc) is treated as previous flow, and has to satisfy size requirements. 58 59 Returns: 60 Calculated flow field. 61 */ 62 DenseFlow evaluate(inout Image f1, inout Image f2, DenseFlow prealloc = emptySlice!([3], float), 63 bool usePrevious = false); 64 }