Beispiel #1
0
        // http://www.w3.org/TR/AERT#color-contrast
        /// <summary>
        /// Sort RGB pixels by luminance (0.299 Red  0.587 Green 0.114 Blue)
        /// </summary>
        /// <param name="image">image OpenCv matrix</param>
        /// <returns>Sorted list</returns>
        private static List <Point3D> SortPixelsByLuminance(Mat image)
        {
            var image_indexer = GetByteVectorIndexer(image);

            //convert RGB to Point3D
            var rgb_points = new Point3DCollection();

            for (int i = 0; i < image.Width; i++)
            {
                for (int j = 0; j < image.Height; j++)
                {
                    var rgb1 = image_indexer[i, j];
                    rgb_points.Add(new Point3D((double)rgb1.Item2, (double)rgb1.Item1, (double)rgb1.Item0));
                }
            }

            // Sort RGB pixels by luminance 0.299 Red  0.587 Green  0.114 Blue
            // http://www.w3.org/TR/AERT#color-contrast
            var rgb_sorted_list = rgb_points.OrderBy(p => 0.299 * p.X + 0.587 * p.Y + 0.114 * p.Z).ToList();

            return(rgb_sorted_list);
        }
Beispiel #2
0
        private void GenerateTextureCordinatesFromPos()
        {
            var    templist = _Positions.OrderBy(x => x.X).ToList();
            double minx = templist[0].X, maxx = templist[templist.Count - 1].X;

            templist = _Positions.OrderBy(y => y.Y).ToList();
            double miny = templist[0].Y, maxy = templist[templist.Count - 1].Y;

            templist = _Positions.OrderBy(z => z.Z).ToList();
            double _minz = templist[0].Z, _maxz = templist[templist.Count - 1].Z;

            double zrange = _maxz - _minz;
            double zmean  = (_minz + _minz) / 2;
            double xrange = maxx - minx;
            double yrange = maxy - miny;

            double xyratio = (double)1920 / 1080;

            //keep the face width to 18% of the texture image
            double xratio = 0.18 / xrange;
            double yratio = xratio * xyratio;

            //offset to center of texture image
            double offsetx = 0.5 - ((minx + maxx) / 2) * xratio;
            double offsety = 0.5 + ((miny + maxy) / 2) * yratio;

            _TextureCoordinates = new PointCollection();

            //double MAX_MULTIPLIER_X = 0.055;
            //double MAX_MULTIPLIER_Y = 0.055;
            double CAM_Z_POS = 0.5;


            foreach (var newpoint in _Positions)
            {
                //the nearer to the camera, the greater the multiplier

                ////X multiplier
                //double zdeltaX = MAX_MULTIPLIER_X * (((newpoint.Z - _minz)) / (zrange));
                //double zratioX = 1 + zdeltaX;//1 + zdeltaX;

                ////Y multiplier
                //double zdeltaY = MAX_MULTIPLIER_Y * (((newpoint.Z - _minz)) / (zrange));
                //double zratioY = 1 + zdeltaY;//1 + zdeltaY;

                //Another way of looking at this..
                // double magnifier = (CAM_Z_POS - _minz) /  (CAM_Z_POS - newpoint.Z);

                // double magnifier = (0.5-MEAN_X_FROM_CAM) / (CAM_Z_POS - newpoint.Z -MEAN_X_FROM_CAM);

                double magnifierX = (CAM_Z_POS + 0.1) / (CAM_Z_POS - newpoint.Z);
                double magnifierY = (CAM_Z_POS + 0.1) / (CAM_Z_POS - newpoint.Z);
                double zratioX    = magnifierX;
                double zratioY    = magnifierY;

                double x = zratioX * newpoint.X * xratio + offsetx;

                //Y direction in World Coordinates is reverse of Texture Coordinate
                double y = -newpoint.Y * yratio * zratioY + offsety;

                _TextureCoordinates.Add(new Point(x, y));
            }
        }