Ejemplo n.º 1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            // Quit running conversions if no more filters
            if (curFilter >= filters.Count)
            {
                timer1.Enabled = false;
                return;
            }

            string filterName, commonName, outputPath;

            GetFilterName(curFilter, out filterName, out commonName, out outputPath);

            double averageFrameTime;

            // Create compressed AVI file.
            using (AviOutputSession outputSession = new AviOutputSession(outputPath, 30, filterName))
            {
                // Copy the frames from original AVI file to the compressed file.
                CopyAvi(inputSession, outputSession, out averageFrameTime);
            }

            // Calculate results of compression and write them to the table
            long   fileSize = new System.IO.FileInfo(outputPath).Length;
            double quality;

            using (AviInputSession writtenSession = new AviInputSession(outputPath)) {
                quality = CompareAvi(inputSession, writtenSession);
            }

            AddItem(commonName, (double)fileSize / 1024, averageFrameTime, quality);
            progressBar1.Value = progressBar1.Value + 1;
            curFilter++;
            Refresh();
        }
Ejemplo n.º 2
0
        // Sample Data creates a time stamp, waveform and image. The time stamp
        // and waveform data are bundled together and flattened to a string.
        // This data is saved with the image in an AVI so when the AVI image is
        // read out later, the same data it was written with can also be
        // retrieved.
        private void SampleData(AviInputSession sourceSession, AviOutputSession destSession, VisionImage frame, uint frameIndex)
        {
            // Get and display  time
            string timestamp = DateTime.Now.ToString();

            form2.CurTime.Text = timestamp;

            // Read the frame
            sourceSession.ReadFrame(frame, frameIndex);

            // Get and display sample waveforms
            double[] waves = new double[3];
            waves[0]  = 5 * Math.Sin(sinPhase);
            waves[1]  = 4 * Math.Cos(cosPhase);
            waves[2]  = (new Random()).NextDouble() * 6 - 3;
            sinPhase += .1;
            cosPhase += .15;

            form2.Graph.AppendData(waves[0], waves[1], waves[2]);

            AviData data = new AviData(timestamp, waves[0], waves[1], waves[2]);

            // Flatten data to buffer
            byte[] bytes = FlattenData(data);
            destSession.WriteFrame(frame, bytes);
        }
Ejemplo n.º 3
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            // Done writing?
            if (curFrame >= numFrames || mode != RunMode.WritingFrames)
            {
                // Close AVIs
                sourceSession.Dispose();
                sourceSession = null;
                destSession.Dispose();
                destSession = null;

                // Setup for reading AVI frames
                mode = RunMode.ReadingFrames;
                startButton.Enabled = true;
                stopButton.Enabled  = false;
                sourceSession       = new AviInputSession(Path.Text);

                form2.Graph.SetupForReading((int)sourceSession.Frames);
                form2.FrameSlider.Enabled = true;
                form2.FrameSlider.SetRangeFromAvi(sourceSession);
                form2.FrameNum.Enabled = true;
                form2.FrameNum.Maximum = (int)sourceSession.Frames - 1;

                // Update display to reflect change in state
                statusLabel.Text = "Reading AVI File and Data";
                this.Refresh();
                form2.Graph.ClearGraph();

                ReadAllData();
                ReadFrame(0);
                form2.Graph.DoneReading();
                timer1.Enabled = false;
                return;
            }

            // Write the frame
            WriteFrame(curFrame);
            curFrame++;
        }
Ejemplo n.º 4
0
        private void CopyAvi(AviInputSession source, AviOutputSession dest, out double averageFrameTime)
        {
            int totalTime = 0;

            // Grab each frame.
            VisionImage[] frames = new VisionImage[source.Frames];
            for (uint i = 0; i < source.Frames; ++i)
            {
                frames[i] = new VisionImage(ImageType.Rgb32);
                source.ReadFrame(frames[i], i);
            }

            // Convert each frame.
            int startTime = System.Environment.TickCount;

            for (int i = 0; i < source.Frames; ++i)
            {
                // Write the frame.
                dest.WriteFrame(frames[i]);
            }
            totalTime        = System.Environment.TickCount - startTime;
            averageFrameTime = ((double)totalTime) / source.Frames;
        }
Ejemplo n.º 5
0
        private void startButton_Click(object sender, EventArgs e)
        {
            // Close AVI if it is open
            if (mode != RunMode.NotRunning)
            {
                form2.Graph.ClearGraph();
                form2.FrameNum.Enabled    = false;
                form2.FrameSlider.Enabled = false;
                if (sourceSession != null)
                {
                    sourceSession.Dispose();
                    sourceSession = null;
                }
            }

            // Load base AVI
            sourceSession = new AviInputSession(System.IO.Path.Combine(ExampleImagesFolder.GetExampleImagesFolder(), @"AVIs\Flame.avi"));
            numFrames     = sourceSession.Frames;

            // Create output AVI
            if (Path.Text == "")
            {
                Browse();
            }
            destSession = new AviOutputSession(Path.Text, sourceSession.FramesPerSecond, null, -1, true, 10000);

            // Start writing
            statusLabel.Text = "Writing AVI File and Data";
            curFrame         = 0;
            mode             = RunMode.WritingFrames;
            frame.Type       = ImageType.Rgb32;
            imageViewer1.Attach(frame);
            timer1.Enabled      = true;
            startButton.Enabled = false;
            stopButton.Enabled  = true;
        }
Ejemplo n.º 6
0
 private void LoadAviFilters()
 {
     filters = AviOutputSession.GetCompressionFilters();
 }