예제 #1
0
 private void FileSelectButtonClick(object sender, EventArgs e)
 {
     using (var ofd = new OpenFileDialog())
     {
         if (ofd.ShowDialog() == DialogResult.OK)
         {
             var video = new VideoCapture(ofd.FileName);
             if (!video.IsOpened())
             {
                 MessageBox.Show("動画ファイルではありません", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 video.Dispose();
                 return;
             }
             if (!this.compatibleFPS.Contains(video.Fps))
             {
                 MessageBox.Show("このソフトは現在20fps, 30fps, 60fpsの動画ファイルにのみ対応しています", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 video.Dispose();
                 return;
             }
             this.targetFileLabel.Text = ofd.FileName;
             this.video  = video;
             this.Width  = baseWidth + this.video.FrameWidth;
             this.Height = baseHeight + this.video.FrameHeight;
             this.videoFrameBox.Width  = this.video.FrameWidth;
             this.videoFrameBox.Height = this.video.FrameHeight;
             this.frame = 0;
             DisplayFrame();
             this.statusLabel.Text = $"{ofd.FileName} を開きました({this.video.Fps}fps, {this.video.FrameCount}frames)";
         }
     }
 }
예제 #2
0
        private void LoadVideo()
        ///<summary>
        /// input the local video file path with FileOpenDialogue.
        /// configure the video capture
        /// </summary>
        {
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                if (cap != null)
                {
                    cap.Dispose();
                }
                // create the video capture
                string path = openFileDialog.FileName;
                cap = VideoCapture.FromFile(path);

                // display the input file name
                string inFname = Path.GetFileName(path);
                // lblInput.Text = "Video File: " + inFname;

                uFps         = (uint)cap.Get(CaptureProperty.Fps);
                uFrameWidth  = (uint)cap.Get(CaptureProperty.FrameWidth);
                uFrameHeight = (uint)cap.Get(CaptureProperty.FrameHeight);

                strCapType = "Video";
                strCapFeed = path;
            }
        }
예제 #3
0
        /// <summary>
        /// 打开摄像头被点击
        /// </summary>
        private void 打开内部摄像头ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (_captureInProgress)
            {  //stop the capture
                camera_MenuItem.Text = "打开摄像头(自带)";
                _capture.Pause();
                process_timer.Stop();
                _capture.Dispose();
                excamera_MenuItem.Enabled = true;
            }
            else
            {
                //start the capture
                try
                {
                    _capture = new VideoCapture(0);
                    _capture.ImageGrabbed += ProcessFrame;
                }
                catch
                {
                    MessageBox.Show("打开自带摄像头失败");
                }
                camera_MenuItem.Text      = "关闭摄像头(自带)";
                excamera_MenuItem.Enabled = false;
                _capture.Start();
                process_timer.Start();
            }

            _captureInProgress = !_captureInProgress;
        }
예제 #4
0
        /// <summary> Открыть видео. </summary>
        /// <param name="path"></param>
        public async Task OpenVideoAsync(string path)
        {
            if (_capture != null)
            {
                _capture.Dispose();
            }

            _fileStart = path;
            _capture   = new VideoCapture(path);
            //_fps = (int)(1000 / _capture.Fps);
            _fps = 30;
            using (Mat image = new Mat())
            {
                _capture.Read(image);
                if (!image.Empty())
                {
                    await NextFrameAddInVideoControlAsync(image);

                    _pause = false;
                }
                else
                {
                    _logControler.AddMessage("Некорректное видео!");
                }
            }
        }
예제 #5
0
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);

            if (e.CloseReason == CloseReason.WindowsShutDown)
            {
                return;
            }

            // Confirm user wants to close
            switch (MessageBox.Show(this, "Are you sure you want to close?", "Closing", MessageBoxButtons.YesNo))
            {
            case DialogResult.No:
                e.Cancel = true;
                if (cap != null)
                {
                    cap.Dispose();
                }
                break;

            default:
                if (cap != null)
                {
                    cap.Dispose();
                }
                break;
            }
        }
예제 #6
0
 private void stopCapture()
 {
     Application.Idle -= new EventHandler(FrameGrabber_Parrellel);
     if (grabber != null)
     {
         grabber.Dispose();
     }
 }
예제 #7
0
        private void BackToCamButton_Click(object sender, EventArgs e)
        {
            capture.Dispose();
            Close();
            WebcamForm camForm = new WebcamForm();

            camForm.Show();
        }
 private void Form1_FormClosed(object sender, FormClosedEventArgs e)
 {
     if (capture != null)
     {
         capture.Dispose();
         capture = null;
     }
 }
예제 #9
0
 public void DisposeAll()
 {
     FrameMat?.Dispose();
     _capture?.Stop();
     _capture?.Dispose();
     _capture = null;
     GC.Collect();
 }
예제 #10
0
 private void _sketch_Exited(object sender, EventArgs e)
 {
     if (_videoCapture != null)
     {
         _videoCapture.ImageGrabbed -= _videoCapture_ImageGrabbed;
         _videoCapture.Stop();
         _videoCapture.Dispose();
     }
 }
예제 #11
0
        private void pictureBox2_Click(object sender, EventArgs e)
        {
            _capture.Dispose();

            Application.Idle -= ProcessFrame;

            ID_Camera nt = new ID_Camera();

            nt.Show();
            this.Hide();
        }
예제 #12
0
        private void btnCamera_Click(object sender, EventArgs e)
        {
            if (cap != null)
            {
                cap.Dispose();
            }

            cap = new VideoCapture(0);
            cap.ImageGrabbed += Cap_ImageGrabbed;
            cap.Start();
        }
예제 #13
0
 private void OnDestroy()
 {
     if (_videoCapture != null)
     {
         _videoCapture.FrameSampleAcquired -= OnFrameSampleAcquired;
         _videoCapture.Dispose();
     }
     if (instance != null)
     {
         instance = null;
     }
 }
예제 #14
0
        static Task OnDesiredPropertiesUpdate(TwinCollection desiredProperties, object userContext)
        {
            try
            {
                LogUtil.Log("Desired property change:", LogLevel.Info);
                LogUtil.Log(JsonConvert.SerializeObject(desiredProperties), LogLevel.Info);

                if (desiredProperties["RTSP"] != null)
                {
                    string tRTSP = desiredProperties["RTSP"];
                    LogUtil.Log("RTSP:" + tRTSP, LogLevel.Info);

                    lock (captureLocker)
                    {
                        if (_cameraCapture != null)
                        {
                            _cameraCapture.Dispose();
                        }
                        _cameraCapture = new VideoCapture(tRTSP);

                        RTSP = tRTSP;
                    }
                    LogUtil.Log("RTSP changed", LogLevel.Info);
                }
                if (desiredProperties["StorageConnectString"] != null)
                {
                    STORAGECONNECTSTRING = desiredProperties["StorageConnectString"];
                    LogUtil.Log($"StorageConnectString: {STORAGECONNECTSTRING}", LogLevel.Info);
                }
                if (desiredProperties["StorageURI"] != null)
                {
                    STORAGEURI = desiredProperties["StorageURI"];
                    LogUtil.Log($"StorageURI: {STORAGEURI}", LogLevel.Info);
                }
                if (desiredProperties["ModuleId"] != null)
                {
                    moduleId = desiredProperties["ModuleId"];
                    LogUtil.Log($"ModuleId: {moduleId}", LogLevel.Info);
                }
            }
            catch (AggregateException ex)
            {
                foreach (Exception exception in ex.InnerExceptions)
                {
                    LogUtil.LogException(exception);
                }
            }
            catch (Exception ex)
            {
                LogUtil.LogException(ex);
            }
            return(Task.CompletedTask);
        }
예제 #15
0
파일: Form1.cs 프로젝트: FinchYang/study
        void FrameGrabber(object sender, EventArgs e)
        {
            //  UpdateStatus(string.Format("in grabber standardm,{0}", 111));
            //Get the current frame form capture device
            using (currentFrame = grabber.QueryFrame().ToImage <Bgr, Byte>())
            {
                if (currentFrame != null)
                {
                    pictureBoxsource.Image = currentFrame.Bitmap;
                    //   UpdateStatus(string.Format("in grabber standardm,{0}", 333));
                    //   gray_frame = currentFrame.Convert<Gray, Byte>();

                    //var filename = Path.GetTempFileName() + ".jpg";
                    //currentFrame.Save(filename);
                    if (HaveFace(currentFrame))
                    {
                        pictureBoxcurrentimage.Image = currentFrame.Bitmap;
                        UpdateStatus(string.Format("high quality face photo captured,{0}", ++facenum));
                        if (facenum > int.Parse(textBoxpicturesource.Text))
                        {
                            Application.Idle -= new EventHandler(FrameGrabber);
                            grabber.Dispose();
                            return;
                        }
                        ISession     session = ImageDatabase.GetCurrentSession();
                        ITransaction tx      = session.BeginTransaction();

                        try
                        {
                            PersistentImage pImage = new PersistentImage(currentFrame.Width, currentFrame.Height);
                            CvInvoke.cvCopy(currentFrame, pImage, IntPtr.Zero);
                            pImage.DateCreated = DateTime.Now;
                            //  UpdateStatus(string.Format("add face to sqlite error,{0}", 111));
                            session.Save(pImage);
                            // UpdateStatus(string.Format("add face to sqlite error,{0}", 222));
                            tx.Commit();
                        }
                        catch (Exception ex)
                        {
                            UpdateStatus(string.Format("add face to sqlite error,{0}", ex));
                        }


                        session.Close();
                    }
                }
            }
            ;
            //  UpdateStatus(string.Format("in grabber standardm,{0}", 222));
            //Convert it to Grayscale
        }
예제 #16
0
파일: Form1.cs 프로젝트: darwinesc/CamApp
        private void SetupCapture(int Camera_Identifier)
        {
            //update the selected device
            int CameraDevice = Camera_Identifier;

            //Dispose of Capture if it was created before
            if (capture != null)
            {
                capture.Dispose();
            }
            try
            {
                //Set up capture device
                capture = new VideoCapture(CameraDevice);

                switch (comboBox2.SelectedIndex)
                {
                case 0:
                    frameWidth  = 320;
                    frameHeight = 240;
                    break;

                case 1:
                    frameWidth  = 640;
                    frameHeight = 480;
                    break;

                case 2:
                    frameWidth  = 720;
                    frameHeight = 480;
                    break;

                case 3:
                    frameWidth  = 1280;
                    frameHeight = 720;
                    break;

                case 4:
                    frameWidth  = 1920;
                    frameHeight = 1080;
                    break;
                }
                capture.ImageGrabbed += ProcessFrame;
                capture.Start();
            }
            catch (NullReferenceException excpt)
            {
                MessageBox.Show(excpt.Message);
            }
        }
예제 #17
0
        private void btStop_Click(object sender, EventArgs e)
        {
            grabber.Dispose();

            rbColor.Checked      = true;
            rbColor.Enabled      = false;
            rbInvert.Enabled     = false;
            rbGrey.Enabled       = false;
            rbBrightness.Enabled = false;
            rbBinary.Enabled     = false;

            btStart.Enabled   = true;
            btStop.Enabled    = false;
            btCapture.Enabled = false;
        }
예제 #18
0
 protected override void OnClosed(EventArgs e)
 {
     if (capture != null)
     {
         capture.Dispose();
     }
 }
예제 #19
0
 public void Dispose()
 {
     Stop();
     capture.Dispose();
     frame.Dispose();
     image.Dispose();
 }
예제 #20
0
 private void ProcessVideo(object sender, EventArgs e)
 {
     FrameCounter++;
     if (FrameCounter < TotalFrames)
     {
         try
         {
             capturedVideo.Retrieve(originalFrame);
             fileName = "RetrievedFrame" + FrameCounter + ".png";
             originalFrame.Save(System.IO.Path.Combine(destinationURL, fileName));
             // Invoke UI's thread
             this.Dispatcher.Invoke(() =>
             {
                 progressReport.Value = (FrameCounter / TotalFrames) * 100;
             });
         }
         catch (Exception err)
         {
             System.Windows.MessageBox.Show("Error in processing frames!\n" + err.ToString(), "Error!", MessageBoxButton.OK, MessageBoxImage.Asterisk);
         }
     }
     else
     {
         System.Windows.MessageBox.Show("Retrieving video frames has been finished successfully!\nNumber of extracted frames: " +
                                        +(FrameCounter - 1) + "", "", MessageBoxButton.OK, MessageBoxImage.Information);
         // Invoke UI's thread
         this.Dispatcher.Invoke(() =>
         {
             progressReport.Value = 0;
         });
         FrameCounter = 0;
         capturedVideo.Dispose();
     }
 }
예제 #21
0
 public void Dispose()
 {
     if (capture != null)
     {
         capture.Dispose();
     }
 }
 public void Dispose()
 {
     if (mic != null)
     {
         mic.Pause();
         mic.Dispose();
         mic = null;
     }
     if (cam != null)
     {
         cam.Pause();
         cam.Dispose();
         cam = null;
     }
     if (EncoderRunning)
     {
         Stop();
     }
     if (coreloops != null)
     {
         foreach (var loop in coreloops)
         {
             if (loop == null)
             {
                 continue;
             }
             loop.Join();
         }
         coreloops.Clear();
     }
 }
예제 #23
0
 private void Form1_FormClosed(object sender, FormClosedEventArgs e)
 {
     if (capVideo != null)
     {
         capVideo.Dispose();
     }
 }
        private async void importVideoFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog.FileName = "";
            openFileDialog.Filter   = "mp4文件|*.mp4|avi文件|*avi|所有文件|*.*";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                info.VideoPath            = openFileDialog.FileName;
                labelVideoPath.Text       = openFileDialog.SafeFileName;
                trackBarBeginTime.Maximum = (int)await Info.GetMediaTime(info.VideoPath);

                buttonMakeSure.Enabled = true;
                if (trackBarBeginTime.Maximum == 0)
                {
                    MessageBox.Show("无法读取视频长度,长度调节暂不可用");
                }
                Task a = new Task(new Action(() => {
                    Split.ExtractAudio(info);
                }));
                a.Start();
                a.Wait();
                VideoCapture cap = new VideoCapture(info.VideoPath);
                info.width  = (int)cap.GetCaptureProperty(CapProp.FrameWidth);
                info.height = (int)cap.GetCaptureProperty(CapProp.FrameHeight);
                info.bmp    = cap.QueryFrame().ToBitmap();
                pictureBox1.CreateGraphics().DrawImage(info.bmp, new System.Drawing.Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height));
                cap.Dispose();
                if (modeVideoToolStripMenuItem.Checked && info.subtitles != null)
                {
                    info.AudioPath = info.bgmTemp;
                    Merge.MixBgmAndSpeech(info);
                }
            }
        }
예제 #25
0
        private void CaptureCameraCallback()
        {
            using Mat frame = new Mat();
            _videoCapture   = new VideoCapture();
            _videoCapture.Open(_selectedWebCamIndex);

            if (!_videoCapture.IsOpened())
            {
                return;
            }

            while (_isCameraRunning)
            {
                try
                {
                    _videoCapture.Read(frame);
                    Bitmap image = BitmapConverter.ToBitmap(frame);
                    Dispatcher.Invoke(() => pictureBox.Source = ConvertBitmap2BitmapImage(image));
                    image.Dispose();
                }
                catch (ArgumentException)
                {
                    // During webcam switches for a short period of time, the frame becomes an invalid argument.
                    // Do nothing, it heals itself.
                }
            }
            _videoCapture.Dispose();
        }
예제 #26
0
 private void ReleaseData()
 {
     if (_capture != null)
     {
         _capture.Dispose();
     }
 }
예제 #27
0
        private void btnStartCam_Click(object sender, EventArgs e)
        {
            try
            {
                _Capture = new VideoCapture(cbxCameras.SelectedIndex);
                _Capture.SetCaptureProperty(CapProp.FrameWidth, 1080);
                _Capture.SetCaptureProperty(CapProp.FrameHeight, 1080);
                _Capture.ImageGrabbed += ProcessFrame;
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
                return;
            }

            if (_Capture != null)
            {
                if (_CaptureInProgress)
                {  //stop the capture
                    btnStartCam.Text = "Start";
                    _Capture.Stop();
                    _Capture.Dispose();
                    _CaptureInProgress = false; //Flag the state of the camera
                    //sttCamera.Text = "Camera OFF";
                }
                else
                {
                    //start the capture
                    btnStartCam.Text = "Stop";
                    _Capture.Start();
                    _CaptureInProgress = true; //Flag the state of the camera
                    //sttCamera.Text = "Camera ON";
                }
            }
        }
예제 #28
0
파일: Form1.cs 프로젝트: fkondou/ocr_test
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            string _s = getTmpFileNm("gray");

            if (gray != null)
            {
                Bitmap _b = (Bitmap)gray.Clone();
                _b.Save(_s);
                _b.Dispose();
            }
            if (frame != null)
            {
                frame.Dispose();
            }
            if (capture != null)
            {
                capture.Dispose();
            }
            if (captBmp != null)
            {
                captBmp.Dispose();
            }
//            if (gray != null) gray.Dispose();
            if (capMat != null)
            {
                capMat.Dispose();
            }
            if (graphic != null)
            {
                graphic.Dispose();
            }
        }
예제 #29
0
파일: MainForm.cs 프로젝트: v5chn/emgucv
        private async void cameraButton_Click(object sender, EventArgs e)
        {
            if (cameraButton.Text.Equals(_startCameraText))
            {
                await Init();

                if (_capture == null)
                {
                    _capture = new VideoCapture(0);
                    if (!_capture.IsOpened)
                    {
                        _capture = null;
                        MessageBox.Show("Failed to open camera");
                        return;
                    }
                    _capture.ImageGrabbed += _capture_ImageGrabbed;
                    _capture.Start();
                }
                cameraButton.Text = _stopCameraText;
            }
            else
            {
                _capture.Stop();
                _capture.Dispose();
                _capture          = null;
                cameraButton.Text = _startCameraText;
            }
        }
예제 #30
0
        private void toolStripButtonStartCapture_Click(object sender, EventArgs e)
        {
            // close currently opened webcam (if any)
            if (capture != null)
            {
                if (capture.IsOpened)
                {
                    capture.Stop();
                }
                Application.Idle -= ProcessFrame;
                //capture.ImageGrabbed -= ProcessFrame;
                capture.Dispose();
                capture = null;
            }

            // start the webcam with specified camera index
            try
            {
                capture           = new VideoCapture(settings.CameraIndex);
                Application.Idle += ProcessFrame;
                //capture.ImageGrabbed += ProcessFrame;
                capture.Start();
            }
            catch (NullReferenceException excpt)
            {
                MessageBox.Show(excpt.Message);
            }
        }