How are Unit Test algorithms that need to load data from the hard drive (pictures in this case!)?

Introduction

I am making a kind of OCR application that needs to recognize characters based on pre-saved .bmp images of each character.

Now, for this part of the screen where I know there will be a symbol, I want to pass the current image to CharacterFactory, which will return a Character object:

class CharacterFactory : ICharacterFactory {
    private Collection<Bitmap> aPictures = new HashTable<Bitmap>();
    private Collection<Bitmap> bPictures = new HashTable<Bitmap>();
    private Collection<Bitmap> cPictures = new HashTable<Bitmap>();
    ...

    public CharacterFactory() {
        LoadAllPictures();
    }

    ...    

    public Character GetCharacter(Bitmap characterToRecognize) {
        if (aPictures.Contains(characterToRecognize)) return new ACharacter();
        if (bPictures.Contains(characterToRecognize)) return new BCharacter();
        if (cPictures.Contains(characterToRecognize)) return new BCharacter();
        ...
    }
}

My question

Unit Test ? , , - characterToRecognize , . , , GetCharacter().

, , CharacterFactory xPictures , .

?

+3
4

, , , BitMap ( .Net) . . , , - , , . , . , , "IBitMap" , , .

"Microsoft Wrappers". , , , .

+1

, , unit test. .

, - , // unit test.

+1

LoadAllPictures() - SRP. , .

, , .

+1

, OCR . , , , .

  • Equals ; () , , , , . , .

  • , , - . , , .

, . . cross-correlation; " " . , ( ), , . , , .

If you are just after implementation and don’t want to know more about how a template works, AForge.NET includes a simple, comprehensive template matching algorithm. There are many improvements that can be made for faster searches, but this may be enough for your needs.

+1
source

Source: https://habr.com/ru/post/1760863/


All Articles