public void Calculate(IntermediateResults intermediateResults)
        {
            Opacity = intermediateResults.GreatestOpacity / 255.0;
            SetCameraAndHeadPoint(intermediateResults);

            RightShoulder = GetPoint(intermediateResults.Red);
            LeftShoulder  = GetPoint(intermediateResults.Blue);
            double x = Math.Round((RightShoulder.X + LeftShoulder.X) / 2, 1);
            double y = Math.Round((RightShoulder.Y + LeftShoulder.Y) / 2, 1);

            Origin = new Point2d(x, y);
            CalculateScale();
            if (Scale == 0)
            {
                Opacity  = 0;
                Scale    = 1;
                Rotation = 0;
            }
            else
            {
                CalculateRotation();
            }

            CalculateFlipped();
        }
Example #2
0
        private static void ProcessLine(DirectBitmap bitmap, int y, IntermediateResults intermediateResults, int xOffset, int yOffset)
        {
            // We have to detect four colors: red, blue, green, yellow (means use profile camera)
            for (int x = 0; x < bitmap.Width; x++)
            {
                System.Drawing.Color pixel = bitmap.GetPixel(x, y);
                //if (pixel.A < 5)
                //	continue;
                if (pixel.A > intermediateResults.GreatestOpacity)
                {
                    intermediateResults.GreatestOpacity = pixel.A;
                }

                if (pixel.R > 0)                 // Could be red or yellow or magenta.
                {
                    if (pixel.G > 0 && AreClose(pixel.R, pixel.G))
                    {
                        intermediateResults.Yellow.Add(x + xOffset, y + yOffset, pixel.A);
                        continue;
                    }
                    else if (pixel.B > 0 && AreClose(pixel.R, pixel.B))
                    {
                        intermediateResults.Magenta.Add(x + xOffset, y + yOffset, pixel.A);
                        continue;
                    }
                    intermediateResults.Red.Add(x + xOffset, y + yOffset, pixel.A);
                    continue;
                }
                if (pixel.G > 0)
                {
                    if (pixel.B > 0 && AreClose(pixel.G, pixel.B))
                    {
                        intermediateResults.Cyan.Add(x + xOffset, y + yOffset, pixel.A);
                        continue;
                    }
                    intermediateResults.Green.Add(x + xOffset, y + yOffset, pixel.A);
                    continue;
                }
                if (pixel.B > 0)
                {
                    intermediateResults.Blue.Add(x + xOffset, y + yOffset, pixel.A);
                    continue;
                }
            }
        }
Example #3
0
        public static ObsTransform GetVisualProcessingResults(string fileName)
        {
            ObsTransform        results             = new ObsTransform();
            IntermediateResults intermediateResults = new IntermediateResults();

            using (DirectBitmap bitmap = DirectBitmap.FromFile(fileName))
            {
                int line         = 0;
                int bitmapWidth  = bitmap.Width;
                int bitmapHeight = bitmap.Height;
                int xOffset      = bitmapWidth > 1920 ? -(bitmapWidth - 1920) / 2 : 0;
                int yOffset      = bitmapHeight > 1080 ? -(bitmapHeight - 1080) / 2 : 0;

                while (line < bitmapHeight)
                {
                    ProcessLine(bitmap, line, intermediateResults, xOffset, yOffset);
                    line++;
                }
                //intermediateResults.FindCircleCenters(bitmap);
            }

            results.Calculate(intermediateResults);
            return(results);
        }
        void SetCameraAndHeadPoint(IntermediateResults intermediateResults)
        {
            int greenCount   = intermediateResults.Green.Count;
            int yellowCount  = intermediateResults.Yellow.Count;
            int cyanCount    = intermediateResults.Cyan.Count;
            int magentaCount = intermediateResults.Magenta.Count;

            if (cyanCount == 0 && yellowCount == 0 && greenCount == 0 && magentaCount == 0)
            {
                Camera    = INT_Camera0Green;
                HeadPoint = new Point2d(-1920, 0);
                return;
            }

            if (greenCount > yellowCount)
            {
                if (greenCount > cyanCount)
                {
                    if (greenCount > magentaCount)
                    {
                        Camera    = INT_Camera0Green;
                        HeadPoint = GetPoint(intermediateResults.Green);
                    }
                    else
                    {
                        Camera    = INT_Camera3Magenta;
                        HeadPoint = GetPoint(intermediateResults.Magenta);
                    }
                }
                else                 // cyanCount is greater than or equal to green.
                {
                    if (cyanCount > magentaCount)
                    {
                        Camera    = INT_Camera2Cyan;
                        HeadPoint = GetPoint(intermediateResults.Cyan);
                    }
                    else
                    {
                        Camera    = INT_Camera3Magenta;
                        HeadPoint = GetPoint(intermediateResults.Magenta);
                    }
                }
            }
            else              // yellow is greater than or equal to green.
            {
                if (yellowCount > cyanCount)
                {
                    if (yellowCount > magentaCount)
                    {
                        Camera    = INT_Camera1Yellow;
                        HeadPoint = GetPoint(intermediateResults.Yellow);
                    }
                    else
                    {
                        Camera    = INT_Camera3Magenta;
                        HeadPoint = GetPoint(intermediateResults.Magenta);
                    }
                }
                else                 // cyanCount is greater than or equal to yellow.
                {
                    if (cyanCount > magentaCount)
                    {
                        Camera    = INT_Camera2Cyan;
                        HeadPoint = GetPoint(intermediateResults.Cyan);
                    }
                    else
                    {
                        Camera    = INT_Camera3Magenta;
                        HeadPoint = GetPoint(intermediateResults.Magenta);
                    }
                }
            }
        }