private IEnumerable<string> GetText(LogicalRectangle leadRect, BarcodeReadOptions[] coreReadOptions, ImageSource image, BarcodeImageType imageType) { var engine = new BarcodeEngine(); engine.Reader.ImageType = imageType; var barcodeDatas = engine.Reader.ReadBarcodes(image.ToRasterImage(), leadRect, 10, BarcodeSymbologies.ToArray(), coreReadOptions); var textForStrategy = barcodeDatas .Select(data => data.Value) .DefaultIfEmpty(); return textForStrategy; }
public IEnumerable<RecognitionResult> Recognize(BitmapSource bitmap, ZoneConfiguration config) { var coreReadOptions = CoreReadOptions; var leadRect = new LogicalRectangle(0, 0, bitmap.PixelWidth, bitmap.PixelHeight, LogicalUnit.Pixel); var unitsOfWork = from strategy in BarcodeStrategies let filteredImage = Freeze(strategy.BitmapFilter.Apply(bitmap)) select new { ImageType = strategy.ImageType, FilteredImage = filteredImage }; var selectMany = unitsOfWork.SelectMany(u => GetText(leadRect, coreReadOptions, u.FilteredImage, u.ImageType)); return selectMany.Select(s => new RecognitionResult(s, 1)); }