Created
May 29, 2024 22:56
-
-
Save joshooaj/0d83acc455c8871c8f163d301588bd49 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-VmsCameraMotion { | |
<# | |
.SYNOPSIS | |
Gets the motion detection settings for one or more cameras. | |
.DESCRIPTION | |
The `Get-VmsCameraMotion` cmdlet gets the motion detection settings for one or more cameras. The MotionDetection | |
object for a camera can be accessed using $camera.MotionDetectionFolder.MotionDetections[0]. This command can be | |
considered a PowerShell-friendly shortcut for accessing these settings. | |
The only difference between using this command or accessing the MotionDetection objects directly is that this | |
command adds a NoteProperty to the MotionDetection object named "Camera" to make it easier to access the Camera | |
object associated with the MotionDetection object. | |
.PARAMETER Camera | |
One or more cameras returned by the Get-VmsCamera cmdlet. | |
.EXAMPLE | |
Get-VmsCamera | Get-VmsCameraMotion | Where-Object Enabled -eq $false | Select-Object -ExpandProperty Camera | |
Get all enabled cameras where motion detection is disabled. | |
#> | |
[OutputType([VideoOS.Platform.ConfigurationItems.MotionDetection])] | |
param ( | |
[Parameter(Mandatory, ValueFromPipeline)] | |
[VideoOS.Platform.ConfigurationItems.Camera[]] | |
$Camera | |
) | |
process { | |
foreach ($currentDevice in $Camera) { | |
$currentDevice.MotionDetectionFolder.MotionDetections[0] | Add-Member -MemberType NoteProperty -Name Camera -Value $currentDevice -PassThru | |
} | |
} | |
} | |
function Set-VmsCameraMotion { | |
<# | |
.SYNOPSIS | |
Sets motion detection settings for one or more cameras. | |
.DESCRIPTION | |
The `Set-VmsCameraMotion` cmdlet sets motion detection settings for one or more cameras. | |
.PARAMETER Camera | |
One or more cameras on which to update motion detection settings. | |
.PARAMETER DetectionMethod | |
A value of 'Normal', 'Optimized', or 'Fast' which represent 100%, 25%, and 12% detection resolution respectively. | |
For example, a DetectionMethod of 'Optimized' would only evaluate every 4th pixel requiring less compute than | |
'Normal' or 100%. | |
.PARAMETER Enabled | |
A boolean value specifying whether motion detection should be enabled or disabled. | |
.PARAMETER ExcludeRegions | |
A string of 0's and 1's representing the chosen grid size. Areas of the grid marked with a 1 will be excluded from | |
motion detection. | |
.PARAMETER GenerateMotionMetadata | |
Specifies whether motion metadata used to support smart search capabilities will be generated. | |
.PARAMETER GridSize | |
The size of the grid representing the motion detection exclusion region. Supported values are 'Grid8X8', 'Grid16X16', 'Grid32X32', 'Grid64X64'. | |
.PARAMETER HardwareAccelerationMode | |
Set the HardwareAccelerationMode to Automatic, or Off. | |
.PARAMETER KeyframesOnly | |
Only evaluate keyframes for motion. By default, keyframes usually arrive once per second. They can be much farther | |
apart when using a custom keyframe interval, or a "smart" codec with a dynamic GOP (group of pictures) length. | |
.PARAMETER ManualSensitivity | |
A value between 0 and 300 representing how much an individual pixel must change before it is considered a changing | |
pixel. Note that the Management Client user interface represents this number as a range of 0-100. In PowerShell you | |
should see a number 3x larger than the number shown in Management Client. | |
.PARAMETER ManualSensitivityEnabled | |
Specifies that the ManualSensitivity and Threshold parameters should be used to evaluate motion instead of using | |
automatic motion detection. | |
.PARAMETER ProcessTime | |
Specifies the time interval between each image evaluated for motion. This applies only to cameras streaming MJPEG. | |
.PARAMETER Threshold | |
Specifies how many pixels must change in order to trigger a motion started event. | |
.PARAMETER UseExcludeRegions | |
Specifies whether the ExcludeRegions mask should be applied so that changes in the masked areas of the image are | |
ignored for motion detection. | |
.PARAMETER PassThru | |
Return the camera object to the pipeline after updating motion detection settings. | |
.EXAMPLE | |
$splat = @{ | |
Enabled = $true | |
HardwareAccelerationMode = 'Automatic' | |
KeyframesOnly = $true | |
DetectionMethod = 'Fast' | |
ProcessTime = 'Ms500' | |
GenerateMotionMetadata = $true | |
ManualSensitivityEnabled = $false | |
UseExcludeRegions = $false | |
GridSize = 'Grid16X16' | |
ExcludeRegions = '0' * (16*16) | |
} | |
Get-VmsCamera | Set-VmsCameraMotion @splat -Verbose -WhatIf | |
Updates all cameras to the default motion detection settings when the -WhatIf switch is removed. | |
#> | |
[CmdletBinding(SupportsShouldProcess)] | |
[OutputType([VideoOS.Platform.ConfigurationItems.Camera])] | |
param ( | |
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)] | |
[VideoOS.Platform.ConfigurationItems.Camera[]] | |
$Camera, | |
[Parameter()] | |
[ValidateSet('Normal', 'Optimized', 'Fast')] | |
[string] | |
$DetectionMethod, | |
[Parameter()] | |
[bool] | |
$Enabled, | |
[Parameter()] | |
[string] | |
$ExcludeRegions, | |
[Parameter()] | |
[bool] | |
$GenerateMotionMetadata, | |
[Parameter()] | |
[ValidateSet('Grid8X8', 'Grid16X16', 'Grid32X32', 'Grid64X64')] | |
[string] | |
$GridSize, | |
[Parameter()] | |
[ValidateSet('Automatic', 'Off')] | |
[string] | |
$HardwareAccelerationMode, | |
[Parameter()] | |
[bool] | |
$KeyframesOnly, | |
[Parameter()] | |
[ValidateRange(0, 300)] | |
[int] | |
$ManualSensitivity, | |
[Parameter()] | |
[bool] | |
$ManualSensitivityEnabled, | |
[Parameter()] | |
[ValidateSet('Ms100', 'Ms250', 'Ms500', 'Ms750', 'Ms1000')] | |
[string] | |
$ProcessTime, | |
[Parameter()] | |
[ValidateRange(0, 10000)] | |
[int] | |
$Threshold, | |
[Parameter()] | |
[bool] | |
$UseExcludeRegions, | |
[Parameter()] | |
[switch] | |
$PassThru | |
) | |
begin { | |
$members = @{} | |
} | |
process { | |
foreach ($currentDevice in $Camera) { | |
$dirty = $false | |
try { | |
$motion = $currentDevice.MotionDetectionFolder.MotionDetections[0] | |
if ($members.Count -eq 0) { | |
# Cache settable property names as keys in hashtable | |
$motion | Get-Member -MemberType Property | Where-Object Definition -match 'set;' | ForEach-Object { | |
$members[$_.Name] = $null | |
} | |
} | |
foreach ($parameter in $PSCmdlet.MyInvocation.BoundParameters.GetEnumerator()) { | |
$key, $newValue = $parameter.Key, $parameter.Value | |
if (!$members.ContainsKey($key)) { | |
continue | |
} elseif ($motion.$key -eq $newValue) { | |
Write-Verbose "Motion detection setting '$key' is already '$newValue' on $currentDevice" | |
continue | |
} | |
Write-Verbose "Changing motion detection setting '$key' to '$newValue' on $currentDevice" | |
$motion.$key = $newValue | |
$dirty = $true | |
} | |
if ($PSCmdlet.ShouldProcess($currentDevice, "Update motion detection settings")) { | |
if ($dirty) { | |
$motion.Save() | |
} | |
if ($PassThru) { | |
$currentDevice | |
} | |
} | |
} catch { | |
Write-Error -TargetObject $currentDevice -Exception $_.Exception -Message $_.Exception.Message -Category $_.CategoryInfo.Category | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment