Pelco Developer Network (PDN)

MotionDetection Troubleshooting

Some of the following answers involving code samples have a set of assumptions for proper operation by the C# programming language. For better ease of understanding, the code samples shown here may differ from the actual downloadable code samples. Refer to MotionDetection Issues and MotionDetection for more details.

 

 

 

Which devices support the MotionDetection service?

Refer to MotionDetection Issues for details.




What is a region of interest (ROI)?

A region of interest denotes a motion detection region within a video frame. A motion detection region is essentially a grid of motion detection that is 16x16 pixel cell blocks.




How do I perform basic configuration for motion detection?

Refer to the 'Is there a programmatic way to determine an Endura device's control URL?' entry for the ideal way of determining the control URL.

  1. Initialize an instance of the class that acts as a representative of the MotionDetection web service.
  2. Make a call to the GetMDConfiguration action to retrieve the device's current motion detection configuration. (This is a safe precaution.)
  3. Configure the MDConfig (motion detection configuration) instance according to your needs.
  4. Make a call to the SetMDConfiguration action along with the MDConfig instance as a parameter.

C# Example

using CSharpIPCam.MotionDetectionRef;

namespace YourNamespace
{
  static class Program
  {
    static void Main() 
    {
      try
      {
        string CameraAddress = "192.168.1.5:49156";
        string cameraNumber = 1;
        MotionDetectionRef.MotionDetection mdService = 
            new MotionDetectionRef.MotionDetection();

        //This is not the ideal way of setting the control URL. see above Note
        mdService.Url = 
            "http://" + CameraAddress + "/control/MotionDetection-" + cameraNumber;

        MDConfig mdConfig = mdService.GetMDConfiguration();
        mdConfig.alarmEnabled = 1;
        mdConfig.maxSensitivity = 100;
        mdService.SetMDConfiguration(mdConfig);
      }
      catch (Exception e)
      {
        Console.WriteLine( e.Message );
      }
    }
  }
}



How do I retreive the current motion detection configuration (alarm state, max regions, ...)?

Refer to "How do I perform basic configuration for motion detection?" above for details.




How do I create a region of interest (ROI)?

Refer to Determining a Pelco Device's Port Number entry for the ideal way of determining the control URL.

  1. Initialize an instance of the class that acts as a representative of the MotionDetection web service.
  2. Create a Region array instance and set the size to your needs.
  3. Define a new instance of a Region and add it to the Region array.
  4. Define two new Coordinate instances, with one representing the top left corner of the motion detection Region and the other representing the lower right corner. Assign these Coordinate instances to your previously defined Region instance.
  5. Set the Region instance's base64 encoded mask value.
  6. Call the SetRegion action with Region array as a parameter.

C# Example

using CSharpIPCam.MotionDetectionRef;

namespace YourNamespace
{
  static class Program
  {
    static void Main()
    {
      try
      {
        int asyncId = 1;
        bool asyncIdNeeded = true;
        string CameraAddress = "192.168.1.5:49156";
        string cameraNumber = 1;

        MotionDetectionRef.MotionDetection mdService = 
            new MotionDetectionRef.MotionDetection();

        //This is not the ideal way of setting the control URL. see above Note
        mdService.Url = 
            "http://" + CameraAddress + "/control/MotionDetection-" + cameraNumber;

        MotionDetectionRef.Region[] mdRegions = new MotionDetectionRef.Region[1];

        // Configure a motion detection zone
        mdRegions[0] = new MotionDetectionRef.Region()
        {
          name = "Region1", larmEnabled = 1, sensitivity = 100, threshold = 10, 
              coordinate = new coordinate[2]
        };

        MotionDetectionRef.coordinate c1 = new MotionDetectionRef.coordinate()
        {
          position = "upperLeft". row = 5, column = 13 };
          mdRegions[0].coordinate[0] = c1;

          MotionDetectionRef.coordinate c2 = new MotionDetectionRef.coordinate()
          {
            position = "lowerRight", row = 20, column = 29};
            mdRegions[0].coordinate[1] = c2;

            // Hard-coded here, this mask represents a full block for the block size
            // represented above. Mask is user defined and is base64 encoded.
            mdRegions[0].mask = "////////////////////////////////////////=";

            // Set the region
            mdService.SetMDRegions(mdRegions, ref asyncId, ref asyncIdNeeded);
          }
        }
      }
      catch (Exception e)
      {
        Console.WriteLine( e.Message );
      }
    }
  }
}



How do I delete existing region(s) of interest (ROI)?

Refer to Determining a Pelco Device's Port Number for the ideal way of determining the control URL.

  1. Initialize an instance of the class that acts as a representative of the MotionDetection web service.
  2. Call the ClearMDRegions action along with a MDRegionList instance, containing the regions you would like deleted, as a parameter.

C# Example

using CSharpIPCam.MotionDetectionRef;

namespace YourNamespace
{
  static class Program
  {
    static void Main()
    {
      try
      {
        string CameraAddress = "192.168.1.5:49156";
        string cameraNumber = 1;
        MotionDetectionRef.MotionDetection mdService = 
            new MotionDetectionRef.MotionDetection();

        //This is not the ideal way of setting the control URL. see above Note
        mdService.Url = 
            "http://" + CameraAddress + "/control/MotionDetection-" + cameraNumber;

        //retrieve the regions to delete (in this case all of them)
        MotionDetectionRef.Region[] mdRegions = 
            mdService.GetMDRegions(ref asyncId, ref asyncIdNeeded);

        //pass a list of MDregions to delete
        mdService.ClearMDRegions(mdRegions);
      }
      catch (Exception e)
      {
        Console.WriteLine( e.Message ); 
      }
    }
  }
}



Appendix

Pelco Device Port Number

Pelco device port numbers will rarely change. However, a device port number may change when a device restarts. While the port number is unlikely to change when the device restarts, you should account for it. For details on determining a device's current port number, refer to Determining a Pelco Device's Port Number.

Pelco Device Control URL

Be aware that all examples utilize a method of determining the device's control URL in a way that is not suitable for production. This was done to keep our example code simple, and focused on the main task being demonstrated.

To properly determine a device's control URL, refer to Determining a Pelco Device's Port Number.

C# Notes

For the C# code examples, you should have already generated proxy classes from the WSDLs, or you should have access to generated proxy classes. You can find Pelco web service proxy classes in the samples directory. For more details, refer to Installation and Configuration.

If you want to generate the classes that represent the web services yourself, you should use MS Visual Studio (2005 or up) for WSDL stub/proxy class generation.

To implement any examples related to eventing, you must be on the Windows platform and you must register Pelco ActiveX controls. For more details, refer to Installation and Configuration.

You should not utilize Mono, which is an open source alternative CLR for .NET.