当前位置: 首页>>代码示例>>C#>>正文


C# Image.getEdge方法代码示例

本文整理汇总了C#中System.Image.getEdge方法的典型用法代码示例。如果您正苦于以下问题:C# Image.getEdge方法的具体用法?C# Image.getEdge怎么用?C# Image.getEdge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Image的用法示例。


在下文中一共展示了Image.getEdge方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Recognize

        public Tuple<string, int> Recognize(Image<Gray, byte> src)
        {
            var list = src.getEdge().Sample(100);

            #region 计算形状上下文
            int r = 15;
            var scall = Jim.OCR.ShapeContext2D.ShapeContext.ComputeSC(list);
            var scq = new double[r, 60];
            for (int i = 0; i < r; ++i) {
                int pos = rand.Next(list.Count);
                for (int k = 0; k < 60; ++k) {
                    scq[i, k] = scall[pos, k];
                }
            }
            #endregion
            #region 计算距离
            var dists = new ValueIndexPair<double>[SC.template_sc.Length];
            for (int i = 0; i < SC.template_sc.Length; ++i) {
                double[,] sci = SC.template_sc[i];
                double[,] costmat = Jim.OCR.ShapeContext2D.ShapeContext.HistCost(scq, sci);
                double cost = 0;
                for (int j = 0; j < r; ++j) {
                    double min = double.MaxValue;
                    for (int u = 0; u < 100; ++u) {
                        double val = costmat[j, u];
                        if (val < min) min = val;
                    }
                    cost += min;
                }
                dists[i] = new ValueIndexPair<double> { Value = cost, Index = i };
            }
            #endregion

            #region 对结果排序
            var arr = dists
                .OrderBy(p => p.Value)
                .Select(p => new { Distance = p.Value, Char = SC.template_chars[p.Index] })
                //.Where(p => "ABCDEFGHIJKLMNPQRSTUVWXYZ123456789".IndexOf(p.Char) != -1)
                .Where(p => Filter.IndexOf(p.Char) != -1)
                .ToArray();
            Dictionary<string, int> matchcount = new Dictionary<string, int>();
            foreach (var pair in arr.Take(Knn)) {
                string ch = pair.Char;
                matchcount[ch] = matchcount.ContainsKey(ch) ? matchcount[ch] + 1 : 1;
            }
            var match = matchcount.Select(pair => new { Count = pair.Value, Ch = pair.Key })
                                  .Where(v => v.Count > 0)
                                  .OrderByDescending(v => v.Count).ToArray();
            //string result = "";
            //foreach (var m in match.Take(3)) {
            //    result += String.Format("Char:'{0}',Accuracy:{1}/{2}\t", m.Ch, m.Count, knn);
            //}
            #endregion

            return new Tuple<string, int> { First = match[0].Ch, Second = match[0].Count };
        }
开发者ID:pakerliu,项目名称:sharp-context,代码行数:56,代码来源:RSCSingle.cs

示例2: Recognize

        public Tuple<string, int> Recognize(Image<Gray, byte> challenge)
        {
            var list = challenge.getEdge().Sample(100);
            var sc = ShapeContext.ComputeSC2(list);
            if (sc.Length < 100) {
                var tmp = new double[100][];
                for (int i = 0; i < 100; ++i) tmp[i] = new double[60];
                for (int i = 0; i < sc.Length; ++i) {
                    Array.Copy(sc[i], tmp[i], 60);
                }
                sc = tmp;
            }

            #region 量化到shapeme
            int[] histogram = new int[100];
            for (int i = 0; i < 100; ++i) {
                double[] ds = new double[100];
                for (int j = 0; j < 100; ++j)
                    ds[j] = ShapeContext.HistCost(sc[i], SC.shapemes[j]);
                int id = ds.Select((v, idx) => new ValueIndexPair<double> { Value = v, Index = idx })
                           .OrderBy(p => p.Value)
                           .First().Index;
                ++histogram[id];
            }
            #endregion
            #region 计算距离
            double[] dists = new double[SC.template_histograms.Length];
            for (int i = 0; i < SC.template_histograms.Length; ++i) {
                dists[i] = Jim.OCR.ShapeContext2D.ShapeContext.ChiSquareDistance(histogram, SC.template_histograms[i]);
                //dists[i] = Jim.OCR.ShapeContext2D.ShapeContext.HistCost(histogram.Cast<double>().ToArray(), templatehistograms[i].Cast<double>().ToArray());
            }
            #endregion

            #region 对结果排序
            var arr = dists.Select((d, i) => new ValueIndexPair<double> { Value = d, Index = i })
                .OrderBy(p => p.Value)
                .Select(p => new { Distance = p.Value, Char = SC.template_chars[p.Index] })
                //.Where(p => "ABCDEFGHIJKLMNPQRSTUVWXYZ123456789".IndexOf(p.Char) != -1)
                .Where(p => Filter.IndexOf(p.Char) != -1)
                .ToArray();
            Dictionary<string, int> matchcount = new Dictionary<string, int>();
            foreach (var pair in arr.Take(Knn)) {
                string ch = pair.Char;
                matchcount[ch] = matchcount.ContainsKey(ch) ? matchcount[ch] + 1 : 1;
            }
            var match = matchcount.Select(pair => new { Count = pair.Value, Ch = pair.Key })
                                  .Where(v => v.Count > 0)
                                  .OrderByDescending(v => v.Count).ToArray();
            //string result = "";
            //foreach (var m in match.Take(3)) {
            //    result += String.Format("Char:'{0}',Accuracy:{1}/{2}\t", m.Ch, m.Count, Knn);
            //}
            #endregion

            return new Tuple<string, int> { First = match[0].Ch, Second = match[0].Count };
        }
开发者ID:pakerliu,项目名称:sharp-context,代码行数:56,代码来源:ShapemeSingle.cs


注:本文中的System.Image.getEdge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。