December 04, 2020, 11:08:13 AM

Author Topic: [bmx] ESCAPI 2.0 Webcam/Image Capture by BlitzSupport [ 1+ years ago ]  (Read 863 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : ESCAPI 2.0 Webcam/Image Capture
Author : BlitzSupport
Posted : 1+ years ago

Description : You need to place escapi.dll in the same folder as this source code. (You'll therefore have to save the code before running it.) This DLL is part of the escapi20.zip package available from <a href="http://sol.gfxile.net/code.html" target="_blank">http://sol.gfxile.net/code.html[/url]

This version grabs directly to a PixMap. If for some reason this causes any problems for you, try the (slower) pixel-by-pixel version posted <a href="../Community/postsf95c-3.html?topic=66505" target="_blank">here[/url].

By default, this example uses the first capture device found (number 0).

UPDATE: Tidier 'include/import' version here, which grabs to standard Blitz images: <a href="http://www.hi-toro.com/blitz/escapi_max.zip" target="_blank">escapi_max.zip[/url]. It also comes with a simple example for one web cam, and an example of using two web cams at the same time. Again, you will need the ESCAPI 2.0 package as described above.


Code :
Code: BlitzMax
  1. ' Thanks to Freak from the PureBasic forums for assistance!
  2.  
  3. Type SimpleCapParams
  4.         Field mTargetBuf:Byte Ptr ' Must be at least mWidth * mHeight * SizeOf(Int) of size!
  5.         Field mWidth
  6.         Field mHeight
  7. End Type
  8.  
  9. Global InitCOM () "C"
  10. Global CountCaptureDevices () "C"
  11. Global OpenCaptureDevice (device, scp:Byte Ptr) "C"
  12. Global CloseCaptureDevice (device) "C"
  13. Global GetCapture (device) "C"
  14. Global CaptureDone (device) "C"
  15. Global CaptureDeviceName (device, name:Byte Ptr, namelen) "C"
  16. Global ESCAPIDLLVersion () "C"
  17.  
  18. Function SetupESCAPI ()
  19.  
  20.         esc = LoadLibraryA ("escapi.dll")
  21.        
  22.         If esc
  23.        
  24.                 InitCOM                                 = GetProcAddress (esc, "initCOM")
  25.                 CountCaptureDevices             = GetProcAddress (esc, "countCaptureDevices")
  26.                 OpenCaptureDevice               = GetProcAddress (esc, "initCapture")
  27.                 CloseCaptureDevice              = GetProcAddress (esc, "deinitCapture")
  28.                 GetCapture                              = GetProcAddress (esc, "doCapture")
  29.                 CaptureDone                             = GetProcAddress (esc, "isCaptureDone")
  30.                 CaptureDeviceName               = GetProcAddress (esc, "getCaptureDeviceName")
  31.                 ESCAPIDLLVersion                = GetProcAddress (esc, "ESCAPIDLLVersion")
  32.  
  33.                 If InitCOM = Null Or CountCaptureDevices = Null Or OpenCaptureDevice = Null or..
  34.                         CloseCaptureDevice = Null Or GetCapture = Null Or CaptureDone = Null or..
  35.                                 CaptureDeviceName = Null Or ESCAPIDLLVersion = Null
  36.                                         DebugLog "Function missing!"
  37.                                         Return 0
  38.                 EndIf
  39.  
  40.                 InitCOM ()
  41.                
  42.                 If ESCAPIDLLVersion () < $200
  43.                         DebugLog "Old DLL (needs version 2.0+)"
  44.                         Return 0
  45.                 EndIf
  46.                
  47.         Else
  48.                 DebugLog "Failed to open DLL"
  49.                 Return 0
  50.         EndIf
  51.  
  52.         Return 1
  53.        
  54. End Function
  55.  
  56. Function CaptureDevice$ (device)
  57.         Local cam:Byte [1024]
  58.         CaptureDeviceName (device, cam, 1024)
  59.         Return String.FromCString (cam)
  60. End Function
  61.  
  62. If SetupESCAPI () = 0
  63.         Notify "Error! Make sure escapi.dll is in same folder and capture device plugged in!"
  64.         End
  65. EndIf
  66.  
  67. For num = 0 Until CountCaptureDevices ()
  68.         Print "Capture device [" + num + "] name: " + CaptureDevice (num)
  69. Next
  70.  
  71. device = 0
  72.  
  73. ' To list/select devices...
  74.  
  75.         'Repeat
  76.         '       device = Int (Input ("Enter capture device number: "))
  77.         'Until device > -1 And device < CountCaptureDevices ()
  78.  
  79. ' Preferred target width/height (ESCAPI scales capture data to this)...
  80.  
  81. width = 320
  82. height = 240
  83.  
  84. AppTitle = "Using " + CaptureDevice (device) + "..."
  85.  
  86. Graphics width, height', 32
  87.  
  88. ' Data structure...
  89.  
  90. Local scp:SimpleCapParams = New SimpleCapParams
  91.  
  92. ' A PixMap for captured data...
  93.  
  94. pix:TPixmap = CreatePixmap (width, height, PF_BGRA8888)
  95.  
  96. ' Stick pixmap memory pointer into data structure...
  97.  
  98. scp.mTargetBuf  = PixmapPixelPtr (pix)
  99. scp.mWidth              = width
  100. scp.mHeight             = height
  101.  
  102. ' Start capture process...
  103.  
  104. If OpenCaptureDevice (device, scp) = 0
  105.         Print "Failed to initialise capture device!"
  106.         End
  107. EndIf
  108.  
  109. Repeat
  110.  
  111.         Cls
  112.  
  113.         GetCapture (device)
  114.        
  115.         Repeat
  116.                 If KeyHit (KEY_ESCAPE) Then quit = True
  117.         Until CaptureDone (device)
  118.  
  119.         DrawPixmap pix, 0, 0
  120.  
  121.         Flip
  122.  
  123. Until quit = True
  124.  
  125. ' Stop capture process...
  126.        
  127. CloseCaptureDevice (device)
  128.  
  129. End


Comments :


ssdw(Posted 1+ years ago)

 Thank you very much!


Fielder(Posted 1+ years ago)

 no new ways to acquire the webcam, this method seems not working well with Driver-provided webcams and windows 8 and 10


xlsior(Posted 1+ years ago)

 There's a newer 3.0 version of Escapi dll as well, which is a complete rewrite based on media foundation APIs, includes new interfaces for adjusting camera properties (such as brightness), comes with both 32 and 64 bit builds, and source code is in github.<a href="http://sol.gfxile.net/escapi/" target="_blank">http://sol.gfxile.net/escapi/[/url]


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal