protected override void CustomUpdateMonitorReading(object sender, Ubicomp.Utils.NET.CAF.ContextAdapter.NotifyContextMonitorListenersEventArgs e) { if (e.Type != typeof(Bitmap)) return; if (Device.State == StackingState.StackedOnTop) return; if (isProcessStopped) return; if (sender is SimCameraMonitor) { List<Glyph> detectedGlyphs = new List<Glyph>(); var simulatorDevice = ((sender as SimCameraMonitor).CameraSource as SimulatorDevice).CalculatorGlyph; if (simulatorDevice == true) detectedGlyphs.Add(Glyph.Square); NotifyContextServiceListeners(this, new NotifyContextServiceListenersEventArgs(typeof(GlyphDetectionService), detectedGlyphs)); } else if (sender is CameraMonitor) { if (Tracker == null) Tracker = (sender as CameraMonitor).Tracker; if (Tracker == null) return; List<Glyph> detectedGlyphs = new List<Glyph>(); ManagedA.Glyphs result = Tracker.DetectFigures(20, 80, 150); for(int i = 0 ; i < result.numberSquares ; i++) detectedGlyphs.Add(Glyph.Square); for (int i = 0; i < result.numberTriangles; i++) detectedGlyphs.Add(Glyph.Triangle); NotifyContextServiceListeners(this, new NotifyContextServiceListenersEventArgs(typeof(GlyphDetectionService), detectedGlyphs)); } }
void Registration_OnNotifyContextServiceListeners(object sender, Ubicomp.Utils.NET.CAF.ContextService.NotifyContextServiceListenersEventArgs e) { Dispatcher.Invoke(DispatcherPriority.Render, (Action)delegate() { lock (captureLock) { UofM.HCI.tPad.Services.RegistrationService registration = sender as UofM.HCI.tPad.Services.RegistrationService; capture = (Bitmap)registration.Tracker.GetCameraImg(true).Clone(); // create a barcode reader instance IBarcodeReader reader = new BarcodeReader(); // detect and decode the barcode inside the bitmap var result = reader.Decode(capture); // do something with the result if (result != null) { FoundCode = true; CodeType = result.BarcodeFormat.ToString(); CodeContent = result.Text; float ratioX = (float)ActualWidth / capture.Width; float ratioY = (float)ActualHeight / capture.Height; TranslateX = (int)(result.ResultPoints.Average(point => point.X) * ratioX) - (int)(ActualWidth / 2); TranslateY = (int)(result.ResultPoints.Average(point => point.Y) * ratioY) - (int)(ActualHeight / 2); lastTimeSeem = DateTime.Now; if (cbAuto.IsChecked == true) bLaunch_Click(null, null); } else { var elapsed = DateTime.Now - lastTimeSeem; if (elapsed.TotalMilliseconds >= 3000) FoundCode = false; } GC.Collect(0, GCCollectionMode.Forced); } }); }