private void TrackFeatures(Image <Gray, Byte> previousGrayImage) { if (m_RawTrackedFeaturePoints.Count == 0) { return; } OpticalFlowResult opticalFlowResult = this.OpticalFlow.CalculateOpticalFlow(previousGrayImage, m_CurrentGrayImage, m_RawTrackedFeaturePoints.ToArray()); System.Drawing.PointF[] rawTrackedFeaturePoints = opticalFlowResult.TrackedFeaturePoints; m_RawTrackedFeaturePoints.Clear(); m_RawTrackedFeaturePoints.AddRange(rawTrackedFeaturePoints); System.Drawing.PointF[] undistortedNewFeaturePoints = m_CameraParameters.IntrinsicCameraParameters.Undistort( rawTrackedFeaturePoints, m_CameraParameters.IntrinsicCameraParameters.IntrinsicMatrix, null); int fullHistoryFeaturesCount = 0; int unsmoothFeaturesCount = 0; for (int i = undistortedNewFeaturePoints.Length - 1; i >= 0; i--) { bool isTracked = opticalFlowResult.TrackingStatusIndicators[i] == 1; if (isTracked) { TrackedFeature trackedFeature = m_TrackedFeatures[i]; trackedFeature.Add(undistortedNewFeaturePoints[i]); if (trackedFeature.IsFull) { fullHistoryFeaturesCount++; if (!trackedFeature.IsSmooth) { unsmoothFeaturesCount++; } } } else { RemoveTrackedFeature(i); } } if (unsmoothFeaturesCount < fullHistoryFeaturesCount / 2) { // The majority of features is smooth. We downgrade unsmooth features //Debug.WriteLine("Consensus: Is smooth"); ApplyUnsmoothGrades(); } else { // Consensus not smooth; not downgrading unsmooth features. //Debug.WriteLine("Consensus: Is not smooth"); } }
private void TrackFeatures(Image <Gray, Byte> previousGrayImage) { System.Drawing.PointF[] trackedFeaturePoints = new System.Drawing.PointF[m_TrackedFeatures.Count]; for (int i = 0; i < trackedFeaturePoints.Length; i++) { trackedFeaturePoints[i] = m_TrackedFeatures[i][0]; } OpticalFlowResult opticalFlowResult = this.OpticalFlow.CalculateOpticalFlow(previousGrayImage, m_CurrentGrayImage, trackedFeaturePoints); trackedFeaturePoints = opticalFlowResult.TrackedFeaturePoints; int fullHistoryFeaturesCount = 0; int unsmoothFeaturesCount = 0; for (int i = trackedFeaturePoints.Length - 1; i >= 0; i--) { bool isTracked = opticalFlowResult.TrackingStatusIndicators[i] == 1; if (isTracked) { TrackedFeature trackedFeature = m_TrackedFeatures[i]; trackedFeature.Add(trackedFeaturePoints[i]); if (trackedFeature.IsFull) { fullHistoryFeaturesCount++; if (!trackedFeature.IsSmooth) { unsmoothFeaturesCount++; } } } else { RemoveTrackedFeature(i); } } if (unsmoothFeaturesCount < fullHistoryFeaturesCount / 2) { // The majority of features is smooth. We downgrade unsmooth features //Debug.WriteLine("Consensus: Is smooth"); ApplyUnsmoothGrades(); } else { // Consensus not smooth; not downgrading unsmooth features. //Debug.WriteLine("Consensus: Is not smooth"); } }
public OpticalFlow(int maxFeatureCount, int blockSize, double qualityLevel, double minDistance) { m_MaxFeatureCount = maxFeatureCount; m_BlockSize = blockSize; m_QualityLevel = qualityLevel; m_MinDistance = minDistance; m_SubCornerTerminationCriteria.max_iter = 20; m_SubCornerTerminationCriteria.epsilon = 0.1; m_SubCornerTerminationCriteria.type = Emgu.CV.CvEnum.TERMCRIT.CV_TERMCRIT_EPS | Emgu.CV.CvEnum.TERMCRIT.CV_TERMCRIT_ITER; m_OpticalFlowTerminationCriteria.max_iter = 20; m_OpticalFlowTerminationCriteria.epsilon = 0.3; m_OpticalFlowTerminationCriteria.type = Emgu.CV.CvEnum.TERMCRIT.CV_TERMCRIT_EPS | Emgu.CV.CvEnum.TERMCRIT.CV_TERMCRIT_ITER; this.OpticalFlowResult = new OpticalFlowResult(); }