I shared this picture on Twitter of a little demo that I was writing for a talk where the PC (via the web cam) was reading a page of text;
and I got asked to share the source so I’m doing that here although the source is a little bit ‘rough and ready’.
I then looked up my old posts and realised that the code here is just an evolution of the code from this post so I won’t add too much here. Essentially, the way it works is something like;
- MainPage.xaml UI displays a CaptureElement, a Canvas and a TextBlock.
- The code behind MainPage.xaml.cs does;
- Creates a class I wrote called CameraPreviewManager which takes a reference to the CaptureElement and a filter to be applied to find the ‘best’ camera and then starts the previewing of video to the CaptureElement.
- Creates a class I wrote called OcrDetectionFrameProcessor which essentially runs a loop on a separate thread to pull preview frames from the camera, process them by using the OCR engine to gather some results and then fires a FrameProcessed event.
- Handles the FrameProcessed on the UI thread to draw the results to the screen as shown above.
- That’s pretty much it – code’s here for download, it’s a bit hacky so caveat emptor as usual