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)"; } } }
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; } }
/// <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; }
/// <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("Некорректное видео!"); } } }
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; } }
private void stopCapture() { Application.Idle -= new EventHandler(FrameGrabber_Parrellel); if (grabber != null) { grabber.Dispose(); } }
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; } }
public void DisposeAll() { FrameMat?.Dispose(); _capture?.Stop(); _capture?.Dispose(); _capture = null; GC.Collect(); }
private void _sketch_Exited(object sender, EventArgs e) { if (_videoCapture != null) { _videoCapture.ImageGrabbed -= _videoCapture_ImageGrabbed; _videoCapture.Stop(); _videoCapture.Dispose(); } }
private void pictureBox2_Click(object sender, EventArgs e) { _capture.Dispose(); Application.Idle -= ProcessFrame; ID_Camera nt = new ID_Camera(); nt.Show(); this.Hide(); }
private void btnCamera_Click(object sender, EventArgs e) { if (cap != null) { cap.Dispose(); } cap = new VideoCapture(0); cap.ImageGrabbed += Cap_ImageGrabbed; cap.Start(); }
private void OnDestroy() { if (_videoCapture != null) { _videoCapture.FrameSampleAcquired -= OnFrameSampleAcquired; _videoCapture.Dispose(); } if (instance != null) { instance = null; } }
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); }
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 }
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); } }
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; }
protected override void OnClosed(EventArgs e) { if (capture != null) { capture.Dispose(); } }
public void Dispose() { Stop(); capture.Dispose(); frame.Dispose(); image.Dispose(); }
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(); } }
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(); } }
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); } } }
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(); }
private void ReleaseData() { if (_capture != null) { _capture.Dispose(); } }
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"; } } }
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(); } }
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; } }
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); } }