#include <APIConstants.au3>
#include <GDIPlus.au3>
#include <WinAPIEx.au3>
#include <GUIConstants.au3>
#include <Webcam.au3> ; http://www.autoitscript.com/forum/topic/68866-webcam-udf/page__hl__Webcam%20%20UDf
$gui = GUICreate('Webcam Test', 640, 480)
HotKeySet('{Esc}', 'quit')
_WebcamInit()
_Webcam($gui, 640, 480, 0, 0)
GUISetState(@SW_HIDE)
Global $razn = 6 ; уровень детекта
Global $C = 100 ; коэфф маштабирования
$checksum = _Matrix()
$i = 0
While 1
;Sleep(400)
$Ma = _Matrix()
For $i = 0 To UBound($Ma) - 1
If $checksum[$i] <> $Ma[$i] Then $i += $i
Next
If $i > $razn Then
$checksum = $Ma
$i = 0
ConsoleWrite(Random(1, 10) & @CRLF) ; какие-то цифры, если есть движение перед камерой
Else
ConsoleWrite('0' & @CRLF) ; 0, если движения нет
EndIf
WEnd
Func _Matrix()
_WebcamSnapShot(@ScriptDir & '\snapshot.bmp')
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\snapshot.bmp')
If $hImage = 0x00000000 Then Exit 2
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$W = _GDIPlus_ImageGetWidth($hImage)
$H = _GDIPlus_ImageGetHeight($hImage)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()
Dim $Matrix[Round($H / $C)][Round($W / $C)]
Dim $HLS[3]
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()
$hSrcDC = _WinAPI_CreateCompatibleDC(0)
$hSrcSv = _WinAPI_SelectObject($hSrcDC, $hBitmap)
$hDstDC = _WinAPI_CreateCompatibleDC(0)
$hDib = _WinAPI_CreateDIB(1, 1)
$hDstSv = _WinAPI_SelectObject($hDstDC, $hDib)
_WinAPI_SetStretchBltMode($hDstDC, $HALFTONE)
For $y = 0 To $H / $C - 1
For $x = 0 To $W / $C - 1
_WinAPI_StretchBlt($hDstDC, 0, 0, 1, 1, $hSrcDC, $x * $C, $y * $C, $C, $C, $SRCCOPY)
$RGB = _WinAPI_GetPixel($hDstDC, 0, 0)
_WinAPI_ColorRGBToHLS($RGB, $HLS[0], $HLS[1], $HLS[2])
$Matrix[$y][$x] = $HLS[1]
Next
Next
_WinAPI_SelectObject($hSrcDC, $hSrcSv)
_WinAPI_DeleteObject($hBitmap)
_WinAPI_DeleteDC($hSrcDC)
_WinAPI_SelectObject($hDstDC, $hDstSv)
_WinAPI_DeleteObject($hDib)
_WinAPI_DeleteDC($hDstDC)
;_ArrayDisplay($Matrix, 'Luminance')
$Min = 240
$Max = 0
For $y = 0 To $H / $C - 1
For $x = 0 To $W / $C - 1
If $Min > $Matrix[$y][$x] Then $Min = $Matrix[$y][$x]
If $Max < $Matrix[$y][$x] Then $Max = $Matrix[$y][$x]
Next
Next
$Q = Round(($Min + $Max) / 2)
$ggg = 0
Dim $fff[$W / $C - 1]
For $y = 0 To $H / $C - 1
For $x = 0 To $W / $C - 1
;$Matrix[$y][$x] = $Matrix[$y][$x]
$ggg += Number($Matrix[$y][$x] < $Q)
Next
$fff[$y] = $ggg
$ggg = 0
Next
Return $fff
EndFunc ;==>_Matrix
Func quit()
Exit
EndFunc ;==>quit