Stereo anaglyph filter.

The image processing filter produces stereo anaglyph images which are aimed to be viewed through anaglyph glasses with red filter over the left eye and cyan over the right.

The stereo image is produced by combining two images of the same scene taken from a bit different points. The right image must be provided to the filter using BaseInPlaceFilter2.OverlayImage property, but the left image must be provided to IFilter.Apply(Bitmap) method, which creates the anaglyph image.

The filter accepts 24 bpp color images for processing.

See Algorithm enumeration for the list of supported anaglyph algorithms.

Sample usage:

// create filter StereoAnaglyph filter = new StereoAnaglyph( ); // set right image as overlay filter.Overlay = rightImage // apply the filter (providing left image) Bitmap resultImage = filter.Apply( leftImage );

Source image (left):

Overlay image (right):

Result image:

Inheritance: BaseInPlaceFilter2
Exemplo n.º 1
0
        // Create stereo anaglyph using current image as the "left" image
        private void CreateStereoAnaglyph( StereoAnaglyph.Algorithm algorithm )
        {
            // get overlay image
            Bitmap overlayImage = host.GetImage( this, "Select an image which should be used as the 'right' image for stereo anaglyph.",
                new Size( width, height ), image.PixelFormat );

            if ( overlayImage != null )
            {
                StereoAnaglyph filter = new StereoAnaglyph( algorithm );
                filter.OverlayImage = overlayImage;

                ApplyFilter( filter );
            }
        }
Exemplo n.º 2
0
        private void FinalVideoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            // Unregister the event until we get finished with this frame...
            FinalVideoSource.NewFrame -= new NewFrameEventHandler(FinalVideoSource_NewFrame);
            Bitmap image = (Bitmap)eventArgs.Frame.Clone();                                                     // Get a local copy from the event
            if (PictureTime)                                                                                    // Take a 3D snapshot
            {
                StereoAnaglyph SAfilter = new StereoAnaglyph( );
                // set right image as overlay
                SAfilter.OverlayImage = filterR.Apply(image);
                // apply the filter (providing left image)
                SavePic = SAfilter.Apply(filterL.Apply(image));
                PictureTime = false;
            }

            // Not taking a picture, handle this as a normal frame
            if (background == null)                                                                         // This will pass the first time or when we nuke the background var
            {
                background = new Bitmap(xMax, yMax);
                background = Grayscale.CommonAlgorithms.BT709.Apply(image);
            }
            else                                                                                            // The rest of the time lets do this...
            {
                hand.ClearFingers();                                                                        // Since this is a new data frame, let's clear the old data
                ProcessImage(image);                                                                        // Process the frame
            }
            image.Dispose();

            // Re-register for the event now that we are done
            FinalVideoSource.NewFrame += new NewFrameEventHandler(FinalVideoSource_NewFrame);
        }
Exemplo n.º 3
0
        private static void Create3DVideo(Cam leftCam, Cam rightCam)
        {
            if (leftCam == null) throw new ArgumentNullException("leftCam");
            if (rightCam == null) throw new ArgumentNullException("rightCam");

            string camSaveDirectory = PrepareSaveDirectory(leftCam.CamContainer);
            string videoFileName = String.Format("{0}{1} {2}.mpeg", camSaveDirectory, leftCam.CamContainer, DateTime.Now.ToString("MMM-dd-yyyy-HH-mm"));

            if (File.Exists(videoFileName))
                File.Delete(videoFileName);

            try
            {
                using (VideoFileWriter videoWriter = new VideoFileWriter())
                {
                    videoWriter.Open(videoFileName, MslCamConstants.FullDataProductWidth, MslCamConstants.FullDataProductHeight);

                    int totalImageCount = 0;
                    using (MSLScraperEntities mslContext = new MSLScraperEntities())
                    {
                        totalImageCount = (from A in
                                               (from a1 in mslContext.SolImageData where a1.Cam.Contains(leftCam.CamName) select a1)
                                           from B in
                                               (from b1 in mslContext.SolImageData where b1.Cam.Contains(rightCam.CamName) select b1)
                                           where A.Sol == B.Sol && A.TimeStamp == B.TimeStamp select A).Count();
                    }

                    int take = 15;
                    int processedCount = 0;
                    for (int skip = 0; skip < totalImageCount; skip = skip + take)
                    {
                        using (MSLScraperEntities mslContext = new MSLScraperEntities())
                        {
                            var imagesToProcess = (from A in
                                                       (from a1 in mslContext.SolImageData where a1.Cam.Contains(leftCam.CamName) select a1)
                                                   from B in
                                                       (from b1 in mslContext.SolImageData where b1.Cam.Contains(rightCam.CamName) select b1)
                                                   where A.Sol == B.Sol && A.TimeStamp == B.TimeStamp
                                                   orderby A.TimeStamp
                                                   select new { LeftCam = A, RightCam = B }).Skip(skip).Take(take);
                            
                            foreach (var imagePair in imagesToProcess)
                            {
                                using (MemoryStream msLeft = new MemoryStream(imagePair.LeftCam.ImageData))
                                using (Bitmap bitmapLeft = (Bitmap)Image.FromStream(msLeft))
                                using (MemoryStream msRight = new MemoryStream(imagePair.RightCam.ImageData))
                                using (Bitmap bitmapRight = (Bitmap)Image.FromStream(msRight))
                                {
                                    if (bitmapLeft.Width == videoWriter.Width && bitmapLeft.Height == videoWriter.Height &&
                                        bitmapRight.Width == videoWriter.Width && bitmapRight.Height == videoWriter.Height)
                                    {
                                        StereoAnaglyph filter = new StereoAnaglyph(StereoAnaglyph.Algorithm.GrayAnaglyph);
                                        filter.OverlayImage = AForge.Imaging.Image.Clone(bitmapRight, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                                        
                                        using (Bitmap bitmap3D = filter.Apply(AForge.Imaging.Image.Clone(bitmapLeft, System.Drawing.Imaging.PixelFormat.Format24bppRgb)))
                                        using (Bitmap newBitmap = new Bitmap(bitmapLeft.Width, bitmapLeft.Height))
                                        using (Graphics g = Graphics.FromImage(newBitmap))
                                        {
                                            g.DrawImage(bitmap3D, 0, 0);
                                            g.DrawString(String.Format("{0} - Sol: {1}", leftCam.CamContainer, imagePair.LeftCam.Sol), new Font(FontFamily.GenericSansSerif, 30, FontStyle.Bold), Brushes.White, new PointF(10, 10));

                                            for (int i = 0; i < 4; i++)
                                            {
                                                videoWriter.WriteVideoFrame(newBitmap);
                                            }
                                        }
                                    }
                                }

                                processedCount++;
                                Console.Clear();
                                Console.WriteLine(string.Format("3D processing: {0} of {1} images processed for {2}", processedCount, totalImageCount, leftCam.CamContainer));
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string errorMessage = String.Format("ERROR while creating 3D video for {0}", leftCam.CamContainer);
                Console.WriteLine(String.Format("{0}: {1}", errorMessage, ex.Message));
                errorCollection.Enqueue(new Exception(errorMessage, ex));
            }
        }