private void RepopulateFeaturePoints() { System.Drawing.PointF[] newRawTrackedFeaturePoints = this.OpticalFlow.FindFeaturesToTrack( m_CurrentGrayImage, m_TrackedFeatures, m_SkyRegionBottom, m_GroundRegionTop); if (newRawTrackedFeaturePoints.Length == 0) { return; } m_RawTrackedFeaturePoints.AddRange(newRawTrackedFeaturePoints); System.Drawing.PointF[] undistortedNewFeaturePoints = m_CameraParameters.IntrinsicCameraParameters.Undistort( newRawTrackedFeaturePoints, m_CameraParameters.IntrinsicCameraParameters.IntrinsicMatrix, null); for (int i = 0; i < undistortedNewFeaturePoints.Length; i++) { TrackedFeature trackedFeature = new TrackedFeature(); trackedFeature.Add(undistortedNewFeaturePoints[i]); m_TrackedFeatures.Add(trackedFeature); } this.InitialFeaturesCount = m_TrackedFeatures.Count; m_ThresholdForFeatureRepopulation = this.InitialFeaturesCount * 9 / 10; if (m_ThresholdForFeatureRepopulation < 100) { m_ThresholdForFeatureRepopulation = 100; } m_NotTrackedFeaturesCount = 0; }
private void RepopulateFeaturePoints() { System.Drawing.PointF[] newTrackedFeaturePoints = this.OpticalFlow.FindFeaturesToTrack( m_CurrentGrayImage, m_TrackedFeatures, m_SkyRegionBottom, m_GroundRegionTop); for (int i = 0; i < newTrackedFeaturePoints.Length; i++) { TrackedFeature trackedFeature = new TrackedFeature(); trackedFeature.Add(newTrackedFeaturePoints[i]); m_TrackedFeatures.Add(trackedFeature); } this.InitialFeaturesCount = m_TrackedFeatures.Count; m_ThresholdForFeatureRepopulation = this.InitialFeaturesCount * 9 / 10; // We ensure that we don't drop below a fixed limit if (m_ThresholdForFeatureRepopulation < 100) { m_ThresholdForFeatureRepopulation = 100; } m_NotTrackedFeaturesCount = 0; }
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"); } }