Created
June 17, 2021 06:46
-
-
Save joshooaj/01967ebaa3307e693f959df9a7bbf4e1 to your computer and use it in GitHub Desktop.
Add live snapshots to Get-CameraReport
This file contains hidden or 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 ConvertFrom-Snapshot { | |
| <# | |
| .SYNOPSIS | |
| Converts from the output provided by Get-Snapshot to a [System.Drawing.Image] object. | |
| .DESCRIPTION | |
| Converts from the output provided by Get-Snapshot to a [System.Drawing.Image] object. Don't | |
| forget to call Dispose() on Image when you're done with it! | |
| .EXAMPLE | |
| PS C:\> $image = $camera | Get-Snapshot -Live | ConvertFrom-Snapshot | |
| Get's a live snapshot from $camera and converts it to a System.Drawing.Image object and saves it to $image | |
| .INPUTS | |
| Accepts a byte array, and will accept the byte array from Get-Snapshot by property name. The property name for | |
| a live image is 'Content' while the property name for the JPEG byte array on a snapshot from recorded video is | |
| 'Bytes'. | |
| .OUTPUTS | |
| [System.Drawing.Image] | |
| .NOTES | |
| Don't forget to call Dispose() when you're done with the image! | |
| #> | |
| [CmdletBinding()] | |
| [OutputType([system.drawing.image])] | |
| param( | |
| [Parameter(Mandatory, ValueFromPipelineByPropertyName)] | |
| [Alias('Bytes')] | |
| [byte[]] | |
| $Content | |
| ) | |
| process { | |
| if ($null -eq $Content -or $Content.Length -eq 0) { | |
| return $null | |
| } | |
| $ms = [io.memorystream]::new($Content) | |
| Write-Output ([system.drawing.image]::FromStream($ms)) | |
| } | |
| } | |
| Get-CameraReport | Foreach-Object { | |
| # Call Dispose() on the last image we processed - we don't need it anymore | |
| if ($null -ne $lastImage) { | |
| $lastImage.Dispose() | |
| } | |
| $image = Get-Snapshot -CameraId $_.CameraId -Live -Width 200 -Height 112 -KeepAspectRatio -IncludeBlackBars -Quality 95 -ErrorAction Ignore | ConvertFrom-Snapshot | |
| $lastImage = $image | |
| # Add the image to the current camera report row so it can be picked up by Export-Excel later | |
| $_ | Add-Member -MemberType NoteProperty -Name Snapshot -Value ($image) | |
| $_ | |
| } | Export-Excel -Path C:\temp\test.xlsx -WorksheetName 'Camera Report' | |
| if ($null -ne $lastImage) { | |
| $lastImage.Dispose() | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that this example uses a modified version of the ImportExcel PowerShell module by Doug Finke. It will not work the same using the publicly available release of ImportExcel.