示例#1
0
        public void DoFinalAction()
        {
            m_isFinalActionRuning = true;

            if (this.Data.Count != 0)
            {
                AviOption option = new AviOption();
                option.frameRate = 7.5F;
                string fileName = this.DirectoryToSaveVideo + @"\" + "PG_Video" + "_" +
                                  DateTime.Now.Year.ToString() + "_" +
                                  DateTime.Now.Month.ToString() + "_" +
                                  DateTime.Now.Day.ToString() + "_" +
                                  DateTime.Now.Hour.ToString() + "_" +
                                  DateTime.Now.Minute.ToString() + "_" +
                                  DateTime.Now.Second.ToString() + ".avi";

                using (ManagedAVIRecorder managedRecoder = new ManagedAVIRecorder())
                {
                    managedRecoder.AVIOpen(fileName, option);

                    foreach (ManagedImage mi in this.Data)
                    {
                        managedRecoder.AVIAppend(mi);
                    }

                    managedRecoder.AVIClose();
                }
            }

            OnFinalStateIsReached();
            this.IsNeedImage = false;
            MessageBox.Show("The video has been recorded successfully", "Video recording is done", MessageBoxButton.OK, MessageBoxImage.Information);
        }
示例#2
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();
            }
        }
示例#3
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();
            }
        }
示例#4
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();
        }