-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcapture.ps1
64 lines (53 loc) · 2.1 KB
/
capture.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
[Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[Reflection.Assembly]::LoadWithPartialName("System.IO")
function screenshot([Drawing.Rectangle]$bounds) {
$bmp = New-Object Drawing.Bitmap $bounds.width, $bounds.height
$graphics = [Drawing.Graphics]::FromImage($bmp)
$graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size)
# Applying color adjustmnet
$graphics.DrawImage($bmp,$drawingParallelogram,$drawingRectangle,[System.Drawing.GraphicsUnit]::Pixel , $attributes)
$stream = New-Object IO.MemoryStream
$bmp.Save($stream, ([system.drawing.imaging.imageformat]::png))
# Uncomment this to see the actual screenshot being used for OCR
$bmp.Save(
"./capture.png",
([system.drawing.imaging.imageformat]::png)
)
$graphics.Dispose()
$bmp.Dispose()
return $stream.ToArray()
}
$vc = Get-WmiObject -class "Win32_VideoController"
$mainMonitor = [PSCustomObject]@{
monitorWidth = $vc.CurrentHorizontalResolution[0] #primary monitor
monitorHeight = $vc.CurrentVerticalResolution[0] #primary monitor
}
$posOffset = [PSCustomObject]@{
x = $mainMonitor.monitorWidth
y = 20
w = -395
h = 15
}
$bounds = [Drawing.Rectangle]::FromLTRB(
$posOffset.x + $posOffset.w,
$posOffset.y,
$posOffset.x,
$posOffset.y + $posOffset.h
)
# simple Color adjustment to try and isolate the coordinates to improve OCR success
$drawingRectangle = new-object Drawing.Rectangle 0, 0, $bounds.Width, $bounds.Height
# need to make this because the parameter sets for DrawImage requires them when using the color matrix
$drawingParallelogram = @(
[Drawing.Point]::new(0, 0),
[Drawing.Point]::new($bounds.Width, 0),
[Drawing.Point]::new(0, $bounds.Height))
[single[][]] $ColorCorrectionMatrix =
(1.8, 1.8, 1.8, 0, 0),
(1.8,1.8, 1.8, 0, 0),
(3.0,3.0, 3.0, 0, 0),
(-0.45, -0.45, -0.45, 1, 0),
(-3.0,-3.0, -3.0, 0, 1)
$colorMatrix = [System.Drawing.Imaging.ColorMatrix]::new($ColorCorrectionMatrix)
$attributes = [System.Drawing.Imaging.ImageAttributes]::new()
$attributes.SetColorMatrix($colorMatrix)
screenshot $bounds