void controller_HeadMove(object sender, HeadEventArgs e) { if (controller == null || controller.Tracker == null) { return; } if (backproj) { try { Camshift camshift = controller.Tracker as Camshift; Bitmap backprojection = camshift.GetBackprojection( PixelFormat.Format24bppRgb, camshift.TrackingObject.Rectangle); if (parent.faceForm != null && !parent.faceForm.IsDisposed) { MatchingTracker matching = parent.faceForm.faceController.Tracker as MatchingTracker; marker.Rectangles = new[] { matching.TrackingObject.Rectangle }; marker.ApplyInPlace(backprojection); } pictureBox.Image = backprojection; } catch { pictureBox.Image = null; } } }
void controller_NewFrame(object sender, NewFrameEventArgs eventArgs) { if (!backproj) { Bitmap image = eventArgs.Frame; if (image == null) { return; } if (parent.faceForm != null && !parent.faceForm.IsDisposed) { MatchingTracker matching = parent.faceForm.faceController.Tracker as MatchingTracker; Rectangle rect = new Rectangle( matching.TrackingObject.Center.X, 0, image.Width - matching.TrackingObject.Center.X, matching.TrackingObject.Center.Y); rect.Intersect(new Rectangle(0, 0, image.Width, image.Height)); marker.Rectangles = new[] { matching.TrackingObject.Rectangle }; image = marker.Apply(image); } pictureBox.Image = image; } }
/// <summary> /// Initializes a new instance of the <see cref="FaceController"/> class. /// </summary> /// public FaceController() { // Setup tracker tracker = new MatchingTracker(); tracker.Extract = false; // Setup detector detector = new HaarObjectDetector(new NoseHaarCascade()); detector.ScalingFactor = 1.1f; detector.SearchMode = ObjectDetectorSearchMode.Single; detector.ScalingMode = ObjectDetectorScalingMode.SmallerToGreater; detector.MinSize = new Size(2, 5); //detector.MaxSize = new Size(15, 18); }
public void stringHashMap() { int LOCAL_STATE_SIZE = 2048; // exercise with random values for (int i = 0; i < 100; ++i) { string[] keys = new string[LOCAL_STATE_SIZE]; bool[] values = new bool[LOCAL_STATE_SIZE]; float[] times = new float[LOCAL_STATE_SIZE]; var realMap = new Dictionary <string, bool>(); for (int j = 0; j < 80; j++) { var key = RandomString(10); realMap.Add(key, true); MatchingTracker.set(key, true, keys, values, times); } foreach (var thing in realMap) { Assert.That(MatchingTracker.lookup(thing.Key, keys, values), Is.True); } } }
public void ProcessFrame() { string basePath = Path.Combine(NUnit.Framework.TestContext.CurrentContext.TestDirectory, "matching-tracker"); #region doc_track // Let's test the tracker using a sample video from // the collection of test videos in the framework: TestVideos ds = new TestVideos(basePath); string fileName = ds["walking.mp4"]; // Now, let's open the video using FFMPEG: var video = new VideoFileReader(); video.Open(fileName); // And then check the contents of one of the frames: Bitmap frame = video.ReadVideoFrame(frameIndex: 150); frame.Save(Path.Combine(basePath, "walking_frame.png")); // Let's register a template for the bike rider in gray shirt Rectangle roi = new Rectangle(x: 70, y: 105, width: 28, height: 54); // initialization var tracker = new MatchingTracker() { SearchWindow = roi, Threshold = 0.0, // never reset the tracker in case it gets lost RegistrationThreshold = 0.95 // re-register the template if we are 95% // confident that the tracked object is indeed the object we want to follow }; // Creating bitmaps and locking them is an expensive // operation. Instead, let's allocate once and reuse BitmapData bitmapData = frame.LockBits(ImageLockMode.ReadWrite); UnmanagedImage unmanagedImage = new UnmanagedImage(bitmapData); // We will create two color markers: one to show the location of the // tracked object (red) and another one to show the regions of the image // that the tracker is looking at (white). RectanglesMarker objectMarker = new RectanglesMarker(Color.Red); RectanglesMarker windowMarker = new RectanglesMarker(Color.White); // Now, for each frame of the video for (int frameIndex = 0; frameIndex < video.FrameCount; frameIndex++) { // Read the current frame into the bitmap data video.ReadVideoFrame(frameIndex, bitmapData); if (frameIndex > 150) // wait until the bike rider enters the scene { // Feed the frame to the tracker tracker.ProcessFrame(unmanagedImage); // Mark the location of the tracker object in red color objectMarker.SingleRectangle = tracker.TrackingObject.Rectangle; objectMarker.ApplyInPlace(unmanagedImage); // overwrite the frame windowMarker.SingleRectangle = tracker.SearchWindow; windowMarker.ApplyInPlace(unmanagedImage); // overwrite the frame } // Save it to disk frame.Save(Path.Combine(basePath, "frame_{0}.png".Format(frameIndex))); } frame.UnlockBits(bitmapData); #endregion }