public void Segmentation( ref int head, ref int tail ) { List <MacheteElement> current = dtw[currentIndex]; MacheteElement curr = current[current.Count - 1]; head = curr.startFrameNo - 1; tail = curr.endFrameNo; }
public void Update( MacheteElement extendThis, int frameNo, double cost, double length ) { startFrameNo = extendThis.startFrameNo; endFrameNo = frameNo; cost *= length; this.runningScore = extendThis.runningScore + cost; this.total = extendThis.total + length; }
public void Update( CircularBuffer <Vector> buffer, Vector pt, Vector nvec, int frameNo, double length ) { // Cache current row as prev List <MacheteElement> previous = dtw[currentIndex]; // Update Circular Buffer Index currentIndex++; currentIndex %= 2; // Cache reference to current row List <MacheteElement> current = dtw[currentIndex]; // Update frame number current[0].startFrameNo = frameNo; for (int col = 1; col <= vectorCount; col++) { double dot = nvec.Dot(vectors[col - 1]); double cost = 1.0 - Math.Max(-1.0, Math.Min(1.0, dot)); cost = cost * cost; // Pick the lowest cost neightbor to // extent it's warping path through // this (frame_no, col) element. MacheteElement n1 = current[col - 1]; MacheteElement n2 = previous[col - 1]; MacheteElement n3 = previous[col]; MacheteElement extend = n1; double minimum = n1.GetNormalizedWarpingPathCost(); if (n2.GetNormalizedWarpingPathCost() < minimum) { extend = n2; minimum = n2.GetNormalizedWarpingPathCost(); } if (n3.GetNormalizedWarpingPathCost() < minimum) { extend = n3; minimum = n3.GetNormalizedWarpingPathCost(); } // Update the miniumum cost warping path // Element to include this frame current[col].Update( extend, frameNo, cost, length); } MacheteElement curr = current[vectorCount]; int startFrameNo = curr.startFrameNo; int endFrameNo = curr.endFrameNo; double durationFrameCount = endFrameNo - startFrameNo + 1; double cf = 1.0f; if (device_id == DeviceType.MOUSE) { double cf_closedness = 2.0; double cf_f2l = 2.0; if (durationFrameCount < buffer.Count() - 1) { // Get first to last vector Vector vec = buffer[-1] - buffer[-(int)durationFrameCount]; double total = current[vectorCount].total; double vlength = vec.L2Norm(); double closedness1 = vlength / total; vec /= vlength; // Closedness cf_closedness = Math.Max(closedness1, closedness); cf_closedness /= Math.Min(closedness1, closedness); cf_closedness = 1 + weightClosedness * (cf_closedness - 1.0); cf_closedness = Math.Min(2.0, cf_closedness); // End direction double f2l_dot = f2l_Vector.Dot(vec); f2l_dot = 1.0 - Math.Max(-1.0, Math.Min(1.0, f2l_dot)); cf_f2l = 1.0 + (f2l_dot / 2.0) * weightF2l; cf_f2l = Math.Min(2.0, cf_f2l); cf = cf_closedness * cf_f2l; } } double ret = curr.GetNormalizedWarpingPathCost(); if (durationFrameCount < minimumFrameCount) { cf *= 1000.0f; } trigger.Update( frameNo, ret, cf, curr.startFrameNo, curr.endFrameNo); double _t = trigger.GetThreshold(); result.Update( ret * cf, _t, curr.startFrameNo, curr.endFrameNo, frameNo); }