添加多个位值词典使用C#一键 [英] adding multiple bitmap values for one key in dictionary with C#

查看:202
本文介绍了添加多个位值词典使用C#一键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一本字典来存储模式图像进行OCR目的。我一把抓起字典这些位图相比,那些我从图像裁剪,如果他们匹配=>抢下(OCR部分完成的)关键。

I had a dictionary to store pattern images for OCR purposes. I grabbed these bitmaps from dictionary and compared to ones that I cropped from image, if they matched => grabbed the key (OCR part is done).

问题就出现在这里。一键应该由几个不同的位图(即,值)来表示。 如何添加多个位图到字典中,以代表相同的密钥

The problem arises here. One Key should be represented by several different bitmaps (i.e. values). How do you add multiple bitmaps to the dictionary, to represent the same key?

这就是我如何使用字典:

that's how I used dictionary:

    Dictionary<string, Bitmap> lookup = new Dictionary<string, Bitmap>();
    lookup.Add("A", new Bitmap(@"C:\08\letters\1\a1.bmp", true));
    lookup.Add("A", new Bitmap(@"C:\08\letters\1\a2.bmp", true)); // Error will be here, because key A already exists for one Bitmap value.
    lookup.Add("a", new Bitmap(@"C:\08\letters\1\aa1.bmp", true));
    lookup.Add("B", new Bitmap(@"C:\08\letters\1\b1.bmp", true));

现在,抢图像和价值我以下内容:

Now, to grab images and value I did following:

var target = lookup.ToList();
bitmap b1 = target[j].Value; //grab value
//if value = cropped bitmap => proceed
string key = target[j].Key; //grab key



如何将根据您的解决方案这一过程改变抢到关键

How will this process change according to your solution?

诗我曾经听说过System.Linq.Lookup(中TKEY的,TElement),但在此之前从未使用过它。将这种查找帮我解决我的问题,或者它是一个完全不同的工具?谷歌不很了解或者,这样的例子将受到欢迎。

P.s. I have heard of "System.Linq.Lookup(Of TKey, TElement)", but never used it before. Will this "lookup" help me solve my problem or is it a completely different tool? google doesn't know much about it either, so an example would be welcomed

请注意,我加载字典只有一次,在程序开始,所以它不要紧,如何快速增加的。
查找,另一边是最困扰我的。
我在我的两个词典的120元,并根据本文的 http://www.dotnetperls.com/dictionary-time - 查找在列表中更慢,比字典..

please note, that I load dictionary only once, at program start, so it doesn't matter how fast adding is. Lookup, on the other side is what bothers me the most. I have 120 elements in two of my dictionaries, and according to this article http://www.dotnetperls.com/dictionary-time - Lookup in the List is much more slower, than in dictionary..

反正我会做一些措施来测试如何列出解决方案,建议如下 - 比较字典的解决方案,我现在和以后告诉结果,大概今天晚上

anyway I'll be doing some measures to test out how List solution that was suggested below - compares to Dictionary solution which I have right now and tell the results later, probably this evening.

推荐答案

查找。它基本上是关键值列表的字典,而不是关键价值。

Lookup. It is basically a dictionary of Key to list of Values, instead of key to value.

lookup.Add("a", "123"); // creates 'a' key and adds '123' to it
lookup.Add("a", "456"); // adds '456' to existing 'a' key
lookup.Add("b", "000"); // creates 'b' key and adds '000' to it

这篇关于添加多个位值词典使用C#一键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆