Webcam UDF


SUBMITTED BY: Guest

DATE: May 29, 2013, 7:07 a.m.

FORMAT: Text only

SIZE: 7.3 kB

HITS: 2106

  1. #include-once
  2. #include <GUIConstants.au3>
  3. ;~ #####################################################
  4. ;~ ### ###
  5. ;~ ### Webcam UDF ###
  6. ;~ ### ###
  7. ;~ ### Functions : _WebcamInit() ###
  8. ;~ ### _Webcam() ###
  9. ;~ ### _WebcamStop() ###
  10. ;~ ### _WebcamSnapShot() ###
  11. ;~ ### ###
  12. ;~ ### Made by L|M|TER ###
  13. ;~ ### --------------------------------------------- ###
  14. ;~ ### ###
  15. ;~ ### Copyright ©2008 - L|M|TER ###
  16. ;~ ### ###
  17. ;~ #####################################################
  18. ;~ Declaring Variables
  19. $WM_CAP_START = 0x400
  20. $WM_CAP_UNICODE_START = $WM_CAP_START +100
  21. $WM_CAP_PAL_SAVEA = $WM_CAP_START + 81
  22. $WM_CAP_PAL_SAVEW = $WM_CAP_UNICODE_START + 81
  23. $WM_CAP_UNICODE_END = $WM_CAP_PAL_SAVEW
  24. $WM_CAP_ABORT = $WM_CAP_START + 69
  25. $WM_CAP_DLG_VIDEOCOMPRESSION = $WM_CAP_START + 46
  26. $WM_CAP_DLG_VIDEODISPLAY = $WM_CAP_START + 43
  27. $WM_CAP_DLG_VIDEOFORMAT = $WM_CAP_START + 41
  28. $WM_CAP_DLG_VIDEOSOURCE = $WM_CAP_START + 42
  29. $WM_CAP_DRIVER_CONNECT = $WM_CAP_START + 10
  30. $WM_CAP_DRIVER_DISCONNECT = $WM_CAP_START + 11
  31. $WM_CAP_DRIVER_GET_CAPS = $WM_CAP_START + 14
  32. $WM_CAP_DRIVER_GET_NAMEA = $WM_CAP_START + 12
  33. $WM_CAP_DRIVER_GET_NAMEW = $WM_CAP_UNICODE_START + 12
  34. $WM_CAP_DRIVER_GET_VERSIONA = $WM_CAP_START + 13
  35. $WM_CAP_DRIVER_GET_VERSIONW = $WM_CAP_UNICODE_START + 13
  36. $WM_CAP_EDIT_COPY = $WM_CAP_START + 30
  37. $WM_CAP_END = $WM_CAP_UNICODE_END
  38. $WM_CAP_FILE_ALLOCATE = $WM_CAP_START + 22
  39. $WM_CAP_FILE_GET_CAPTURE_FILEA = $WM_CAP_START + 21
  40. $WM_CAP_FILE_GET_CAPTURE_FILEW = $WM_CAP_UNICODE_START + 21
  41. $WM_CAP_FILE_SAVEASA = $WM_CAP_START + 23
  42. $WM_CAP_FILE_SAVEASW = $WM_CAP_UNICODE_START + 23
  43. $WM_CAP_FILE_SAVEDIBA = $WM_CAP_START + 25
  44. $WM_CAP_FILE_SAVEDIBW = $WM_CAP_UNICODE_START + 25
  45. $WM_CAP_FILE_SET_CAPTURE_FILEA = $WM_CAP_START + 20
  46. $WM_CAP_FILE_SET_CAPTURE_FILEW = $WM_CAP_UNICODE_START + 20
  47. $WM_CAP_FILE_SET_INFOCHUNK = $WM_CAP_START + 24
  48. $WM_CAP_GET_AUDIOFORMAT = $WM_CAP_START + 36
  49. $WM_CAP_GET_CAPSTREAMPTR = $WM_CAP_START + 1
  50. $WM_CAP_GET_MCI_DEVICEA = $WM_CAP_START + 67
  51. $WM_CAP_GET_MCI_DEVICEW = $WM_CAP_UNICODE_START + 67
  52. $WM_CAP_GET_SEQUENCE_SETUP = $WM_CAP_START + 65
  53. $WM_CAP_GET_STATUS = $WM_CAP_START + 54
  54. $WM_CAP_GET_USER_DATA = $WM_CAP_START + 8
  55. $WM_CAP_GET_VIDEOFORMAT = $WM_CAP_START + 44
  56. $WM_CAP_GRAB_FRAME = $WM_CAP_START + 60
  57. $WM_CAP_GRAB_FRAME_NOSTOP = $WM_CAP_START + 61
  58. $WM_CAP_PAL_AUTOCREATE = $WM_CAP_START + 83
  59. $WM_CAP_PAL_MANUALCREATE = $WM_CAP_START + 84
  60. $WM_CAP_PAL_OPENA = $WM_CAP_START + 80
  61. $WM_CAP_PAL_OPENW = $WM_CAP_UNICODE_START + 80
  62. $WM_CAP_PAL_PASTE = $WM_CAP_START + 82
  63. $WM_CAP_SEQUENCE = $WM_CAP_START + 62
  64. $WM_CAP_SEQUENCE_NOFILE = $WM_CAP_START + 63
  65. $WM_CAP_SET_AUDIOFORMAT = $WM_CAP_START + 35
  66. $WM_CAP_SET_CALLBACK_CAPCONTROL = $WM_CAP_START + 85
  67. $WM_CAP_SET_CALLBACK_ERRORA = $WM_CAP_START + 2
  68. $WM_CAP_SET_CALLBACK_ERRORW = $WM_CAP_UNICODE_START + 2
  69. $WM_CAP_SET_CALLBACK_FRAME = $WM_CAP_START + 5
  70. $WM_CAP_SET_CALLBACK_STATUSA = $WM_CAP_START + 3
  71. $WM_CAP_SET_CALLBACK_STATUSW = $WM_CAP_UNICODE_START + 3
  72. $WM_CAP_SET_CALLBACK_VIDEOSTREAM = $WM_CAP_START + 6
  73. $WM_CAP_SET_CALLBACK_WAVESTREAM = $WM_CAP_START + 7
  74. $WM_CAP_SET_CALLBACK_YIELD = $WM_CAP_START + 4
  75. $WM_CAP_SET_MCI_DEVICEA = $WM_CAP_START + 66
  76. $WM_CAP_SET_MCI_DEVICEW = $WM_CAP_UNICODE_START + 66
  77. $WM_CAP_SET_OVERLAY = $WM_CAP_START + 51
  78. $WM_CAP_SET_PREVIEW = $WM_CAP_START + 50
  79. $WM_CAP_SET_PREVIEWRATE = $WM_CAP_START + 52
  80. $WM_CAP_SET_SCALE = $WM_CAP_START + 53
  81. $WM_CAP_SET_SCROLL = $WM_CAP_START + 55
  82. $WM_CAP_SET_SEQUENCE_SETUP = $WM_CAP_START + 64
  83. $WM_CAP_SET_USER_DATA = $WM_CAP_START + 9
  84. $WM_CAP_SET_VIDEOFORMAT = $WM_CAP_START + 45
  85. $WM_CAP_SINGLE_FRAME = $WM_CAP_START + 72
  86. $WM_CAP_SINGLE_FRAME_CLOSE = $WM_CAP_START + 71
  87. $WM_CAP_SINGLE_FRAME_OPEN = $WM_CAP_START + 70
  88. $WM_CAP_STOP = $WM_CAP_START + 68
  89. $cap = ""
  90. $avi = ""
  91. $user = ""
  92. $snapfile = @ScriptDir & "\snapshot.bmp"
  93. ;~ ##########################################################
  94. ;~ Function Name : _WebcamInit()
  95. ;~ Description : Starts the webcam image capturing session
  96. ;~ Author : L|M|TER
  97. ;~ ##########################################################
  98. Func _WebcamInit()
  99. $avi = DllOpen("avicap32.dll")
  100. $user = DllOpen("user32.dll")
  101. EndFunc
  102. ;~ ##########################################################
  103. ;~ Function Name : _Webcam($gui,$h,$w,$l,$t)
  104. ;~ Description : Creates a webcam preview window
  105. ;~ Parameter(s):
  106. ;~ $gui - The gui where the webcam window should be created
  107. ;~ $h - The height of the webcam window
  108. ;~ $w - The width of the webcam window
  109. ;~ $l - The left position of the webcam window
  110. ;~ $t - The top position of the webcam window
  111. ;~ NOTE : All parameters required !
  112. ;~ Author : L|M|TER
  113. ;~ ##########################################################
  114. Func _Webcam($gui,$w,$h,$l,$t)
  115. $cap = DllCall($avi, "int", "capCreateCaptureWindow", "str", "cap", "int", BitOR($WS_CHILD,$WS_VISIBLE), "int", $l, "int", $t, "int", $w, "int", $h, "hwnd", $gui, "int", 1)
  116. DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_DRIVER_CONNECT, "int", 0, "int", 0)
  117. DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_SCALE, "int", 1, "int", 0)
  118. DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_OVERLAY, "int", 1, "int", 0)
  119. DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_PREVIEW, "int", 1, "int", 0)
  120. DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_PREVIEWRATE, "int", 1, "int", 0)
  121. EndFunc
  122. ;~ ##########################################################
  123. ;~ Function Name : _WebcamStop()
  124. ;~ Description : Closes the webcam image capturing session
  125. ;~ Author : L|M|TER
  126. ;~ ##########################################################
  127. Func _WebcamStop()
  128. DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_END, "int", 0, "int", 0)
  129. DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_DRIVER_DISCONNECT, "int", 0, "int", 0)
  130. DllClose($user)
  131. DllClose($avi)
  132. EndFunc
  133. ;~ ##########################################################
  134. ;~ Function Name : _WebcamSnapShot($file)
  135. ;~ Description : Takes a snapshot
  136. ;~ Parameter(s):
  137. ;~ $file (Optional) - The path to the file where the snapshot will be saved (Default : @ScriptDir & "\snapshot.bmp")
  138. ;~ Author : L|M|TER
  139. ;~ ##########################################################
  140. Func _WebcamSnapShot($file = $snapfile)
  141. DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_GRAB_FRAME_NOSTOP, "int", 0, "int", 0)
  142. DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_FILE_SAVEDIBA, "int", 0, "str", $file)
  143. EndFunc

comments powered by Disqus