public ImageProcessor(Bitmap bitmap) { //dummy code to load the opencv libraries CvInvoke.CV_FOURCC('m', 'j', 'p', 'g'); this.imageBitmap = bitmap; }
private void btnCameraCapture_Click(object sender, EventArgs e) { if (firstClicked) { firstClicked = false; isRecordCamVideo = checkBoxRecordCamVideo.Checked; if (isRecordCamVideo) { string strFileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".avi"; if (fps <= 0 || fps >= 30) { fps = 20; } //全帧非压缩,录制的视频体积巨大 //videoWriter = new VideoWriter(strFileName, fps, frameWidth, frameHeight, true); videoWriter = new VideoWriter(strFileName, CvInvoke.CV_FOURCC('D', 'I', 'V', 'X'), fps, frameWidth, frameHeight, true); } } if (capture != null) { if (isCapturing) { capture.Stop(); btnCameraCapture.Text = "Resume"; labelCameraCaptureStatus.Text = "Paused"; } else { capture.Start(); btnCameraCapture.Text = "Pause"; labelCameraCaptureStatus.Text = "Capturing"; } isCapturing = !isCapturing; } }
protected Boolean openWebCam(int NomCamera, int indexResolution) { LimiteTerrain.Clear(); ratioCmParPixel = new double[2] { 1, 1 }; /* Ouvre le flux vidéo et initialise le EventHandler */ // TODO : selection de la caméra _capture = new Capture(); // Utiliser la webcam de base // Evenement lors de la reception d'une image _capture.ImageGrabbed += ProcessFrame; // Passage en MPG _capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FOURCC, CvInvoke.CV_FOURCC('M', 'J', 'P', 'G')); // Resolution VideoCaptureDevice tmpVideo = new VideoCaptureDevice(VideoCaptureDevices[NomCamera].MonikerString); _capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH, tmpVideo.VideoCapabilities[indexResolution].FrameSize.Width); _capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT, tmpVideo.VideoCapabilities[indexResolution].FrameSize.Height); _capture.Start(); return(true); }
public void Record(RgbImageData imageData) { if (!_recorders.Any(kvp => Equals(kvp.Key.Key, imageData.Key))) { //var width = imageData.Image.Width; //var height = imageData.Image.Height; //var filename = string.Format("{0}_{1}_{2}x{3}_{4}.avi", Filename, imageData.Key, width, height, Fps); var videoMetadata = new VideoMetadata { Key = imageData.Key, FileName = string.Format("{0}{1}", imageData.Key, ".avi"), Width = imageData.Image.Width, Height = imageData.Image.Height, Fps = Fps }; //VideoWriter captureOutput = new VideoWriter(@"test.avi", -1, 1, width, height, true); //var captureOutput = new VideoWriter(@"test.avi", CvInvoke.CV_FOURCC('W', 'M', 'V', '3'), 1, width, height, true); var videoWriter = new VideoWriter( GetTempFilePath(_tmpRecordPath, videoMetadata.FileName), CvInvoke.CV_FOURCC('D', 'I', 'V', 'X'), Fps, videoMetadata.Width, videoMetadata.Height, true); _recorders.Add(videoMetadata, videoWriter); _isRecorderStarted = true; } if (!_isRecorderStarted) { return; } // TODO: The _recorders.Single may raise an exception if sequence is empty or multiple items in sequence match var recorder = _recorders.Single(kvp => Equals(kvp.Key.Key, imageData.Key)).Value; //_recorder = new VideoWriter(Filename, 10, 320, 240, true); if (recorder != null) { Image <Rgb, byte> imageCopy = null; try { Console.WriteLine("Write image frame"); imageCopy = imageData.Image; recorder.WriteFrame(imageCopy.Convert <Bgr, byte>()); } finally { if (imageCopy != null) { imageCopy.Dispose(); } } } }
public void BeginSave(int fpsWanted, string fileName) { this.Dispose(); videoWriter = CvInvoke.cvCreateVideoWriter(fileName, CvInvoke.CV_FOURCC('P', 'I', 'M', '1'), fpsWanted, Recorder.ScreenSize, true); this.saverState = SaverState.Running; this.saveThread.Start(); }
public SelectImageActivityBase(String buttonText) : base() { _buttonText = buttonText; //dummy code to load the opencv libraries CvInvoke.CV_FOURCC('m', 'j', 'p', 'g'); }
public void onImageResults(Dictionary <int, Affdex.Face> faces, Affdex.Frame frame) { process_fps = 1.0f / (frame.getTimestamp() - process_last_timestamp); process_last_timestamp = frame.getTimestamp(); //Console.WriteLine(process_fps); try { byte[] pixels = frame.getBGRByteArray(); this.img = new Bitmap(frame.getWidth(), frame.getHeight(), PixelFormat.Format24bppRgb); if (this.saveWebCam && this.start) { this.saveWebCam = false; //this.vWritter = new VideoWriter( this.videoPath, CvInvoke.CV_FOURCC('X', 'V', 'I', 'D'), (int)framePerSeconds, this.img.Width, this.img.Height, true); this.vWritter = new VideoWriter(this.videoPath, CvInvoke.CV_FOURCC('M', 'J', 'P', 'G'), (int)framePerSeconds, this.img.Width, this.img.Height, true); //this.vWritter = new VideoWriter(this.videoPath, CvInvoke.CV_FOURCC('M', 'P', '4', '2'), (int)framePerSeconds, this.img.Width, this.img.Height, true); } var bounds = new Rectangle(0, 0, frame.getWidth(), frame.getHeight()); BitmapData bmpData = img.LockBits(bounds, ImageLockMode.WriteOnly, img.PixelFormat); IntPtr ptr = bmpData.Scan0; int data_x = 0; int ptr_x = 0; int row_bytes = frame.getWidth() * 3; // The bitmap requires bitmap data to be byte aligned. // http://stackoverflow.com/questions/20743134/converting-opencv-image-to-gdi-bitmap-doesnt-work-depends-on-image-size for (int y = 0; y < frame.getHeight(); y++) { Marshal.Copy(pixels, data_x, ptr + ptr_x, row_bytes); data_x += row_bytes; ptr_x += bmpData.Stride; } img.UnlockBits(bmpData); if (this.vWritter != null && this.start) { //Bitmap bmp = img.Clone(new Rectangle(0, 0, img.Width, img.Height), img.PixelFormat); //this.vWritter.WriteFrame(new Image<Bgr, byte>( bmp )); this.vWritter.WriteFrame(new Image <Bgr, byte>(this.img)); } } catch (Exception e) { System.Console.WriteLine(e.ToString()); } this.faces = faces; //rwLock.ReleaseWriterLock(); this.Invalidate(); frame.Dispose(); }
public CameraControl(int index) { InitializeComponent(); CameraIndex = index; m_Cap = new Capture(index); m_Cap.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_COUNT, Config.FRAME_COUNT); // m_Cap.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH, Config.FRAME_WIDTH); //5168, 1280, 2304, m_Cap.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT, Config.FRAME_HEIGHT); //2907, 720, 1536 m_Cap.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FOURCC, CvInvoke.CV_FOURCC('U', '2', '6', '3')); //622,3730 m_Cap.ImageGrabbed += cap_ImageGrabbed; }
private void BT_Video_Path_Click(object sender, EventArgs e) { SaveFileDialog_Video.FileName = DateTime.Now.ToString("yyyyMMddhhmmss"); SaveFileDialog_Video.Filter = "Image Files(*.avi)|*.avi|All files (*.*)|*.*"; if (SaveFileDialog_Video.ShowDialog() == DialogResult.OK) { //MessageBox.Show("開始錄製,按ESC結束錄製"); VW = new VideoWriter(SaveFileDialog_Video.FileName, CvInvoke.CV_FOURCC('X', 'V', 'I', 'D'), 30, 512, 424, true); label1.Text = SaveFileDialog_Video.FileName; } }
public bool StartCapture(String fileName, int width, int height) { try { writer = new VideoWriter(fileName, CvInvoke.CV_FOURCC('D', 'I', 'V', 'X'), 25, width, height, false); Started = true; return(true); } catch (Exception e) { Console.WriteLine("Exception capturing video: {0}", e.Message); return(false); } }
private void StartRecording() { string recordingFileName = CreateRecordingFilePath(); int width = (int)m_Capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH); int height = (int)m_Capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT); // NOTE: Requires that the xvid codec is installed. It can be downloaded from http://www.xvid.org/ m_VideoWriter = new VideoWriter( recordingFileName, CvInvoke.CV_FOURCC('D', 'I', 'V', 'X'), (int)m_Capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FPS), width, height, true); }
//private Dictionary<int, VideoRecordInstance> FWritersByIndex = new Dictionary<int, VideoRecordInstance>(); public override void Evaluate(int spreadMax) { base.Evaluate(spreadMax); int codec = CvInvoke.CV_FOURCC(FCodec[0][0], FCodec[0][1], FCodec[0][2], FCodec[0][3]); for (int i = 0; i < spreadMax; i++) { if (FInput[i] == null || !FRecord[i]) { InstancesByIndex[i].Close(); } else if (FRecord[i] && !FPRecord[i]) { //Start record InstancesByIndex[i].Initialise(FInput[i], FPath[i], codec); } } FPRecord = (Spread <bool>)FRecord.Clone(); }
/// <summary> /// /// </summary> /// <param name="param"></param> /// <remarks> /// This code should always be called in main thread /// </remarks> public void RunWait(object @param) { using (var capture = new Capture(m_Source)) { //capture.DuplexQueryFrame(); capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_COUNT, 10); // capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH, Config.FRAME_WIDTH); //5168, 1280, 2304, capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT, Config.FRAME_HEIGHT); //2907, 720, 1536 capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FOURCC, CvInvoke.CV_FOURCC('U', '2', '6', '3')); //622,3730 capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_MONOCROME, 1); CheckErrorThrow(); var task = Task.Factory.StartNew((o) => { var sw = Stopwatch.StartNew(); for (; ;) { using (Image <Bgr, byte> img = capture.QueryFrame()) { CheckErrorThrow(); if (img != null && NewImage != null && sw.Elapsed > LOOP) { var ne = new NewImageEventArgs() { Image = img.Copy(), Param = o }; NewImage(this, ne); break; } } Thread.Sleep(50); } }, @param, TaskCreationOptions.AttachedToParent); Task.WaitAll(task); } }
private void previewBtn_Click(object sender, RoutedEventArgs e) { if (previewBtn.Content.ToString() == "Preview Stream") { if (kinect_sensor != null) { // disable all other buttons DeactivateReplay(); gestureCaptureBtn.IsEnabled = false; gestureRecognitionBtn.IsEnabled = false; gestureReplayBtn.IsEnabled = false; previewBtn.Content = "Stop Stream"; isStreaming = true; kinect_data_manager.ifShowJointStatus = true; frame_rec_buffer.Clear(); kinect_sensor.Start(); } } else { if (kinect_sensor != null) { kinect_sensor.Stop(); gestureCaptureBtn.IsEnabled = true; gestureReplayBtn.IsEnabled = true; gestureRecognitionBtn.IsEnabled = true; isStreaming = false; kinect_data_manager.ifShowJointStatus = false; // save recorded frame to disk if (frame_rec_buffer != null && saveVideoCheckBox.IsChecked.Value) { // create video writer int fwidth = (int)groupBox3.Width + 20; int fheight = (int)groupBox3.Height + 20; SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.Filter = "avi files (*.avi)|*.avi"; saveDialog.FilterIndex = 2; saveDialog.RestoreDirectory = true; if (saveDialog.ShowDialog().Value) { statusbarLabel.Content = "Saving video..."; string videofile = saveDialog.FileName.ToString(); VideoWriter videoWriter = new VideoWriter(videofile, CvInvoke.CV_FOURCC('M', 'J', 'P', 'G'), 15, fwidth, fheight, true); if (videoWriter == null) { MessageBox.Show("Fail to save video. Check if codec has been installed."); } else { for (int i = 0; i < frame_rec_buffer.Count; i++) { // write to video file Emgu.CV.Image <Bgr, byte> cvImg = new Emgu.CV.Image <Bgr, byte>(frame_rec_buffer[i] as Bitmap); videoWriter.WriteFrame <Bgr, byte>(cvImg); } videoWriter.Dispose(); statusbarLabel.Content = "Video saved to " + videofile; } } } frame_rec_buffer.Clear(); previewBtn.Content = "Preview Stream"; // save tracked elbow speed //FileStream file = File.Open("d:\\temp\\test.txt", FileMode.Create); //StreamWriter writer = new StreamWriter(file); //for (int i = 0; i < motion_assessor.jointStatusSeq.Count; i++) // writer.WriteLine(motion_assessor.jointStatusSeq[i][JointType.HandRight].abs_speed); //writer.Close(); } } }
/// <summary> /// /// </summary> /// <param name="param"></param> /// <remarks> /// This code should always be called in main thread /// </remarks> public void RunWait(bool isInit, object @param = null) { Clear(isInit); m_isInit = isInit; Application.Idle += new EventHandler(Application_Idle); foreach (int source in m_Sources) { if (ms_CaptureData.ContainsKey(source)) { using (((Tuple <int, Capture, object>)ms_CaptureData[source]).Item2); } var capture = new Capture(source); capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_COUNT, 10); // capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH, 2304); //Config.FRAME_WIDTH);//5168, 1280, 2304, capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT, 1536); //Config.FRAME_HEIGHT);//2907, 720, 1536 capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FOURCC, CvInvoke.CV_FOURCC('U', '2', '6', '3')); //622,3730 capture.CheckErrorThrow(); ms_CaptureData[source] = new Tuple <int, Capture, object>(source, capture, @param); } }
public override void Start() { _videoWriter = new VideoWriter("DataRenderer.avi", CvInvoke.CV_FOURCC('D', 'I', 'V', 'X'), 25, Width, Height, true); base.Start(); }
protected BaseImageProcessor(bool enableVideoWriter) { _enableVideoWriter = enableVideoWriter; if (_enableVideoWriter) { _videoWriter = new VideoWriter(string.Format("{0}_{1}.avi", GetType().Name, VideoWriterId++), CvInvoke.CV_FOURCC('D', 'I', 'V', 'X'), VideoWriterFps, VideoWriterWidth, VideoWriterHeight, true); } }