2012-03-10 52 views
0

ウェブカメラのビデオを表示してフィードからモーションを検出できる簡単なプログラムを作成しましたが、動きが検出されたときにウェブカメラから録画する方法を理解していません。私はAforge.Netサイトを検索しましたが、私は何をする必要があるのか​​を理解することは難しいと思っています。動きが検出されたら、あらかじめ決められた場所に録画を開始し、動きが検出されなかった場合は、一定時間録画を続けてから停止します。これは私が今まで持っていた私のプログラムの一部です...動きに基づいてWebカメラから録画する。 aforgeを使用したwpf

もっと情報やコードを提供する必要があるかどうか私に説明して教えてください。おかげ

$ //オープンビデオソース

private void OpenVideoSource(IVideoSource source) 
    { 
     // set busy cursor 
     //this.Cursor = Cursors.WaitCursor; 

     // close previous video source 
     CloseVideoSource(); 

     //motionDetectionType = 1; 
     //SetMotionDetectionAlgorithm(new TwoFramesDifferenceDetector()); 
     //motionProcessingType = 1; 
     //SetMotionProcessingAlgorithm(new MotionAreaHighlighting()); 

     // start new video source 
     videoSourcePlayer.VideoSource = new AsyncVideoSource(source); 


     videoSourcePlayer.NewFrame +=new VideoSourcePlayer.NewFrameHandler(videoSourcePlayer_NewFrame); 
     //videoSourcePlayer.DesiredFrameRate = 30; 
     //webcam's default frame rate will be used instead of above code that has an error 


     // create new video file 
     writer.Open("test.avi", width, height, 25, VideoCodec.MPEG4); 
     // create a bitmap to save into the video file 
     Bitmap image = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); 
     // write 1000 video frames 
     for (int i = 0; i < 1000; i++) 
     { 
      image.SetPixel(i % width, i % height, System.Drawing.Color.Red); 
      writer.WriteVideoFrame(image); 
     } 
     writer.Close(); 



     try 
     { 
      videoSourcePlayer.Start(); 
      //motionAlarmLevel = sldMotionSensitivity.Value/100; 
     } 

     catch (Exception x) 
     { 
      System.Windows.MessageBox.Show(x.ToString()); 
     } 
     //videoSource.DesiredFrameSize = new System.Drawing.Size(800,600); 
     videoSourcePlayer.BorderColor = System.Drawing.Color.Blue; 
     // reset statistics 
     statIndex = statReady = 0; 

     // start timers 
     clock.Start(); 
     //alarm.Start(); 

     videoSource = source; 

     //this.Cursor = Cursors.Default; 
    } 

    // Close current video source 
    private void CloseVideoSource() 
    { 
     // set busy cursor 
     //this.Cursor = Cursors.WaitCursor; 

     // stop current video source 
     videoSourcePlayer.SignalToStop(); 

     // wait 2 seconds until camera stops 
     for (int i = 0; (i < 50) && (videoSourcePlayer.IsRunning); i++) 
     { 
      Thread.Sleep(100); 
     } 
     if (videoSourcePlayer.IsRunning) 
      videoSourcePlayer.Stop(); 

     // stop timers 
     clock.Stop(); 
     //alarm.Stop(); 

     motionHistory.Clear(); 

     // reset motion detector 
     if (detector != null) 
      detector.Reset(); 

     //videoSourcePlayer.BorderColor = System.Drawing.Color.Red; 
     //this.Cursor = Cursors.Default; 
    } 

    // New frame received by the player 
    void videoSourcePlayer_NewFrame(object sender, ref Bitmap image) 
    { 

     lock (this) 
     { 
      if (detector != null) 
      { 
       //motion detected 
       if (detector.ProcessFrame(image) > motionAlarmLevel) 
       { 
        //float motionLevel = detector.ProcessFrame(image); 
        videoSourcePlayer.BorderColor = System.Drawing.Color.Red; 
        Dispatcher.BeginInvoke(new ThreadStart(delegate { lblMotionDetected.Content = "Motion Detected"; })); 
        //lblMotionDetected.Content = "Motion Detected"; 
        //flash = (int)(2 * (1000/alarm.Interval)); 
       } 

       // no motion detected 
       if (detector.ProcessFrame(image) < motionAlarmLevel) 
       { 
        videoSourcePlayer.BorderColor = System.Drawing.Color.Black; 
        Dispatcher.BeginInvoke(new ThreadStart(delegate { lblMotionDetected.Content = "No Motion Detected"; })); 
       } 


       // if (motionLevel > motionAlarmLevel) 
       // { 
       //  // flash for 2 seconds 
       //  timer.Start(); 
       // } 

      } 
     } 
    } 

答えて

0

ispyと呼ばれるオープンソースプロジェクトがあります - http://www.ispyconnect.com、まさにその作業を行います。ソースはダウンロード可能です。

関連する問題