예제 #1
0
        /// <summary>
        /// Helper function for creating video file
        /// </summary>
        /// <param name="imageList">Reference to list where frames are being added</param>
        /// <param name="aviFileName">Path to .avi file where video will save</param>
        /// <param name="frameRate">Video framerate to use</param>
        private void SaveAviHelper(ref List <ManagedImage> imageList, string aviFileName, float frameRate)
        {
            using (ManagedAVIRecorder aviRecorder = new ManagedAVIRecorder())
            {
                // Set MJPG codec options
                MJPGOption option = new MJPGOption();
                option.frameRate = frameRate;
                option.quality   = 90;

                aviRecorder.AVIOpen(aviFileName, option);

                // Write frames to video as they are being added
                int imageCnt = 0;
                while (this.Recording)
                {
                    // Don't write latest frame as it is incomplete
                    if (imageCnt < imageList.Count - 1)
                    {
                        aviRecorder.AVIAppend(imageList[imageCnt]);
                        imageList[imageCnt].Dispose(); // Dispose to save RAM
                        imageCnt++;
                    }
                }
                // Write remaining frames to file
                for (; imageCnt < imageList.Count; imageCnt++)
                {
                    aviRecorder.AVIAppend(imageList[imageCnt]);
                }
                // Close file
                aviRecorder.AVIClose();
            }
        }
예제 #2
0
        private void SaveAviHelper(AviType aviType, ref List <ManagedImage> imageList, string aviFileName, float frameRate)
        {
            // Set maximum AVI file size to 2GB. A new AVI file is generated when 2GB
            // limit is reached. Setting maximum file size to 0 indicates no limit.
            const uint AviMaxSize = 2048;

            using (ManagedAVIRecorder aviRecorder = new ManagedAVIRecorder())
            {
                aviRecorder.SetMaximumAVISize(AviMaxSize);

                switch (aviType)
                {
                case AviType.Uncompressed:
                {
                    AviOption option = new AviOption();
                    option.frameRate = frameRate;
                    aviRecorder.AVIOpen(aviFileName, option);
                }
                break;

                case AviType.Mjpg:
                {
                    MJPGOption option = new MJPGOption();
                    option.frameRate = frameRate;
                    option.quality   = 75;
                    aviRecorder.AVIOpen(aviFileName, option);
                }
                break;

                case AviType.H264:
                {
                    H264Option option = new H264Option();
                    option.frameRate = frameRate;
                    option.bitrate   = 1000000;
                    option.height    = Convert.ToInt32(imageList[0].rows);
                    option.width     = Convert.ToInt32(imageList[0].cols);
                    aviRecorder.AVIOpen(aviFileName, option);
                }
                break;
                }

                Console.WriteLine("Appending {0} images to AVI file {1}...", imageList.Count, aviFileName);

                for (int imageCnt = 0; imageCnt < imageList.Count; imageCnt++)
                {
                    // Append the image to AVI file
                    aviRecorder.AVIAppend(imageList[imageCnt]);

                    Console.WriteLine("Appended image {0}", imageCnt);
                }

                aviRecorder.AVIClose();
            }
        }
예제 #3
0
        private void SaveAviHelper(AviType aviType, ref List <ManagedImage> imageList, string aviFileName, float frameRate)
        {
            using (ManagedAVIRecorder aviRecorder = new ManagedAVIRecorder())
            {
                switch (aviType)
                {
                case AviType.Uncompressed:
                {
                    AviOption option = new AviOption();
                    option.frameRate = frameRate;
                    aviRecorder.AVIOpen(aviFileName, option);
                }
                break;

                case AviType.Mjpg:
                {
                    MJPGOption option = new MJPGOption();
                    option.frameRate = frameRate;
                    option.quality   = 75;
                    aviRecorder.AVIOpen(aviFileName, option);
                }
                break;

                case AviType.H264:
                {
                    H264Option option = new H264Option();
                    option.frameRate = frameRate;
                    option.bitrate   = 1000000;
                    option.height    = Convert.ToInt32(imageList[0].rows);
                    option.width     = Convert.ToInt32(imageList[0].cols);
                    aviRecorder.AVIOpen(aviFileName, option);
                }
                break;
                }

                Console.WriteLine("Appending {0} images to AVI file {1}...", imageList.Count, aviFileName);

                for (int imageCnt = 0; imageCnt < imageList.Count; imageCnt++)
                {
                    // Append the image to AVI file
                    aviRecorder.AVIAppend(imageList[imageCnt]);

                    Console.WriteLine("Appended image {0}", imageCnt);
                }

                aviRecorder.AVIClose();
            }
        }
        // start capturing
        public void startCapture(ManagedPGRGuid camGuid, int vidMode, System.Windows.Forms.PictureBox displayPicture,
                                 String fileName, Boolean record2file)
        {
            int i;

            Flag_GravityFound_Y = false; // garvity is not known

            // CLEARING THE FRAME QUEUE NO MATTER WHAT...
            FrameQueue.clear();


            RecordToFile = record2file;

            // creating the GPS data list
            GpsCaptureData = new List <GPSDataInstance>();
            // creating the IMU data List
            IMUCapturedata = new List <IMUDataInstance>();

            // resetting frame index
            FrameIndex = 0;

            // 1. connect to the camera
            Cam.Connect(camGuid);

            int fps_i = 0;

            if (vidMode == 0)
            {
                Cam.SetVideoModeAndFrameRate(VideoMode.VideoMode1600x1200Yuv422, FrameRate.FrameRate30);
                fps_i = 30;
            }
            else if (vidMode == 1)
            {
                Cam.SetVideoModeAndFrameRate(VideoMode.VideoMode1600x1200Rgb, FrameRate.FrameRate15);
                fps_i = 15;
            }
            else if (vidMode == 2)
            {
                Format7ImageSettings fset = new Format7ImageSettings();
                fset.height  = 540;
                fset.width   = 960;
                fset.offsetX = 40;
                fset.offsetY = 118;
                fset.mode    = Mode.Mode4;

                fset.pixelFormat = PixelFormat.PixelFormatRgb8;

                Cam.SetFormat7Configuration(fset, 40.0f); // this equivalent to 24 fps

                fps_i = 24;
            }


            if (RecordToFile)
            {
                // 3. Creating the avi recorder object
                AviRecorder = new ManagedAVIRecorder();

                MJPGOption option = new MJPGOption();

                float fps = (float)fps_i;

                option.frameRate = fps;
                option.quality   = 100; // 100 for superb quality
                AviRecorder.AVIOpen(fileName, option);
            }


            // 4. setting the frame buffering option
            // leave it for now...


            // 5. start the capturing
            Cam.StartCapture();

            // MUST discard the first few frames!
            ManagedImage rawImage = new ManagedImage();

            for (i = 0; i < 10; i++)
            {
                Cam.RetrieveBuffer(rawImage);
            }

            // 6. set the display bitmap
            DisplayPicture = displayPicture;

            // 7. starting sampling, recording and dumping threads


            // IMU sampling thread
            IMUSamplingTimer = new PrecisionTimer(.0075, this.IMUSamplingEvent); // sampling frequency at 150 Hz

            RecordingThreadActive = true;
            OutOfRecordingThread  = true;

            IMUSamplingTimer.start();
            RecordingThread = new Thread(this.mainLoop);
            //RecordingThread.Priority = ThreadPriority.Highest;
            RecordingThread.Start();


            // creating the thread for the dumping
            DumpingThread = new System.Threading.Thread(this.dumpingLoop);

            while (OutOfRecordingThread)
            {
                ;                         // must wait until the recording thread enters the loop, otherwise the dumping will never start!
            }
            DumpingThread.Start();
        }
        // start capturing
        public void startCapture(ManagedPGRGuid camGuid, int vidMode,System.Windows.Forms.PictureBox displayPicture, 
                                 String fileName,Boolean record2file)
        {
            int i;

            Flag_GravityFound_Y = false; // garvity is not known

            // CLEARING THE FRAME QUEUE NO MATTER WHAT...
            FrameQueue.clear();

            RecordToFile = record2file;

            // creating the GPS data list
            GpsCaptureData = new List<GPSDataInstance>();
            // creating the IMU data List
            IMUCapturedata = new List<IMUDataInstance>();

            // resetting frame index
            FrameIndex = 0;

            // 1. connect to the camera
            Cam.Connect(camGuid);

            int fps_i = 0;
            if (vidMode == 0)
            {
                Cam.SetVideoModeAndFrameRate(VideoMode.VideoMode1600x1200Yuv422, FrameRate.FrameRate30);
                fps_i = 30;
            }
            else if (vidMode == 1) {
                Cam.SetVideoModeAndFrameRate(VideoMode.VideoMode1600x1200Rgb, FrameRate.FrameRate15);
                fps_i = 15;
                }
            else if (vidMode == 2)
            {
                Format7ImageSettings fset = new Format7ImageSettings();
                fset.height = 540;
                fset.width = 960;
                fset.offsetX = 40;
                fset.offsetY = 118;
                fset.mode = Mode.Mode4;

                fset.pixelFormat = PixelFormat.PixelFormatRgb8;

                Cam.SetFormat7Configuration(fset, 40.0f); // this equivalent to 24 fps

                fps_i = 24;
            }

            if (RecordToFile)
            {
                // 3. Creating the avi recorder object
                AviRecorder = new ManagedAVIRecorder();

                MJPGOption option = new MJPGOption();

                float fps = (float)fps_i;

                option.frameRate = fps;
                option.quality = 100;  // 100 for superb quality
                AviRecorder.AVIOpen(fileName, option);
            }

            // 4. setting the frame buffering option
            // leave it for now...

            // 5. start the capturing
            Cam.StartCapture();

            // MUST discard the first few frames!
            ManagedImage rawImage = new ManagedImage();
            for (i = 0; i < 10;  i++)
            {
                Cam.RetrieveBuffer(rawImage);
            }

            // 6. set the display bitmap
            DisplayPicture = displayPicture;

            // 7. starting sampling, recording and dumping threads

            // IMU sampling thread
            IMUSamplingTimer = new PrecisionTimer(.0075, this.IMUSamplingEvent); // sampling frequency at 150 Hz

            RecordingThreadActive = true;
            OutOfRecordingThread = true;

            IMUSamplingTimer.start();
            RecordingThread = new Thread(this.mainLoop);
            //RecordingThread.Priority = ThreadPriority.Highest;
            RecordingThread.Start();

            // creating the thread for the dumping
            DumpingThread = new System.Threading.Thread(this.dumpingLoop);

            while (OutOfRecordingThread); // must wait until the recording thread enters the loop, otherwise the dumping will never start!

            DumpingThread.Start();
        }
예제 #6
0
        // This function prepares, saves, and cleans up an video from a list of images.
        int SaveListToVideo(INodeMap nodeMap, INodeMap nodeMapTLDevice, ref List <IManagedImage> images)
        {
            int result = 0;

            Console.WriteLine("\n\n*** CREATING VIDEO ***\n");

            try {
                // Retrieve device serial number for filename
                String deviceSerialNumber = "";

                IString iDeviceSerialNumber = nodeMapTLDevice.GetNode <IString>("DeviceSerialNumber");
                if (iDeviceSerialNumber != null && iDeviceSerialNumber.IsReadable)
                {
                    deviceSerialNumber = iDeviceSerialNumber.Value;

                    Console.WriteLine("Device serial number retrieved as {0}...", deviceSerialNumber);
                }

                //
                // Retrieve the current frame rate; acquisition frame rate recorded in hertz
                //
                // *** NOTES ***
                // The video frame rate can be set to anything; however, in
                // order to have videos play in real-time, the acquisition frame
                // rate can be retrieved from the camera.
                //
                IFloat iAcquisitionFrameRate = nodeMap.GetNode <IFloat>("AcquisitionFrameRate");
                if (iAcquisitionFrameRate == null || !iAcquisitionFrameRate.IsReadable)
                {
                    Console.WriteLine("Unable to retrieve frame rate. Aborting...\n");
                    return(-1);
                }

                float frameRateToSet = (float)iAcquisitionFrameRate.Value;

                Console.WriteLine("Frame rate to be set to {0}", frameRateToSet);

                //
                // Create a unique filename
                //
                // *** NOTES ***
                // This example creates filenames according to the type of
                // video being created. Notice that '.avi' does not need to be
                // appended to the name of the file. This is because the video
                // recorder object takes care of the file extension
                // automatically.
                //
                string videoFilename;

                switch (chosenFileType)
                {
                case VideoType.Uncompressed:
                    videoFilename = "SaveToAvi-CSharp-Uncompressed";
                    if (deviceSerialNumber != "")
                    {
                        videoFilename = videoFilename + "-" + deviceSerialNumber;
                    }
                    break;

                case VideoType.Mjpg:
                    videoFilename = "SaveToAvi-CSharp-MJPG";
                    if (deviceSerialNumber != "")
                    {
                        videoFilename = videoFilename + "-" + deviceSerialNumber;
                    }
                    break;

                case VideoType.H264:
                    videoFilename = "SaveToAvi-CSharp-H264";
                    if (deviceSerialNumber != "")
                    {
                        videoFilename = videoFilename + "-" + deviceSerialNumber;
                    }
                    break;

                default:
                    videoFilename = "SaveToAvi-CSharp";
                    break;
                }

                //
                // Select option and open video file type
                //
                // *** NOTES ***
                // Depending on the filetype, a number of settings need to be
                // set in an object called an option. An uncompressed option
                // only needs to have the video frame rate set whereas videos
                // with MJPG or H264 compressions should have more values set.
                //
                // Once the desired option object is configured, open the video
                // file with the option in order to create the image file.
                //
                // *** LATER ***
                // Once all images have been added, it is important to close the
                // file - this is similar to many other standard file streams.
                //
                using (IManagedSpinVideo video = new ManagedSpinVideo()) {
                    // Set maximum video file size to 2GB. A new video file is generated when 2GB
                    // limit is reached. Setting maximum file size to 0 indicates no limit.
                    const uint FileMaxSize = 2048;

                    video.SetMaximumFileSize(FileMaxSize);

                    switch (chosenFileType)
                    {
                    case VideoType.Uncompressed:
                        AviOption uncompressedOption = new AviOption();
                        uncompressedOption.frameRate = frameRateToSet;
                        video.Open(videoFilename, uncompressedOption);
                        break;

                    case VideoType.Mjpg:
                        MJPGOption mjpgOption = new MJPGOption();
                        mjpgOption.frameRate = frameRateToSet;
                        mjpgOption.quality   = 75;
                        video.Open(videoFilename, mjpgOption);
                        break;

                    case VideoType.H264:
                        H264Option h264Option = new H264Option();
                        h264Option.frameRate = frameRateToSet;
                        h264Option.bitrate   = 1000000;
                        h264Option.height    = Convert.ToInt32(images[0].Height);
                        h264Option.width     = Convert.ToInt32(images[0].Width);
                        video.Open(videoFilename, h264Option);
                        break;
                    }

                    //
                    // Construct and save video
                    //
                    // *** NOTES ***
                    // Although the video file has been opened, images must be
                    // individually appended in order to construct the video.
                    //
                    Console.WriteLine("Appending {0} images to video file {1}.avi...", images.Count, videoFilename);

                    for (int imageCnt = 0; imageCnt < images.Count; imageCnt++)
                    {
                        video.Append(images[imageCnt]);

                        Console.WriteLine("Appended image {0}...", imageCnt);
                    }
                    Console.WriteLine();

                    //
                    // Close video file
                    //
                    // *** NOTES ***
                    // Once all images have been appended, it is important to
                    // close the video file. Notice that once an video file has
                    // been closed, no more images can be added.
                    //
                    video.Close();
                }
            } catch (SpinnakerException ex) {
                Console.WriteLine("Error: {0}", ex.Message);
                result = -1;
            }

            return(result);
        }