A basic example of template replacement in black images with some white areas (!not binary images), using EmguCV library and TPL Dataflow from .NET (for execution paralelism). The solution can be adjusted for all template replacement cases.
Given a set of binary images that may contain some white areas in random position and a template image, fill all the white area/areas with the provided template following this rules:
- The size of the white areas can be different, but the valid areas has exactly the same size as the template and can not contain any black pixels.
- The template can not be manipulated. You need to replace all the valid areas with the same width and the same height as the template.
- For every input*.bmp from Input folder you need to create a output*.bmp in the Output folder. The format of this file must be .bmp.
- Input folder and template folder are needs to be provided by you and the output folder needs to be created dynamically if does not exist in the same folder with the executable.
- C# .NET at least 4.5
- EmguCV 3.3.0.2824 (check http://www.emgu.com/wiki/index.php/Main_Page for downloading)
- TPL Dataflow from .NET (https://www.nuget.org/packages/Microsoft.Tpl.Dataflow/)
IDE : Microsoft Visual Studio 2017
- Install EmguCV and compile the sources (see how to use EmguCV with VS2017)
- Create a visual studio console application
- Add the provided files and/or adjust your Program.cs to match the provided Program.cs file
- Install TPL Dataflow package from nuget
- Go to Project tab in Visual Studio and choose Properties
- In the opened window choose Build tab and change the Platform target:
- if you choose x86 then : Add reference Emgu.CV.World.dll from bin/x86 folder found to the installed library path (usually in C:\Emgu\emgucv-windesktop 3.3.0.2824)
- if you choose x64 then : Add reference Emgu.CV.World.dll from bin/x64 folder found to the installed library path (usually in C:\Emgu\emgucv-windesktop 3.3.0.2824)
- Right click on the solution name -> Add -> Add Existing Item... -> [Go to the EmguCV installed folder and find the "cvextern.dll"] -> Add
- Right click on "cvextern.dll" and press "Properties". In the properties window please change the "Copy to Output Directory" property form Advanced section with "Copy always" option
- Build your project
- Copy and paste the provided bin content folder inside your bin folder
- Run the project