Пример #1
0
        private void getImage_Click(object sender, EventArgs e)
        {
            string inputText = this.textBox1.Text;

            if (inputText == "")
            {
                inputText = "0";
            }

            savedVideo = new AVIReader();
            if (videoFilePath != null)
            {
                savedVideo.Open(videoFilePath);
                if (Int32.Parse(inputText) * savedVideo.FrameRate <= (savedVideo.Length))
                {
                    savedVideo.Position = Int32.Parse(inputText) * (int)savedVideo.FrameRate;
                    Bitmap frame = savedVideo.GetNextFrame();

                    //Form picture = new Snapshot(frame);
                    //picture.Show(this);

                    frame.Save("snapshot.jpg");
                    label2.Text = "Image Captured!";
                }
                else
                {
                    label2.Text = "Video is not long enough!!!";
                }
            }
            else
            {
                label3.Text = "Select an .avi File first!";
            }
        }
Пример #2
0
        private void Init(string FileName)
        {
            InitBrushPen();
            AVIReader aw = new AVIReader();

            aw.Open(FileName);
            Settings.framerate = (int)aw.FrameRate;
            Bitmap fr = aw.GetNextFrame();

            InitFrameSize(fr.Width, fr.Height);
            InitLists();
            InitVariables();
            int    awLen    = aw.Length;
            double framedur = ((double)(60 / Settings.framerate)) / 60;

            bitmaps.Add(fr);
            FrameDurations.Add(framedur);
            AddFrameToGallery(0, LocY);
            LocY += 95;
            for (int i = 1; i < awLen; i++)
            {
                fr = aw.GetNextFrame();
                bitmaps.Add(fr);
                FrameDurations.Add(framedur);
                AddFrameToGallery(bitmaps.Count - 1, LocY);
                LocY += 95;
            }
            SetBrush();
            SetBackColor(Color.White);
            SelectPB(0);
            RefreshGI();
            InitBrushSizeBar();
            InitScaleBar();
        }
        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (videoFilePath != null)
            {
                sampleVid = new AVIReader();
                sampleVid.Open(videoFilePath);
                linkLabel1.Enabled = false;
                for (int k = 0; k < sampleVid.Length; k++)
                {
                    sampleImg = sampleVid.GetNextFrame();
                    for (int i = 0; i < sampleImg.Width; i++)
                    {
                        for (int j = 0; j < sampleImg.Height; j++)
                        {
                            Color pixel = sampleImg.GetPixel(i, j);

                            if (pixel.R >= 130)
                            {
                                this.dataGridView1.Rows.Insert((this.dataGridView1.Rows.Count) - 1, i.ToString(), j.ToString());
                                coordInfo += "(" + i.ToString() + " , " + j.ToString() + ") \n\r ";
                                break;
                            }
                        }
                    }
                }

                System.IO.File.WriteAllText("RedDotCoordinateInfo.txt", coordInfo);
            }
            else
            {
                label2.Text = "Select a .avi file first!";
            }
        }
Пример #4
0
 private void WorkerThread(CancellationToken token)
 {
     Task.Factory.StartNew(() =>
     {
         this.Running        = true;
         AVIReader aviReader = new AVIReader();
         try
         {
             aviReader.Open(VideoSource); // open file
             while (!cts.IsCancellationRequested)
             {
                 Bitmap bmp = aviReader.GetNextFrame();  // get next frame
                 FramesReceived++;
                 if (NewFrame != null)
                 {
                     NewFrame(this, new CameraEventArgs(bmp));
                 }
                 bmp.Dispose();  // free image
             }
         }
         catch (Exception ex)
         {
             Logger.Error(ex);
         }
         aviReader.Dispose();
         aviReader    = null;
         this.Running = false;
     }, token);
 }
Пример #5
0
        // Start work
        public void Start()
        {
            if (thread == null)
            {
                framesReceived = 0;

                // create events
                stopEvent = new ManualResetEvent(false);

                // open file
                try
                {
                    aviReader = new AVIReader();
                    aviReader.Open(source);
                    _embededFps = aviReader.FrameRate;

                    // create and start new thread
                    thread      = new Thread(new ThreadStart(WorkerThread));
                    thread.Name = source;
                    thread.Start();
                    _fpsMark = DateTime.Now;
                } catch (Exception ex) {
                    System.Diagnostics.Debug.WriteLine("exception : " + ex.Message);
                }
            }
        }
 // Open video file using VFW
 private void openVideofileusingVFWToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (openFileDialog.ShowDialog() == DialogResult.OK)
     {
         AVIReader aviReader = new AVIReader();
         aviReader.Open(openFileDialog.FileName);
         OpenVideoFile(openFileDialog.FileName);
     }
 }
Пример #7
0
        public Video(String input, String password)
        {
            Password = ToPasswordSeed(password);

            reader = new AVIReader();

            reader.Open(input);
            ResetReadByte();

            ExtractHeader();
        }
Пример #8
0
        public VideoAVIGiver(string path)
        {
            reader = new AVIReader();
            reader.Open(path);

            Path = path;

            RunFrom = 0;
            RunTo   = RunToMax;
            Step    = 1;
        }
Пример #9
0
        // Thread entry point
        public void WorkerThread()
        {
            AVIReader aviReader = new AVIReader();

            try
            {
                // open file
                aviReader.Open(source);

                while (true)
                {
                    // start time
                    DateTime start = DateTime.Now;

                    // get next frame
                    Bitmap bmp = aviReader.GetNextFrame();

                    framesReceived++;

                    // need to stop ?
                    if (stopEvent.WaitOne(0, false))
                    {
                        break;
                    }

                    if (NewFrame != null)
                    {
                        NewFrame(this, new CameraEventArgs(bmp));
                    }

                    // free image
                    bmp.Dispose();

                    // end time
                    TimeSpan span = DateTime.Now.Subtract(start);

                    // sleep for a while

/*					int			m = (int) span.TotalMilliseconds;
 *
 *                                      if (m < 100)
 *                                              Thread.Sleep(100 - m);*/
                }
            }
            catch (Exception ex)
            {
                Tools.WriteToFile(Tools.errorFile, "WorkerThread error: " + ex.Message);
                System.Diagnostics.Debug.WriteLine("exception : " + ex.Message);
            }

            aviReader.Dispose();
            aviReader = null;
        }
Пример #10
0
        public Video(String input, String output, int length, String extension, int LSB, String password)
        {
            Length       = length;
            Extension    = extension;
            this.LSB     = LSB;
            Password     = ToPasswordSeed(password);
            SumPNSRFrame = 0;
            SumPNSR      = 0;
            PNSR         = 0;

            reader = new AVIReader();
            writer = new AVIWriter();

            reader.Open(input);
            writer.Open(output, reader.Width, reader.Height);
            ResetWriteByte();

            HideHeader();
        }
Пример #11
0
        /// <summary>
        /// Worker thread.
        /// </summary>
        ///
        public void WorkerThread()
        {
            // AVI reader
            try
            {
                // open file
                aviReader.Open(source);

                // stop positions
                int stopPosition = aviReader.Start + aviReader.Length;

                while (true)
                {
                    // start time
                    DateTime start = DateTime.Now;

                    // get next frame
                    Bitmap bitmap = aviReader.GetNextFrame();

                    framesReceived++;

                    // need to stop ?
                    if (stopEvent.WaitOne(0, false))
                    {
                        break;
                    }

                    if (NewFrame != null)
                    {
                        NewFrame(this, new NewFrameEventArgs(bitmap));
                    }

                    // free image
                    bitmap.Dispose();

                    // check current position
                    if (aviReader.Position >= stopPosition)
                    {
                        break;
                    }

                    while (this.Pause && (stopEvent.WaitOne(0, true) == false))
                    {
                        Thread.Sleep(1000);
                        start.AddSeconds(1.0);
                    }
                    // frame interval
                    int interval = (frameIntervalFromSource) ? (int)(1000 / aviReader.FrameRate) : frameInterval;
                    if (this.Speed > 1)
                    {
                        interval = (interval * 1000 / this.Speed) / 1000;
                    }
                    if (this.Speed < -1)
                    {
                        interval = interval * (0 - this.Speed);
                    }
                    // wait for a while ?
                    if (interval > 0)
                    {
                        // get frame extract duration
                        TimeSpan span = DateTime.Now.Subtract(start);

                        // miliseconds to sleep
                        int msec = interval - (int)span.TotalMilliseconds;

                        while ((msec > 0) && (stopEvent.WaitOne(0, true) == false))
                        {
                            // sleeping ...
                            Thread.Sleep((msec < 100) ? msec : 100);
                            msec -= 100;
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                // provide information to clients
                if (VideoSourceError != null)
                {
                    VideoSourceError(this, new VideoSourceErrorEventArgs(exception.Message));
                }
            }

            aviReader.Close();
            //aviReader.Dispose();
            //aviReader = null;
        }