Example #1
0
 public OpenCVCamera(int cameraIndex, Size textureSize)
 {
     Texture = new GLTextureObject(textureSize);
     this.Texture.TextureUnit = TextureUnit.Texture8;
     _capture               = new Capture(cameraIndex);
     _capture.FlipType      = FLIP.VERTICAL;
     _capture.ImageGrabbed += new Capture.GrabEventHandler(_capture_ImageGrabbed);
 }
Example #2
0
		public OpenCVCamera(int cameraIndex, Size textureSize)
		{
			Texture = new GLTextureObject(textureSize);
			this.Texture.TextureUnit = TextureUnit.Texture8;
			_capture = new Capture(cameraIndex);
			_capture.FlipType = FLIP.VERTICAL;
			_capture.ImageGrabbed += new Capture.GrabEventHandler(_capture_ImageGrabbed);
		}
Example #3
0
        //private bool dumped;

        private void RenderTexToScreen(GLTextureObject tex)
        {
            this.visibleFbo.Bind();
            //Render texture to screen
            GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            tex.Bind();
            this.shader.SetUniform("FrameTx", tex.TextureUnit);
            this.shader.SetUniform("Mode", 0);
            RenderToFramebuffer();
            SwapBuffers();
        }
Example #4
0
        public TextureManager(Rectangle viewport, IEnumerable <string> textureNames)
        {
            Fbo = new GLFrameBufferObject(viewport);
            List <string> texNames = textureNames.ToList();

            texNames.Add("scratch");
            GLTextureObject curr;

            for (int i = 0; i < texNames.Count; i++)
            {
                this.textureNames.Add(texNames[i], TextureUnit.Texture0 + i);
                curr             = new GLTextureObject(viewport.Size, PixelInternalFormat.Rgb32f);
                curr.TextureUnit = TextureUnit.Texture0 + i;
                this.textures.Add(texNames[i], new KeyValuePair <GLTextureObject, FramebufferAttachment>(curr, FramebufferAttachment.ColorAttachment0 + i));
                Fbo.AttachTexture2D(FramebufferAttachment.ColorAttachment0 + i, curr.TextureId);
                Fbo.DrawBuffer = FramebufferAttachment.ColorAttachment0 + i;
            }
            Fbo.Validate(true);
        }
Example #5
0
		public FileCamera(IEnumerable<string> imageFiles, Size textureSize)
		{
			this.image_files = imageFiles.ToList();
			this.Texture = new GLTextureObject(textureSize);
			this.Texture.TextureUnit = TextureUnit.Texture8;
		}
Example #6
0
 public FileCamera(IEnumerable <string> imageFiles, Size textureSize)
 {
     this.image_files         = imageFiles.ToList();
     this.Texture             = new GLTextureObject(textureSize);
     this.Texture.TextureUnit = TextureUnit.Texture8;
 }
Example #7
0
        /// <summary>Load resources here.</summary>
        /// <param name="e">Not used.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.Texture2D);
            GL.Enable(EnableCap.CullFace);
            GL.CullFace(CullFaceMode.Back);

            GL.ClampColor(ClampColorTarget.ClampFragmentColor, ClampColorMode.False);
            GL.ClampColor(ClampColorTarget.ClampReadColor, ClampColorMode.False);

            //new GLTextureObject(new Bitmap(GetAbsolutePath("calib_img/big100.png"))).GetBitmapOfTexture().Save("/tmp/big100.bmp");

            this.shader = new GLShader(File.ReadAllText(GetAbsolutePath("shader.vert")), File.ReadAllText(GetAbsolutePath("calibrate.frag")));

            texManager = new TextureManager(new Rectangle(0, 0, WIDTH, HEIGHT), new string[] { "Sum", "Intermed", "StdDev", "AiBi" });

            visibleFbo = new GLVisibleFrameBufferObject(new Rectangle(0, 0, WIDTH, HEIGHT));
            visibleFbo.Bind();

            const int frameCount = 20;

            // Create camera
            camera = new FileCamera(
                Directory.GetFiles(GetAbsolutePath("calib_img"), "big*.png").Take(frameCount),
                new Size(WIDTH, HEIGHT)
                );
            this.inputTex = camera.Texture;

            // Set up render loop actions
            RenderActions = new List <Action>();
            for (int j = 0; j < frameCount; j++)
            {
                // Load the background frame
                Action <int> temp = (i) => {
                    Console.WriteLine("Loading BkgndFrame {0}", i);
                    //this.inputTex.Bind();
                    camera.UpdateTexture();
                    //camera.Texture.GetBitmapOfTexture().Save("/tmp/out.bmp");
                };
                this.RenderActions.Add(temp.Curry(j));

                // Process it for sum (average)
                temp = (i) => {
                    this.texManager.Bind();
                    Console.WriteLine("Sum");

                    this.shader.SetUniform("FrameTx", this.inputTex.TextureUnit);
                    this.shader.SetUniform("SumTx", texManager.GetTexture("Sum").TextureUnit);
                    this.shader.SetUniform("Mode", 1);
                    this.shader.SetUniform("NumFrames", (float)frameCount);

                    RenderToFramebuffer();

                    texManager.EndRender("Sum");
                };
                this.RenderActions.Add(temp.Curry(j));

                // Process it for SumSq
                temp = (i) => {
                    this.texManager.Bind();
                    Console.WriteLine("SumSq");

                    this.shader.SetUniform("FrameTx", this.inputTex.TextureUnit);
                    this.shader.SetUniform("IntermedTx", texManager.GetTexture("Intermed").TextureUnit);
                    this.shader.SetUniform("Mode", 2);
                    this.shader.SetUniform("NumFrames", (float)frameCount);

                    RenderToFramebuffer();

                    texManager.EndRender("Intermed");
                };
                this.RenderActions.Add(temp.Curry(j));
            }

            // stddev
            {
                // Take the StdDev now that we have the sum and sumsq
                Action temp = () => {
                    this.texManager.Bind();
                    Console.WriteLine("StdDev");

                    //this.shader.SetUniform("FrameTx", this.inputTex.TextureUnit);
                    this.shader.SetUniform("SumTx", texManager.GetTexture("Sum").TextureUnit);
                    this.shader.SetUniform("IntermedTx", texManager.GetTexture("Intermed").TextureUnit);
                    this.shader.SetUniform("Mode", 3);
                    this.shader.SetUniform("NumFrames", (float)frameCount);

                    RenderToFramebuffer();

                    texManager.EndRender("StdDev");
                };
                this.RenderActions.Add(temp);
            }

            // Second pass for alfi sum
            for (int j = 0; j < frameCount; j++)
            {
                // Load the background frame
                Action <int> temp = (i) => {
                    Console.WriteLine("Loading BkgndFrame {0}", i);
                    //this.inputTex.Bind();
                    camera.UpdateTexture();
                    //camera.Texture.GetBitmapOfTexture().Save("/tmp/out.bmp");
                };
                this.RenderActions.Add(temp.Curry(j));

                // Calculate AlfI (xi-1)**2/N and CDi sum
                temp = (i) => {
                    this.texManager.Bind();
                    Console.WriteLine("AlfISum");

                    this.shader.SetUniform("FrameTx", this.inputTex.TextureUnit);
                    this.shader.SetUniform("SumTx", texManager.GetTexture("Sum").TextureUnit);
                    this.shader.SetUniform("StdDevTx", texManager.GetTexture("StdDev").TextureUnit);
                    this.shader.SetUniform("IntermedTx", texManager.GetTexture("Intermed").TextureUnit);
                    this.shader.SetUniform("Mode", 4);
                    this.shader.SetUniform("NumFrames", (float)frameCount);

                    RenderToFramebuffer();

                    texManager.EndRender("AiBi");
                };
                this.RenderActions.Add(temp.Curry(j));
            }

            // calculate ai and bi
            {
                // Take ai and bi now that we have the intermed sums
                Action temp = () => {
                    this.texManager.Bind();
                    Console.WriteLine("AiBi");

                    //this.shader.SetUniform("FrameTx", this.inputTex.TextureUnit);
                    this.shader.SetUniform("IntermedTx", texManager.GetTexture("Intermed").TextureUnit);
                    this.shader.SetUniform("Mode", 5);
                    this.shader.SetUniform("NumFrames", (float)frameCount);

                    RenderToFramebuffer();

                    texManager.EndRender("AiBi");
                };
                this.RenderActions.Add(temp);
            }

            // calculate Ai,Bi,Ci,Di

            /*{
             *      Action temp = () => {
             *              this.texManager.Bind();
             *              Console.WriteLine("AiBi");
             *
             *              this.shader.SetUniform("FrameTx", this.inputTex.TextureUnit);
             *              this.shader.SetUniform("SumTx", texManager.GetTexture("Sum").TextureUnit);
             *              this.shader.SetUniform("StdDevTx", texManager.GetTexture("StdDev").TextureUnit);
             *              this.shader.SetUniform("Mode", 6);
             *              this.shader.SetUniform("NumFrames", (float)frameCount);
             *
             *              RenderToFramebuffer();
             *
             *              texManager.EndRender("AiBi");
             *      };
             *      this.RenderActions.Add(temp);
             * }*/
        }