ByteScout Barcode Reader SDK - C# - Image Preprocessing Filters - ByteScout

ByteScout Barcode Reader SDK – C# – Image Preprocessing Filters

  • Home
  • /
  • Articles
  • /
  • ByteScout Barcode Reader SDK – C# – Image Preprocessing Filters

image preprocessing filters in C# and ByteScout BarCode Reader SDK

How to use ByteScout BarCode Reader SDK for image preprocessing filters in C#

These source code samples are listed and grouped by their programming language and functions they use. ByteScout BarCode Reader SDK helps with image preprocessing filters in C#. ByteScout BarCode Reader SDK is the SDK for reading of barcodes from PDF, images and live camera or video. Almost every common type like Code 39, Code 128, GS1, UPC, QR Code, Datamatrix, PDF417 and many others are supported. Supports noisy and defective images and docs. Includes optional documents splitter and merger for pdf and tiff based on found barcodess. Batch mode is supported for superior performance using multiple threads. Decoded values are easily exported to JSON, CSV, XML and to custom format.

You will save a lot of time on writing and testing code as you may just take the code below and use it in your application. Follow the instruction from the scratch to work and copy and paste code for C# into your editor. Enhanced documentation and tutorials are available along with installed ByteScout BarCode Reader SDK if you’d like to dive deeper into the topic and the details of the API.

On our website you may get trial version of ByteScout BarCode Reader SDK for free. Source code samples are included to help you with your C# application.

Try it today: Get 60 Day Free Trial or sign up for Web API

ImagePreprocessingFilters.NETCore.csproj
      
<?xml version="1.0" encoding="utf-8"?> <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp2.0</TargetFramework> <EnableDefaultCompileItems>false</EnableDefaultCompileItems> <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> <GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute> <GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute> <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> <GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute> <GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute> <GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute> <GenerateAssemblyTrademarkAttribute>false</GenerateAssemblyTrademarkAttribute> <GenerateAssemblyCultureAttribute>false</GenerateAssemblyCultureAttribute> <GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute> </PropertyGroup> <ItemGroup> <Compile Include="Program.cs" /> <None Include="barcode-with-large-margins.png"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> <None Include="low-contrast-barcode.png"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> <None Include="noisy-barcode.png"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> <None Include="too-dense-barcode.png"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> </ItemGroup> <ItemGroup> <PackageReference Include="Microsoft.Windows.Compatibility" Version="2.0.0" /> </ItemGroup> <ItemGroup> <Reference Include="Bytescout.BarCodeReader"> <SpecificVersion>False</SpecificVersion> <HintPath>c:\Program Files\Bytescout BarCode Reader SDK\netcoreapp2.0\Bytescout.BarCodeReader.dll</HintPath> </Reference> </ItemGroup> </Project>

Try it today: Get 60 Day Free Trial or sign up for Web API

ImagePreprocessingFilters.VS2005.csproj
      
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProductVersion>8.0.50727</ProductVersion> <SchemaVersion>2.0</SchemaVersion> <ProjectGuid>{C664E764-C424-4CD5-AF69-F6B05FB17BA8}</ProjectGuid> <OutputType>Exe</OutputType> <RootNamespace>ImagePreprocessingFilters</RootNamespace> <AssemblyName>ImagePreprocessingFilters</AssemblyName> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin\Debug\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>pdbonly</DebugType> <Optimize>true</Optimize> <OutputPath>bin\Release\</OutputPath> <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> <Reference Include="Bytescout.BarCodeReader, Version=8.20.0.1340, Culture=neutral, PublicKeyToken=f7dd1bd9d40a50eb, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>C:\Program Files\Bytescout BarCode Reader SDK\net2.00\Bytescout.BarCodeReader.dll</HintPath> </Reference> <Reference Include="System" /> <Reference Include="System.Data" /> <Reference Include="System.Drawing" /> <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> <Compile Include="Program.cs" /> </ItemGroup> <ItemGroup> <Content Include="barcode-with-large-margins.png"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> <Content Include="low-contrast-barcode.png"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> <Content Include="noisy-barcode.png"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> <Content Include="too-dense-barcode.png"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. <Target Name="BeforeBuild"> </Target> <Target Name="AfterBuild"> </Target> --> </Project>

Try it today: Get 60 Day Free Trial or sign up for Web API

ImagePreprocessingFilters.VS2008.csproj
      
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5"> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProductVersion>9.0.30729</ProductVersion> <SchemaVersion>2.0</SchemaVersion> <ProjectGuid>{C664E764-C424-4CD5-AF69-F6B05FB17BA8}</ProjectGuid> <OutputType>Exe</OutputType> <RootNamespace>ImagePreprocessingFilters</RootNamespace> <AssemblyName>ImagePreprocessingFilters</AssemblyName> <OldToolsVersion>2.0</OldToolsVersion> <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin\Debug\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>pdbonly</DebugType> <Optimize>true</Optimize> <OutputPath>bin\Release\</OutputPath> <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> <Reference Include="Bytescout.BarCodeReader, Version=8.20.0.1340, Culture=neutral, PublicKeyToken=f7dd1bd9d40a50eb, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>C:\Program Files\Bytescout BarCode Reader SDK\net3.50\Bytescout.BarCodeReader.dll</HintPath> </Reference> <Reference Include="System" /> <Reference Include="System.Data" /> <Reference Include="System.Drawing" /> <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> <Compile Include="Program.cs" /> </ItemGroup> <ItemGroup> <Content Include="barcode-with-large-margins.png"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> <Content Include="low-contrast-barcode.png"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> <Content Include="noisy-barcode.png"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> <Content Include="too-dense-barcode.png"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. <Target Name="BeforeBuild"> </Target> <Target Name="AfterBuild"> </Target> --> </Project>

Try it today: Get 60 Day Free Trial or sign up for Web API

ImagePreprocessingFilters.VS2010.csproj
      
<?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0"> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProductVersion> </ProductVersion> <SchemaVersion>2.0</SchemaVersion> <ProjectGuid>{C664E764-C424-4CD5-AF69-F6B05FB17BA8}</ProjectGuid> <OutputType>Exe</OutputType> <RootNamespace>ImagePreprocessingFilters</RootNamespace> <AssemblyName>ImagePreprocessingFilters</AssemblyName> <OldToolsVersion>3.5</OldToolsVersion> <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin\Debug\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>pdbonly</DebugType> <Optimize>true</Optimize> <OutputPath>bin\Release\</OutputPath> <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> <Reference Include="Bytescout.BarCodeReader"> <HintPath>C:\Program Files\Bytescout BarCode Reader SDK\net4.00\Bytescout.BarCodeReader.dll</HintPath> </Reference> <Reference Include="System" /> <Reference Include="System.Data" /> <Reference Include="System.Drawing" /> <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> <Compile Include="Program.cs" /> </ItemGroup> <ItemGroup> <Content Include="barcode-with-large-margins.png"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> <Content Include="low-contrast-barcode.png"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> <Content Include="noisy-barcode.png"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> <Content Include="too-dense-barcode.png"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. <Target Name="BeforeBuild"> </Target> <Target Name="AfterBuild"> </Target> --> </Project>

Try it today: Get 60 Day Free Trial or sign up for Web API

Program.cs
      
using System; using Bytescout.BarCodeReader; namespace ImagePreprocessingFilters { /// <summary> /// This exmaple demonstrates the use of image filters to improve the decoding or speed. /// </summary> class Program { static void Main() { using (Reader reader = new Reader("demo", "demo")) { // Set barcode type to find reader.BarcodeTypesToFind.Code128 = true; // WORKING WITH LOW CONTRAST BARCODE IMAGES // Add contrast adjustment for low-contrast image reader.ImagePreprocessingFilters.AddContrast(40); Console.WriteLine("Image {0}", "low-contrast-barcode.png"); FoundBarcode[] barcodes = reader.ReadFrom("low-contrast-barcode.png"); if (barcodes.Length == 0) Console.WriteLine("No barcode found!"); else foreach (FoundBarcode barcode in barcodes) Console.WriteLine("Found barcode {0} with value '{1}'", barcode.Type, barcode.Value); reader.ImagePreprocessingFilters.Clear(); Console.WriteLine(); // WORKING WITH NOISY BARCODE IMAGES // Add the median filter to lower the noise reader.ImagePreprocessingFilters.AddMedian(); Console.WriteLine("Image {0}", "noisy-barcode.png"); /* ----------------------------------------------------------------------- NOTE: We can read barcodes from specific page to increase performance. For sample please refer to "Decoding barcodes from PDF by pages" program. ----------------------------------------------------------------------- */ barcodes = reader.ReadFrom("noisy-barcode.png"); if (barcodes.Length == 0) Console.WriteLine("No barcode found!"); else foreach (FoundBarcode barcode in barcodes) Console.WriteLine("Found barcode {0} with value '{1}'", barcode.Type, barcode.Value); reader.ImagePreprocessingFilters.Clear(); Console.WriteLine(); // WORKING WITH DENSE AND ILLEGIBLE BARCODES // Add the scale filter to enlarge the barcode to make gaps between bars more distinguishable reader.ImagePreprocessingFilters.AddScale(2d); // enlarge twice Console.WriteLine("Image {0}", "too-dense-barcode.png"); barcodes = reader.ReadFrom("too-dense-barcode.png"); if (barcodes.Length == 0) Console.WriteLine("No barcode found!"); else foreach (FoundBarcode barcode in barcodes) Console.WriteLine("Found barcode {0} with value '{1}'", barcode.Type, barcode.Value); reader.ImagePreprocessingFilters.Clear(); Console.WriteLine(); // REMOVE EMPTY MARGINS FROM IMAGE TO SPEED UP THE PROCESSING // Add the crop filter to cut off empty margins from the image. // This will not improve the recognition quality but may speed up the processing // if you enabled multiple barcode types to search. reader.ImagePreprocessingFilters.AddCropDark(); Console.WriteLine("Image {0}", "barcode-with-large-margins.png"); barcodes = reader.ReadFrom("barcode-with-large-margins.png"); if (barcodes.Length == 0) Console.WriteLine("No barcode found!"); else foreach (FoundBarcode barcode in barcodes) Console.WriteLine("Found barcode {0} with value '{1}'", barcode.Type, barcode.Value); reader.ImagePreprocessingFilters.Clear(); Console.WriteLine(); } Console.WriteLine("Press any key to exit.."); Console.ReadKey(); } } }

Try it today: Get 60 Day Free Trial or sign up for Web API

MORE INFORMATION

Get 60 Day Free Trial or Visit ByteScout BarCode Reader SDK page

Explore ByteScout BarCode Reader SDK documentation

WEB API VERSION

Sign Up for free Web API key

Explore Web API Documentation

Tutorials:

prev
next