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


C# Point3.update方法代码示例

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


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

示例1: Pool

        // Uses the per-pixel classes from PredictGPU to pool the location of 
        // gestures. Supports multiple types of pooling algorithms. Each 
        // algorithm is described before each section.
        private static List<Pooled> Pool(PoolType type, ProcessorState state)
        {
            List<Pooled> gestures = new List<Pooled>();
            System.Drawing.Point center;
            int[] label_counts;
            Tuple<int, int> max;

            switch (type)
            {
                #region KMeans
                case PoolType.KMeans:
                    Random rand = new Random();
                    Point3 p = new Point3(0, 0, 0); 
                    int K = 7, num_changes = 10, iterations = 0;

                    List<Point3> centroids = new List<Point3>(K);
                    for (int i = 0; i < K; i++)
                        centroids.Insert(i, new Point3(
                            rand.Next(width),
                            rand.Next(height),
                            rand.Next(400, 1500)
                            ));

                    List<HashSet<int>> clusters = new List<HashSet<int>>(K);
                    for (int i = 0; i < K; i++) clusters.Insert(i, new HashSet<int>());

                    Dictionary<int, int> assignments = new Dictionary<int,int>();
                    for (int i = 0; i < state.depth.Length; i++)
                        if (state.predict_labels_[i] != (int)HandGestureFormat.Background)
                        {
                            int cluster = rand.Next(K);
                            assignments.Add(i, cluster);
                            clusters[cluster].Add(i);
                        }
                    
                    List<int> points = new List<int>(assignments.Keys);

                    // If there have been no changes, the centroids wont 
                    // change either so KMeans has found a minimum. This may
                    // be a local minimum. 
                    #region KMeans, can be factored out
                    while (num_changes > 0)
                    {
                        num_changes = 0;
                        iterations++;

                        if (iterations % 10 == 0)
                            Console.WriteLine("Iteration {0}", iterations);

                        // Update centroids
                        for (int i = 0; i < K; i++)
                        {
                            int x = (int)clusters[i].Average(point => Util.toXY(point, width, height, kDepthStride).X);
                            int y = (int)clusters[i].Average(point => Util.toXY(point, width, height, kDepthStride).Y);
                            int depth = (int)clusters[i].Average(point => state.depth[point]);

                            centroids[i].update(x, y, depth);
                        }

                        // Update classifications
                        foreach (int point in points)
                        {
                            System.Drawing.Point xy = Util.toXY(point, width, height, kDepthStride);
                            p.update(xy.X, xy.Y, state.depth[point]);
                            int nearest = 0;
                            double nearest_distance = Util.EuclideanDistance(centroids[nearest], p);
                            for (int i = 1; i < K; i++)
                            {
                                double distance = Util.EuclideanDistance(centroids[i], p);
                                if (distance < nearest_distance)
                                {
                                    nearest = i;
                                    nearest_distance = distance;
                                }
                            }


                            if (assignments[point] != nearest && clusters[assignments[point]].Count != 1)
                            {
                                num_changes++;
                                clusters[assignments[point]].Remove(point);
                                clusters[nearest].Add(point);
                                assignments[point] = nearest;
                            }
                        }
                    }
                    #endregion

                    // Fit a Gaussian distribution on all the cluster sizes 
                    // and look for outliers that are at least two standard
                    // deviations away from the mean.
                    #region Gaussian outlier detection
                    // Print the distribution of sizes within clusters
                    var sizes = clusters.Select(cluster => cluster.Count).
                                  OrderByDescending(val => val).ToArray();

                    // Fit normal distribution and look for outliers
//.........这里部分代码省略.........
开发者ID:arunganesan,项目名称:hand-gesture-recognition,代码行数:101,代码来源:Filter.cs


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