2011-08-14 4 views
1

동작 감지에 AForge를 사용하고 있으며 동작 영역을 설정할 수 있음을 알고 있습니다. 움직임이있는 경우에만 트리거하도록 할 수 있습니까? 정의 된 모든 영역? 위의 기능을 쉽게 사용할 수없는 경우 필자는이를 작성하려고 생각하고 있습니다.Aforge.Net의 동작 감지 영역

현재 비전 라이브러리의 MotionDetector.cs에서 region이 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; 
}