Esempio n. 1
0
        protected override void RenderFrame()
        {
            GL.Color4(Color4.White);

            if (backgroundSubtractionData != null)
            {
                if (backgroundSubtractionData.Image != null)
                {
                    if (labelImage == null || labelImage.Size != backgroundSubtractionData.Image.Size)
                    {
                        labelImage = new IplImage(backgroundSubtractionData.Image.Size, IplDepth.U8, 4);
                    }
                }

                labelImage.SetZero();
                GL.Disable(EnableCap.Texture2D);
                using (var labelBitmap = new Bitmap(labelImage.Width, labelImage.Height, labelImage.WidthStep, System.Drawing.Imaging.PixelFormat.Format32bppArgb, labelImage.ImageData))
                    using (var graphics = Graphics.FromImage(labelBitmap))
                    {
                        graphics.SmoothingMode = SmoothingMode.AntiAlias;
                        GL.Enable(EnableCap.Texture2D);
                        labelTexture.Update(labelImage);
                        labelTexture.Draw();
                    }
            }
        }
Esempio n. 2
0
        protected override void RenderFrame()
        {
            GL.Color4(Color4.White);
            base.RenderFrame();

            if (tailPoints != null)
            {
                GL.PointSize(5 * VisualizerCanvas.Height / 640f);
                if (labelImage == null || labelImage.Size != tailPoints.Image.Size)
                {
                    labelImage = new IplImage(tailPoints.Image.Size, IplDepth.U8, 4);
                }

                labelImage.SetZero();
                GL.Disable(EnableCap.Texture2D);
                GL.Begin(PrimitiveType.Points);
                using (var labelBitmap = new Bitmap(labelImage.Width, labelImage.Height, labelImage.WidthStep, System.Drawing.Imaging.PixelFormat.Format32bppArgb, labelImage.ImageData))
                    using (var graphics = Graphics.FromImage(labelBitmap))
                    {
                        graphics.SmoothingMode = SmoothingMode.AntiAlias;
                        for (int i = 0; i < tailPoints.Points.Length; i++)
                        {
                            GL.Color3(1.0, 0.0, 0.0);
                            GL.Vertex2(NormalizePoint(tailPoints.Points[i], tailPoints.Image.Size));
                        }
                        GL.End();

                        GL.Color4(Color4.White);
                        GL.Enable(EnableCap.Texture2D);
                        labelTexture.Update(labelImage);
                        labelTexture.Draw();
                    }
            }
        }
Esempio n. 3
0
        protected override void RenderFrame()
        {
            GL.Color4(Color4.White);

            if (centroidData != null && centroidData.Image != null && centroidData.ThresholdImage != null)
            {
                GL.PointSize(5 * VisualizerCanvas.Height / 640f);
                if (labelImage == null || labelImage.Size != centroidData.Image.Size)
                {
                    labelImage = new IplImage(centroidData.Image.Size, IplDepth.U8, 4);
                }

                labelImage.SetZero();
                GL.Disable(EnableCap.Texture2D);
                using (var labelBitmap = new Bitmap(labelImage.Width, labelImage.Height, labelImage.WidthStep, System.Drawing.Imaging.PixelFormat.Format32bppArgb, labelImage.ImageData))
                    using (var graphics = Graphics.FromImage(labelBitmap))
                    {
                        graphics.SmoothingMode = SmoothingMode.AntiAlias;
                        GL.Color4(1.0, 0.0, 0.0, 1.0);
                        GL.Begin(PrimitiveType.Points);
                        GL.Vertex2(Utilities.NormalizePoint(centroidData.Centroid, centroidData.Image.Size));
                        GL.End();
                        GL.Color4(Color4.White);
                        GL.Enable(EnableCap.Texture2D);
                        labelTexture.Update(labelImage);
                        labelTexture.Draw();
                    }
            }
        }
Esempio n. 4
0
        protected override void RenderFrame()
        {
            GL.Color4(Color4.White);
            base.RenderFrame();

            if (pose != null)
            {
                GL.PointSize(5 * VisualizerCanvas.Height / 640f);
                if (labelImage == null || labelImage.Size != pose.Image.Size)
                {
                    labelImage = new IplImage(pose.Image.Size, IplDepth.U8, 4);
                    var emSize = VisualizerCanvas.Font.SizeInPoints * (labelImage.Height * LabelFontScale) / VisualizerCanvas.Font.Height;
                    labelFont = new Font(VisualizerCanvas.Font.FontFamily, emSize);
                }

                labelImage.SetZero();
                GL.Disable(EnableCap.Texture2D);
                GL.Begin(PrimitiveType.Points);
                using (var labelBitmap = new Bitmap(labelImage.Width, labelImage.Height, labelImage.WidthStep, System.Drawing.Imaging.PixelFormat.Format32bppArgb, labelImage.ImageData))
                    using (var graphics = Graphics.FromImage(labelBitmap))
                        using (var format = new StringFormat())
                        {
                            graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
                            graphics.SmoothingMode     = SmoothingMode.AntiAlias;
                            format.Alignment           = StringAlignment.Center;
                            format.LineAlignment       = StringAlignment.Center;
                            for (int i = 0; i < pose.Count; i++)
                            {
                                var hue = 180f - (i * 180f / pose.Count);
                                convertBuffer[0] = new Scalar(hue, 255, 255);
                                CV.CvtColor(convertBuffer, convertBuffer, ColorConversion.Hsv2Bgr);
                                var color = convertBuffer[0];

                                var bodyPart = pose[i];
                                var position = bodyPart.Position;
                                GL.Color3(color.Val2 / 255, color.Val1 / 255, color.Val0 / 255);
                                GL.Vertex2(NormalizePoint(position, pose.Image.Size));
                                graphics.DrawString(bodyPart.Name, labelFont, Brushes.White, position.X, position.Y);
                            }
                        }
                GL.End();

                GL.Color4(Color4.White);
                GL.Enable(EnableCap.Texture2D);
                labelTexture.Update(labelImage);
                labelTexture.Draw();
            }
        }
        protected override void RenderFrame()
        {
            GL.Color4(Color4.White);

            if (multiAnimalTrackingData != null && multiAnimalTrackingData.Image != null && multiAnimalTrackingData.OrderedCentroids != null)
            {
                if (labelImage == null || labelImage.Size != multiAnimalTrackingData.Image.Size)
                {
                    labelImage = new IplImage(multiAnimalTrackingData.Image.Size, IplDepth.U8, 4);
                }
                labelImage.SetZero();
                GL.PointSize(5 * VisualizerCanvas.Height / 640f);
                GL.Disable(EnableCap.Texture2D);
                while (randomColors.Count < multiAnimalTrackingData.OrderedCentroids.Length)
                {
                    Color randomColor = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256));
                    randomColors.Add(randomColor);
                }
                using (var labelBitmap = new Bitmap(labelImage.Width, labelImage.Height, labelImage.WidthStep, System.Drawing.Imaging.PixelFormat.Format32bppArgb, labelImage.ImageData))
                    using (var graphics = Graphics.FromImage(labelBitmap))
                    {
                        graphics.SmoothingMode = SmoothingMode.AntiAlias;
                        try
                        {
                            for (int i = 0; i < multiAnimalTrackingData.OrderedCentroids.Length; i++)
                            {
                                GL.Color4(randomColors[i].R, randomColors[i].G, randomColors[i].B, randomColors[i].A);
                                //GL.Color4(1.0, 0.0, 0.0, 1.0);
                                GL.Begin(PrimitiveType.Points);
                                GL.Vertex2(Utilities.NormalizePoint(multiAnimalTrackingData.OrderedCentroids[i], multiAnimalTrackingData.Image.Size));
                            }
                        }
                        finally
                        {
                            GL.End();
                            GL.Color4(Color4.White);
                            GL.Enable(EnableCap.Texture2D);
                            labelTexture.Update(labelImage);
                            labelTexture.Draw();
                        }
                    }
            }
        }
        protected override void OnRenderFrame(EventArgs e)
        {
            base.OnRenderFrame(e);
            var image = Image;

            if (image != null)
            {
                GL.Disable(EnableCap.Texture2D);
                GL.Color3(Color.White);
                GL.Enable(EnableCap.Texture2D);
                if (labelImage != null)
                {
                    if (refreshLabels)
                    {
                        UpdateLabelTexture();
                        refreshLabels = false;
                    }
                    labelTexture.Draw();
                }
            }
        }
        protected override void RenderFrame()
        {
            GL.Color4(Color4.White);
            base.RenderFrame();

            if (tailPoints.Length != 0)
            {
                if (labelImage == null || labelImage.Size != imageSize)
                {
                    labelImage = new IplImage(imageSize, IplDepth.U8, 4);
                }

                labelImage.SetZero();
                GL.Disable(EnableCap.Texture2D);
                using (var labelBitmap = new Bitmap(labelImage.Width, labelImage.Height, labelImage.WidthStep, System.Drawing.Imaging.PixelFormat.Format32bppArgb, labelImage.ImageData))
                    using (var graphics = Graphics.FromImage(labelBitmap))
                    {
                        graphics.SmoothingMode = SmoothingMode.AntiAlias;
                        GL.LineWidth(3 * VisualizerCanvas.Height / 640f);
                        try
                        {
                            for (int i = 0; i < tailPoints.Length - 1; i++)
                            {
                                GL.Begin(PrimitiveType.Lines);
                                GL.Color4(1.0, 0.0, 0.0, 1.0);
                                GL.Vertex2(Utilities.NormalizePointForTailAngle(tailPoints[i], Math.Atan2(tailPoints[i].Y - tailPoints[i + 1].Y, tailPoints[i].X - tailPoints[i + 1].X), imageSize));
                                GL.Vertex2(Utilities.NormalizePointForTailAngle(tailPoints[i + 1], Math.Atan2(tailPoints[i + 1].Y - tailPoints[i].Y, tailPoints[i + 1].X - tailPoints[i].X), imageSize));
                                GL.End();
                            }
                        }
                        finally
                        {
                            GL.Color4(Color4.White);
                            GL.Enable(EnableCap.Texture2D);
                            labelTexture.Update(labelImage);
                            labelTexture.Draw();
                        }
                    }
            }
        }