[C#][DirectShow] Capturer flux video

mecano14 Messages postés 35 Date d'inscription samedi 26 février 2005 Statut Membre Dernière intervention 12 août 2006 - 4 août 2006 à 14:44
mecano14 Messages postés 35 Date d'inscription samedi 26 février 2005 Statut Membre Dernière intervention 12 août 2006 - 7 août 2006 à 09:40
Bonjour, j'utilise le code suivant pour afficher le flux video d'une webcam dans un pictureBox
Dans le code en dessous on utilise un panel mais c'est exactement la meme chose

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

using DShowNET;

using DShowNET.Device;

using System.Runtime.InteropServices;

using System.IO;

using System.Diagnostics;

namespace testCam

{

      ///<summary></summary>

      /// Description résumée de Form1.

      ///

      publicclass Form1 : System.Windows.Forms.Form

      {

            private System.Windows.Forms.Panel panel1;

            ///<summary></summary>

            /// Variable nécessaire au concepteur.

            ///

            private System.ComponentModel.Container components = null;

 

            public Form1()

            {

                  //

                  //

                  InitializeComponent();

                  //

                  //

            }

            ///<summary></summary>

            /// Nettoyage des ressources utilisées.

            ///

            protectedoverridevoid Dispose( bool disposing )

            {

                  if( disposing )

                  {

                        if (components != null)

                        {

                             components.Dispose();

                        }

                  }

                  base.Dispose( disposing );

            }

            #region Code généré par le Concepteur Windows Form

     

            privatevoid InitializeComponent()

            {

                  this.panel1 = new System.Windows.Forms.Panel();

                  this.SuspendLayout();

                  //

                  // panel1

                  //

                  this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;

                  this.panel1.Location = new System.Drawing.Point(0, 0);

                  this.panel1.Name = "panel1";            

                  this.panel1.Size = new System.Drawing.Size(376, 333);

                  this.panel1.TabIndex = 0;

                  //

                  // Form1

                  //

                  this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

                  this.ClientSize = new System.Drawing.Size(376, 333);

                  this.Controls.Add(this.panel1);

                  this.Name = "Form1";

                  this.Text = "Form1";

                  this.Load += new System.EventHandler(this.Form1_Load);

                  this.ResumeLayout(false);

            }

            #endregion

            ///<summary></summary>

            /// Point d'entrée principal de l'application.

            ///

            [STAThread]

            staticvoid Main()

 

            {

                  Application.Run(new Form1());

            }

            privatevoid Form1_Load(object sender, System.EventArgs e)

            {

                  ICaptureGraphBuilder2 CaptureGraph = null;

                  IGraphBuilder GraphBuilder = null;

                  IMediaControl MediaControl = null;

                  IBaseFilter FiltreVideoInput = null;

                  IBaseFilter ASFWriter = null;

                  ArrayList Webcamliste;

                  DsDevice Webcam = null;           

                  int hr;

                  if( ! DsUtils.IsCorrectDirectXVersion() ) // teste si la version de DirectX est OK

                  {

                  MessageBox.Show( this, "DirectX 9.0 n'est pas installé sur votre système", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Stop );

                  this.Close();

                  }

                  if(!DsDev.GetDevicesOfCat( FilterCategory.VideoInputDevice, out Webcamliste) )

                  {

                  MessageBox.Show( this, "Aucune webcam n'a été trouvée", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Stop );                     this.Close();

                  }

                  else

                  {

                        Webcam = (DsDevice)Webcamliste[0];

                  }

                  object objet =null;

                  UCOMIMoniker moniker = Webcam.Mon;

                  Guid gbasefilter = typeof( IBaseFilter ).GUID;

                  moniker.BindToObject( null, null, ref gbasefilter, out objet );

                  FiltreVideoInput = (IBaseFilter) objet;

                  objet = null ;   

                  Type comType = null;
                  object ObjetCOM null;                                                comType Type.GetTypeFromCLSID( Clsid.FilterGraph );
                  ObjetCOM Activator.CreateInstance( comType );                       GraphBuilder (IGraphBuilder) ObjetCOM;                                     ObjetCOM = null;

 

                  Guid clsid = Clsid.CaptureGraphBuilder2;

                  Guid gcapture = typeof(ICaptureGraphBuilder2).GUID;

                  ObjetCOM = DsBugWO.CreateDsInstance( ref clsid, ref gcapture );

                  CaptureGraph = (ICaptureGraphBuilder2) ObjetCOM;

                  ObjetCOM = null;            

                  MediaControl = (IMediaControl)GraphBuilder;
                  IVideoWindow videoWin   (IVideoWindow)GraphBuilder;                  hr CaptureGraph.SetFiltergraph( GraphBuilder );                     hr = GraphBuilder.AddFilter( FiltreVideoInput, "Capture Video" );

                  Guid categorie = PinCategory.Capture;

     

                  Guid media = MediaType.Video;

                  hr = CaptureGraph.RenderStream( ref categorie, ref media, FiltreVideoInput, null, null );

 

                  videoWin.put_Owner( panel1.Handle );

                  hr = videoWin.SetWindowPosition( 0, 0, panel1.Width, panel1.Height );

                  videoWin.put_WindowStyle( 0x40000000);
                  hr videoWin.put_Visible( 1 );                                        hr MediaControl.Run();

      }

      }

}

Ca marche très bien, maintenant je souhaiterai capturer une frame de ce flux video à un instant t mais je ne trouve pas le moyen de le faire.
Bien entendu la proprieté Image.Image ne retourne rien

Voici l'article ou j'ai eu ce code : Cliquez ici

Des idées?

2 réponses

Supopste Messages postés 69 Date d'inscription dimanche 30 octobre 2005 Statut Membre Dernière intervention 6 mars 2008
4 août 2006 à 15:02
J'ai eu exactement le même problèe et je n'ai moi aussi trouvé aucune solution, donc j'espère que quelqu'un ici pourra nous aider...
0
mecano14 Messages postés 35 Date d'inscription samedi 26 février 2005 Statut Membre Dernière intervention 12 août 2006
7 août 2006 à 09:40
J'ai trouvé un truc très interessant

http://www.codeproject.com/cs/media/webcamservice.asp

Tout est dans Capture.cs
0
Rejoignez-nous