Exemple #1
0
 public void Show(object value)
 {
     using (var inputImage = (IplImage)value)
     {
         visualizerImage = IplImageHelper.EnsureImageFormat(visualizerImage, inputImage.Size, inputImage.Depth, inputImage.Channels);
         CV.Copy(inputImage, visualizerImage);
     }
     value = null;
 }
Exemple #2
0
        public void Update(IplImage image)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }
            if (image.Depth != IplDepth.U8)
            {
                double min, max;
                Point  minLoc, maxLoc;
                normalizedImage = IplImageHelper.EnsureImageFormat(normalizedImage, image.Size, IplDepth.U8, image.Channels);
                using (var buffer = image.Reshape(1, 0))
                {
                    CV.MinMaxLoc(buffer, out min, out max, out minLoc, out maxLoc);
                }

                var range = max - min;
                var scale = range > 0 ? 255.0 / range : 0;
                var shift = range > 0 ? -min : 0;
                CV.ConvertScale(image, normalizedImage, scale, shift * scale);
                image = normalizedImage;
            }

            if (!nonPowerOfTwo || image.Width > maxTextureSize || image.Height > maxTextureSize)
            {
                var textureWidth  = Math.Min(maxTextureSize, NearestPowerOfTwo(image.Width));
                var textureHeight = Math.Min(maxTextureSize, NearestPowerOfTwo(image.Height));
                textureImage = IplImageHelper.EnsureImageFormat(textureImage, new Size(textureWidth, textureHeight), image.Depth, image.Channels);
                CV.Resize(image, textureImage, SubPixelInterpolation.Linear);
                image = textureImage;
            }

            OpenTK.Graphics.OpenGL.PixelFormat pixelFormat;
            switch (image.Channels)
            {
            case 1: pixelFormat = OpenTK.Graphics.OpenGL.PixelFormat.Luminance; break;

            case 2: pixelFormat = OpenTK.Graphics.OpenGL.PixelFormat.Rg; break;

            case 3: pixelFormat = OpenTK.Graphics.OpenGL.PixelFormat.Bgr; break;

            case 4: pixelFormat = OpenTK.Graphics.OpenGL.PixelFormat.Bgra; break;

            default: throw new ArgumentException("Image has an unsupported number of channels.", "image");
            }

            GL.BindTexture(TextureTarget.Texture2D, texture);
            GL.PixelStore(PixelStoreParameter.UnpackRowLength, image.WidthStep / image.Channels);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, image.Width, image.Height, 0, pixelFormat, PixelType.UnsignedByte, image.ImageData);
        }