2011-08-14 20 views
1

動き検出にAForgeを使用していますが、動き領域を設定できることがわかりました。動きがある場合にのみトリガーするようにすることは可能ですかすべての定義済み領域? 上記の機能をすぐに利用できない場合は、私はそれを書くことを考えています。Aforge.Netの動き検出領域

現在のところ、リージョンはVision LibraryのMotionDetector.csのzoneFrameに設定されています。私は各地域でこれを行うことを考えていますが、それは効率的ではないようです。

これを行う最も効率的な方法は何ですか?

誰か私に以下のコードを説明してもらえますか?

private unsafe void CreateMotionZonesFrame() 
    { 
     lock (this) 
     { 
      // free previous motion zones frame 
      if (zonesFrame != null) 
      { 
       zonesFrame.Dispose(); 
       zonesFrame = null; 
      } 

      // create motion zones frame only in the case if the algorithm has processed at least one frame 
      if ((motionZones != null) && (motionZones.Length != 0) && (videoWidth != 0)) 
      { 
       zonesFrame = UnmanagedImage.Create(videoWidth, videoHeight, PixelFormat.Format8bppIndexed); 

       Rectangle imageRect = new Rectangle(0, 0, videoWidth, videoHeight); 

       // draw all motion zones on motion frame 
       foreach (Rectangle rect in motionZones) 
       { 
        //Please explain here 
        rect.Intersect(imageRect); 

        // rectangle's dimenstion 
        int rectWidth = rect.Width; 
        int rectHeight = rect.Height; 

        // start pointer 
        //Please explain here 
        int stride = zonesFrame.Stride; 

        //Please explain here 
        byte* ptr = (byte*) zonesFrame.ImageData.ToPointer() + rect.Y * stride + rect.X; 

        for (int y = 0; y < rectHeight; y++) 
        { 
         //Please explain here 
         AForge.SystemTools.SetUnmanagedMemory(ptr, 255, rectWidth); 
         ptr += stride; 
        } 
       } 
      } 
     } 
    } 

答えて

1

これを行う最も効率的な方法は何ですか? は各地域に対応しています。私は顕著なパフォーマンスの低下があるだろうとは思わない(私は間違っている可能性)

さて、あなたが囲まれたコードは、次の操作を実行します。

1)のチェックをするかどうかmotionZonesイメージが 2を作成しているかどうかを制約)白の領域をマスクする:

//Please explain here => if the motion region is out of bounds crop it to the image bounds 
rect.Intersect(imageRect); 

//Please explain here => gets the image stride (width step), the number of bytes per row; see: 
//http://msdn.microsoft.com/en-us/library/windows/desktop/aa473780(v=vs.85).aspx 
int stride = zonesFrame.Stride; 

//Please explain here => gets the pointer of the first element in rectangle area 
byte* ptr = (byte*) zonesFrame.ImageData.ToPointer() + rect.Y * stride + rect.X; 

//mask the rectangle area with 255 value. If the image is color every pixel will have the //(255,255, 255) value which is white color 
for (int y = 0; y < rectHeight; y++) 
{ 
    //Please explain here 
    AForge.SystemTools.SetUnmanagedMemory(ptr, 255, rectWidth); 
    ptr += stride; 
} 
関連する問題