// 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();
        }