Video capture issues

Just starting out? Need help? Post your questions and find answers here.
fcb
User
User
Posts: 42
Joined: Fri Aug 31, 2012 10:12 pm

Video capture issues

Post by fcb »

Hi,

I'm trying to display video from a low cost USB video capture device (from Amazon), whilst displaying the video I also want to capture stills for further processing.

I know the capture device works in the standard Win10 webcam app and OBS. I found various bits of sample code on this forum, however they only display solid black.I've also tried this on a laptop with a built in camera - same results.

Running w10. and PB 6.00

Code: Select all

cwFlags = #WS_CHILD | #WS_VISIBLE
wFlags = #PB_Window_ScreenCentered | #PB_Window_SystemMenu
If OpenWindow(0, 0, 0, 660, 500, "Webcam Example", wFlags)
  If OpenLibrary(0, "avicap32.dll")
    *capAddress = GetFunction(0, "capCreateCaptureWindowA")
    If *capAddress 
      hWnd = CallFunctionFast(*capAddress, 0, cwFlags, 10, 10, 640, 480, WindowID(0), 0)
      If hWnd
        If SendMessage_(hWnd, #WM_CAP_DRIVER_CONNECT, 0, 0)
          Delay(100)
          x=SendMessage_(hWnd, #WM_CAP_SET_SCALE, #True, 0)              ; was true
          Debug "#WM_CAP_SET_SCALE:"+x
          x=SendMessage_(hWnd, #WM_CAP_SET_PREVIEWRATE, 15, 0)          ; was 15ms
          Debug "#WM_CAP_SET_PREVIEWRATE:"+x 
          x=SendMessage_(hWnd, #WM_CAP_SET_PREVIEW, #True, 0)  
          Debug "#WM_CAP_SET_PREVIEW:"+x 
          While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend 
          error$ = "Webcam terminated."
        Else
          error$ = "Unable to connect to webcam."
        EndIf
      Else
        error$ = "Unable to create capture window."
      EndIf
    Else      
      error$ = "Unable to locate capture function."
    EndIf        
    SendMessage_(hWnd, #WM_CAP_STOP, 0, 0)
    SendMessage_(hWnd, #WM_CAP_DRIVER_DISCONNECT, 0, 0)
    DestroyWindow_(hWnd)
    CloseLibrary(0)    
  Else
    error$ = "Unable to open AVI library."
  EndIf
  MessageRequester("Webcam", error$)
Endif
Any thoughts?
fcb
User
User
Posts: 42
Joined: Fri Aug 31, 2012 10:12 pm

Re: Video capture issues

Post by fcb »

So I've abandoned VfW in favour of ESCAPI (V2.1)

I got it working for a couple of hours (escapi.dll in the same directory as my project code). Lovely. Then it stopped working. :shock:

Basically something is now stopping it finding escapi.dll, so I tried adding escapi.dll to Windows/System32 (using regsvr32 "C:\Windows\System32\escapi.dll") - and keep getting this error:

"
The module "C:\Windows\System32\escapi.dll" was loaded but the entry-point DllRegisterServer was not found.
Make sure that "C:\Windows\System32\escapi.dll" is a valid DLL or OCX file and then try again.
"
I've also tried registring the escapi.dll from V3

Running Windows 10.
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Video capture issues

Post by Caronte3D »

Is better if you post a code to work with (and a link to download that dll), so more users can try to help you :wink:
fcb
User
User
Posts: 42
Joined: Fri Aug 31, 2012 10:12 pm

Re: Video capture issues

Post by fcb »

Code here (thanks Caronte). This requires escapi.pb and escapi.dll (https://solhsa.com/escapi/index.html) I've been using 2.1

I put "escapi.pb" and "escapi.dll" in the same folder as the code below:

demo.pb

Code: Select all

XIncludeFile "escapi.pb"

device = 0

count = setupESCAPI()
Debug "init: " + Str(count)

If count = 0
  End
EndIf

name$ = Space(1000)
getCaptureDeviceName(device, @name$, 1000)
Debug "name: " + name$

scp.SimpleCapParams
scp\mWidth = 640  ; was 320
scp\mHeight = 480 ; was 240
scp\mTargetBuf = AllocateMemory (scp\mWidth * scp\mHeight * 4)

If initCapture(device, @scp)
  Debug "cap init successful" 
 
  ;image = CreateImage(#PB_Any, 320, 240)
  image = CreateImage(#PB_Any, 640, 480)
  
 
  OpenWindow(0, 0, 0, 640, 480, name$, #PB_Window_ScreenCentered|#PB_Window_SystemMenu) ; was 320x240
  CreateGadgetList(WindowID(0))
  ImageGadget(0, 0, 0, 640, 480, ImageID(image))
 
  Quit = 0
  Repeat
 
    doCapture(device)
    While isCaptureDone(device) = 0
      If WaitWindowEvent(1) = #PB_Event_CloseWindow
        Quit = 1
        Break
      EndIf       
    Wend
   
    If StartDrawing(ImageOutput(image))   
      For y = 0 To scp\mHeight - 1
        For x = 0 To scp\mWidth - 1
          pixel = PeekL(scp\mTargetBuf + (y*scp\mWidth + x) * 4)
          rgb   = RGB((pixel >> 16) & $FF, (pixel >> 8) & $FF, pixel & $FF)
          Plot(x, y, rgb)
        Next
      Next
     
      StopDrawing()
      SetGadgetState(0, ImageID(image))
    EndIf
     
 
  Until Quit

  deinitCapture(device)
Else
  Debug "init capture failed!"
EndIf

End
The code for escapi.pb is below, the only difference from the escapi.pb in the link is I've added line 54 to help with debug:

escapi.pb

Code: Select all

;/* Extremely Simple Capture API */

Structure SimpleCapParams
   *mTargetBuf ; Must be at least mWidth * mHeight * SizeOf(int) of size!
   mWidth.l
   mHeight.l
EndStructure

;/* Return the number of capture devices found */
PrototypeC countCaptureDevicesProc()

; /* initCapture tries To open the video capture device.
;  * Returns 0 on failure, 1 on success.
;  * Note: Capture parameter values must Not change While capture device
;  *       is in use (i.e. between initCapture And deinitCapture).
;  *       Do *Not* free the target buffer, Or change its pointer!
;  */
PrototypeC initCaptureProc(deviceno, *aParams.SimpleCapParams)

;/* deinitCapture closes the video capture device. */
PrototypeC deinitCaptureProc(deviceno)

;/* doCapture requests video frame To be captured. */
PrototypeC doCaptureProc(deviceno)

;/* isCaptureDone returns 1 when the requested frame has been captured.*/
PrototypeC isCaptureDoneProc(deviceno)


;/* Get the user-friendly name of a capture device. */
PrototypeC getCaptureDeviceNameProc(deviceno, *namebuffer, bufferlength)


;/* Returns the ESCAPI DLL version. 0x200 For 2.0 */
PrototypeC ESCAPIDLLVersionProc()

; marked as "internal" in the example
PrototypeC initCOMProc()

Global countCaptureDevices.countCaptureDevicesProc
Global initCapture.initCaptureProc
Global deinitCapture.deinitCaptureProc
Global doCapture.doCaptureProc
Global isCaptureDone.isCaptureDoneProc
Global getCaptureDeviceName.getCaptureDeviceNameProc
Global ESCAPIDLLVersion.ESCAPIDLLVersionProc


Procedure setupESCAPI()
   
  ; load library
  capdll = OpenLibrary(#PB_Any, "escapi.dll")
  If capdll = 0
    Debug "escapi.dll Not found"  ; Ben added 19/3/2023
    ProcedureReturn 0
  EndIf
 
   ;/* Fetch function entry points */
   countCaptureDevices  = GetFunction(capdll, "countCaptureDevices")
   initCapture          = GetFunction(capdll, "initCapture")
   deinitCapture        = GetFunction(capdll, "deinitCapture")
   doCapture            = GetFunction(capdll, "doCapture")
   isCaptureDone        = GetFunction(capdll, "isCaptureDone")
   initCOM.initCOMProc  = GetFunction(capdll, "initCOM")
   getCaptureDeviceName = GetFunction(capdll, "getCaptureDeviceName")
   ESCAPIDLLVersion     = GetFunction(capdll, "ESCAPIDLLVersion")
   
   If countCaptureDevices = 0 Or initCapture = 0 Or deinitCapture = 0 Or doCapture = 0 Or isCaptureDone = 0 Or initCOM = 0 Or getCaptureDeviceName = 0 Or ESCAPIDLLVersion = 0
     ProcedureReturn 0
   EndIf
   
   ;/* Verify DLL version */
   If ESCAPIDLLVersion() < $200
     ProcedureReturn 0
   EndIf
 
   ;/* Initialize COM.. */
   initCOM(); 
 
  ; returns number of devices found
  ProcedureReturn countCaptureDevices()
EndProcedure 
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Video capture issues

Post by Caronte3D »

Works here, I don't know how to reproduce the crash without leave it open for hours :?
Try to use the 3.0 dll instead of 2.1 I tested it and works with the same code.

From the web of the dll:
I've been involved in several projects that use ESCAPI, and webcam drivers do vary a lot. In some cases you couldn't run several cameras at once, even if they're from the same manufacturer; other times drivers would hang after running capture for about 8 hours straight.
Last edited by Caronte3D on Mon Mar 20, 2023 9:02 pm, edited 1 time in total.
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Video capture issues

Post by Caronte3D »

BTW: If you use this line after the getCaptureDeviceName one, you get correct camera name:

Code: Select all

name$ = PeekS(@name$, 1000, #PB_Ascii)
Also, you need a better way to fill the image than Plot() if speed matters at high resolutions.
fcb
User
User
Posts: 42
Joined: Fri Aug 31, 2012 10:12 pm

Re: Video capture issues

Post by fcb »

Thanks Caronte3D,

The camera output is being used for homebrew machine vision (not OpenCV!) and in my prototype runs at either 2 or 10Hz (throttled on purpose).

The problem is registering the damn escapi.dll (machine is Windows 10, Defender as AntiVirus). It worked fine initially for a few hours, then I closed it (badly..?) and it wouldn't recognise the .dll. I even tried a different PC, just couldn't get it to work. Tried fresh downloads of the .dll, etc...

As I don't understand how regsvr32 really works I'm flying blind. It might even be the antivirus, however it doesn't flag anything up.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Video capture issues

Post by JHPJHP »

Hi fcb,

I haven't used ESCAPI before, but after reading the documentation, nowhere does it say that the DLL needs to be registered.

To confirm this, I downloaded escapi21.zip and escapi3.zip from https://solhsa.com/escapi/index.html.
Copied the PureBasic example folder from escapi21 into escapi3, made a couple insignificant changes...

NOTE: This is just additional confirmation to what Caronte3D already posted, that the DLL and example are working as expected.
Last edited by JHPJHP on Wed Mar 22, 2023 3:40 pm, edited 1 time in total.
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Video capture issues

Post by Caronte3D »

Yes, as I said, there is a warning on the website, so some controllers may hang:
other times drivers would hang after running capture for about 8 hours straight.
fcb
User
User
Posts: 42
Joined: Fri Aug 31, 2012 10:12 pm

Re: Video capture issues

Post by fcb »

Thanks JHPJHP & Caronte3D for your help.

Can confirm the demo.pb now works on my machine!! - there appears to be some small changes between 2.1 and 3.0 demo code.

Going to make the changes to my code later to reflect this and try it again.
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Video capture issues

Post by Caronte3D »

A simple optimization to get rid of some operation in the inner loop:

Code: Select all

EnableExplicit

CompilerIf #PB_Compiler_Debugger
  MessageRequester("Warning","With Debugger enabled the speed will be slow.")
CompilerEndIf

XIncludeFile "escapi.pbi"

Procedure FilterCallback(x, y, SourceColor, TargetColor)
  ProcedureReturn RGBA(Blue(SourceColor), Green(SourceColor), Red(SourceColor), Alpha(TargetColor))
EndProcedure

Define device = 0

Define count = setupESCAPI()
Debug "init: " + Str(count)

If count = 0
  End
EndIf

Define name$ = Space(1000)
getCaptureDeviceName(device, @name$, 1000)

name$ = PeekS(@name$, 1000, #PB_Ascii)

Debug "name: " + Trim(name$)
Define ancho = 1920
Define alto  = 1080

Define scp.SimpleCapParams
scp\mWidth     = ancho  ; was 320
scp\mHeight    = alto ; was 240
scp\mTargetBuf = AllocateMemory (scp\mWidth * scp\mHeight * 4)

If initCapture(device, @scp)
  Debug "cap init successful"
  
  ;image = CreateImage(#PB_Any, 320, 240)
  Define image = CreateImage(#PB_Any, ancho, alto, 24)
  
  
  OpenWindow(0, 0, 0, ancho, alto, name$, #PB_Window_ScreenCentered | #PB_Window_SystemMenu) ; was 320x240
  ImageGadget(0, 0, 0, ancho, alto, ImageID(image))
  
  Define Quit = 0, y, x, pixel, rgb
  Repeat
    
    doCapture(device)
    While isCaptureDone(device) = 0
      If WaitWindowEvent(1) = #PB_Event_CloseWindow
        Quit = 1
        Break
      EndIf
    Wend
    
    If StartDrawing(ImageOutput(image))
      
      DrawingMode(#PB_2DDrawing_CustomFilter)
      CustomFilterCallback(@FilterCallback())
      
      For y = 0 To scp\mHeight - 1
        Define part = y * scp\mWidth
        For x = 0 To scp\mWidth - 1
          Plot(x, y, PeekL(scp\mTargetBuf + (part + x) << 2))
        Next
      Next
      
      StopDrawing()
      SetGadgetState(0, ImageID(image))
    EndIf
    
    
  Until Quit
  
  deinitCapture(device)
Else
  Debug "init capture failed!"
EndIf

End
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Video capture issues

Post by Caronte3D »

Maybe you could edit the title of this thread to: "Simple way to use a WebCam" or something similar :D
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: Video capture issues

Post by chris319 »

I wrote a program using PB and ESCAPI 3.0 which processes the lift, gamma and gain of the video and renders it to the screen. It also has a scope.

Is there any way to do anything with the output of my program besides render it to the screen, like record it (with audio)?

NOTE: This program requires 32-bit PB and ESCAPI 3.0

It is intended to be used with a test chart.

Feel free to modify as needed.

Code: Select all

;WORKS WITH ESCAPI ;REQUIRES 32-BIT PUREBASIC
;LAST MODIFIED 3/28/2023

std$ = "SDR"
;"HLG" OR "SDR" OR "HDR"

result = ExamineDesktops()
Global V_RES = DesktopHeight(0):Global H_RES = DesktopWidth(0)

Enumeration
#GAINGAD = 1;GAIN GADGET
#GAMMA;GAMMA GADGET
#PEDESTAL;PEDESTAL GADGET
#GAINTEXT
#PEDTEXT
#GAMMATEXT
EndEnumeration

#UNITY = 0.5
#KR = 0.2126:#KG = 0.7152:#KB = 0.0722 ;REC.709

;SDR SETTINGS                                                                                                                                                                                                                                                                                                                                                                                     
;Global gamma.d = 2.4: factor.d = 255/Pow(255,gamma) ;1.85
;Global pedestal.d = 16;8
;Global gain.d = 0.80;0.98

;CAM ALIGN CHART
gamma.d = 2.10: factor.d = 255/Pow(255,gamma)
pedestal.d = 16
gain.d = 0.94

;gamma.d = 1: factor.d = 255/Pow(255,gamma)
;pedestal.d = 1
;gain.d = 1

IncludeFile "escapi.pbi"

#HEIGHT = 360
#WIDTH = #height * 16/9
#WIDTHM1 = #WIDTH - 1
#HEIGHTM1 = #HEIGHT - 1

Procedure Graticule(std$)
DrawingMode(#PB_2DDrawing_Default)
;BLACK
lum = 16: LineXY(68,(255 - lum) + 52, #WIDTH-45,(255 - lum) + 52,$00ffff);BLACK
LineXY(36,(255 - lum) + 52, #WIDTH-45,(255 - lum) + 52,$00ffff)

lum = 16
DrawText(600,(255 - lum) + 44, "0", $ffffff)
DrawText(6,(255 - lum) + 44, " 0%", $ffffff)

;If std$ = "HLG" Or std$ = "HDR"
;DrawText(2,(255 - lum) + 44,"64", $ffffff)
;ElseIf std$ = "SDR":;DrawText(2,(255 - lum) + 44,"16", $ffffff)
;EndIf

;GAMMA
If std$ = "HLG" Or std$ = "HDR"
lum = 397 / 4 ;HLG
LineXY(36,(255 - lum) + 52, #WIDTH-45,(255 - lum) + 52,$00ffff)
DrawText(600,(255 - lum) + 42,"38", $ffffff)
;DrawText(2,(255 - lum) + 44,"397", $ffffff)
DrawText(6,(255 - lum) + 42, "18%", $ffffff)

ElseIf std$ = "SDR"
  lum = 105
  LineXY(36,(255 - lum) + 52, #WIDTH-45,(255 - lum) + 52,$00ffff)
  DrawText(600,(255 - lum) + 44, "40", $ffffff)
  DrawText(6,(255 - lum) + 44, "18%", $ffffff)
  
EndIf

;PEAK WHITE

;HLG 90% REFLECTANCE
If std$ = "HLG" Or std$ = "HDR"
lum = 235
LineXY(36,(255 - lum) + 52, #WIDTH-45,(255 - lum) + 52,$00ffff)
DrawText(600,(255 - lum) + 42, "100", $ffffff)
DrawText(6,(255 - lum) + 42,"90%", $ffffff)

ElseIf std$ = "SDR"
lum = 235 ;90% REFLECTANCE
LineXY(36,(255 - lum) + 52, #WIDTH-45,(255 - lum) + 52,$00ffff)
DrawText(600,(255 - lum) + 42, "100", $ffffff)
DrawText(6,(255 - lum) + 42, "90%", $ffffff)

EndIf

;DrawText(2, 13, "DIG.", $ffffff)
DrawText(6, 13, "REFL.", $ffffff)
DrawText(600, 13, "IRE", $ffffff)

EndProcedure

LoadFont(1,"arial",10,#PB_Font_Bold);FOR SCOPE GRATICULE
LoadFont(2,"arial",24);FOR GADGETS

device = 0
count = setupESCAPI()

    If count = 0
      MessageRequester("Error", "Unable to initialize ESCAPI.  Use 32-bit version")
      End
    EndIf

    name$ = Space(255)
    getCaptureDeviceName(device, @name$, 255)

    bufSize = #WIDTH * #HEIGHT * 4
    scp.SimpleCapParams
    scp\mWidth = #WIDTH
    scp\mHeight = #HEIGHT
    scp\mTargetBuf = AllocateMemory(bufSize)
    ;*buf = scp\mTargetBuf

If initCapture(device, @scp) = #False
 MessageRequester("Error", "Unable to initialize webcam.")
 End
EndIf
     
image = CreateImage(1, #WIDTH, #HEIGHT * 2, 24) ;CAMERA

;MAIN WINDOW
OpenWindow(1,0, 0, #WIDTH*2, #HEIGHT * 2 - 40, name$, #PB_Window_SystemMenu)

SpinGadget(#GAINGAD, #WIDTH * 1.5, 50,200,48,0,100)
SpinGadget(#GAMMA,#WIDTH * 1.5, 250,200,48,0,100)
SpinGadget(#PEDESTAL,#WIDTH * 1.5, 150,200,48,0,100)
SetGadgetFont(#GAINGAD,FontID(2))
SetGadgetFont(#PEDESTAL,FontID(2))
SetGadgetFont(#GAMMA,FontID(2))

SetGadgetText(#GAINGAD,StrD(gain,2))
SetGadgetText(#GAMMA,StrD(gamma,2))
SetGadgetText(#PEDESTAL,StrD(pedestal,2))

TextGadget(#GAINTEXT,#WIDTH * 1.1,50,200,48,"GAIN")
TextGadget(#PEDTEXT,#WIDTH * 1.1,250,200,48,"GAMMA")
TextGadget(#GAMMATEXT,#WIDTH * 1.1,150,200,48,"PEDESTAL")

TextGadget(11,#WIDTH * 1.1,350,600,48,"WHITE: 100 IRE")
TextGadget(12,#WIDTH * 1.1,400,600,48,"18% GRAY: 40 IRE")
TextGadget(13,#WIDTH * 1.1,450,600,48,"BLACK: 0 IRE")

SetGadgetFont(#GAINTEXT,FontID(2))
SetGadgetFont(#PEDTEXT,FontID(2))
SetGadgetFont(#GAMMATEXT,FontID(2))
SetGadgetFont(11,FontID(2))
SetGadgetFont(12,FontID(2))
SetGadgetFont(13,FontID(2))

setCaptureProperty(DEVICE,#CAPTURE_ZOOM,0,#VideoProcAmp_Flags_Manual)
setCaptureProperty(DEVICE,#CAPTURE_BRIGHTNESS,0.5,#VideoProcAmp_Flags_Manual); INITIALIZE TO UNITY

Quit = #False

Repeat
doCapture(device)
Delay(50) ;Delay(200)
event = WindowEvent()

If event = #PB_Event_CloseWindow
       Quit = #True
       Break
ElseIf event = #PB_Event_Gadget

If EventGadget() = #GAINGAD
If EventType() = #PB_EventType_Up:gain + 0.01
ElseIf EventType() = #PB_EventType_Down:gain - 0.01
EndIf
SetGadgetText(#GAINGAD,StrD(gain,2))

ElseIf EventGadget() = #GAMMA
If EventType() = #PB_EventType_Up:gamma - 0.05
ElseIf EventType() = #PB_EventType_Down:gamma + 0.05
EndIf
factor.d = 255/Pow(255,gamma)
SetGadgetText(#GAMMA,StrD(gamma,2))

ElseIf EventGadget() = #PEDESTAL
If EventType() = #PB_EventType_Up:pedestal + 1
ElseIf EventType() = #PB_EventType_Down:pedestal - 1
EndIf
SetGadgetText(#PEDESTAL,StrD(pedestal,2))

EndIf
EndIf

Repeat:Until isCaptureDone(device) <> #False

StartDrawing(ImageOutput(1))
DrawingFont(FontID(1))
*writeBuffer = DrawingBuffer()
pitch = DrawingBufferPitch()

Box(0,0,#WIDTH, #HEIGHT,0) ;BLANK SCOPE

;PIXEL-BY-PIXEL READING AND WRITING
factor.d = 255/Pow(255,gamma)

hm1 = *writebuffer + (#HEIGHTM1 * pitch)

*bufr = scp\mTargetBuf

For y = 0 To #HEIGHTM1: For x = 0 To #WIDTHM1
r = (PeekA(*bufr+2))
g = (PeekA(*bufr+1))
b = (PeekA(*bufr))

rf.d = r * gain
gf.d = g * gain
bf.d = b * gain

r=(Pow(rf,gamma) * factor) + PEDESTAL
If r > 255:r=255:EndIf;clip

g=(Pow(gf,gamma) * factor) + PEDESTAL
If g > 255:g=255:EndIf;clip

b=(Pow(bf,gamma) * factor) + PEDESTAL
If b > 255:b=255:EndIf;clip

If r < 0:r = 0:EndIf;clip
If g < 0:g = 0:EndIf;clip
If b < 0:b = 0:EndIf;clip

PokeA(hm1 + x*3,b)
PokeA(hm1 + x*3+1,g)
PokeA(hm1 + x*3+2,r)

;DRAW SCOPE
lum.f = (r*#KR) + (g*#KG) + (b*#KB)
;lum = 170;TEST

If (255 - lum) + 52 >= 0 ;And (255 - lum) + 52 <= 255
Plot(x, (255 - lum) + 52, $00cc00)
EndIf

*bufr + 4
Next
hm1 - pitch
Next

Graticule(std$)

StopDrawing()

StartDrawing(WindowOutput(1))
DrawImage(ImageID(1),0,0);DRAW TO SCREEN
StopDrawing()

Until quit <> #False

StopDrawing()
FreeImage(1)
deinitCapture(device)
FreeMemory(scp\mTargetBuf)
CloseWindow(1)

End
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Video capture issues

Post by Caronte3D »

Line 154: setCaptureProperty() is not a function, array, list, map or macro.
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: Video capture issues

Post by chris319 »

Caronte3D wrote: Tue Mar 28, 2023 3:02 pm Line 154: setCaptureProperty() is not a function, array, list, map or macro.
It works perfectly for me.

Just in case, here is my escapi.pbi

Code: Select all

;/* Extremely Simple Capture API */

Structure SimpleCapParams
   *mTargetBuf ; Must be at least mWidth * mHeight * SizeOf(int) of size!
   mWidth.l
   mHeight.l
EndStructure

;/* Return the number of capture devices found */
PrototypeC countCaptureDevicesProc()

; /* initCapture tries To open the video capture device.
;  * Returns 0 on failure, 1 on success.
;  * Note: Capture parameter values must Not change While capture device
;  *       is in use (i.e. between initCapture And deinitCapture).
;  *       Do *Not* free the target buffer, Or change its pointer!
;  */
PrototypeC initCaptureProc(deviceno, *aParams.SimpleCapParams)

;/* deinitCapture closes the video capture device. */
PrototypeC deinitCaptureProc(deviceno)

;/* doCapture requests video frame To be captured. */
PrototypeC doCaptureProc(deviceno)

;/* isCaptureDone returns 1 when the requested frame has been captured.*/
PrototypeC isCaptureDoneProc(deviceno)

;/* Get the user-friendly name of a capture device. */
PrototypeC getCaptureDeviceNameProc(deviceno, *namebuffer, bufferlength)

#VideoProcAmp_Flags_Auto = #True
#VideoProcAmp_Flags_Manual = #False

Enumeration CAPTURE_PROPERTIES
   #CAPTURE_BRIGHTNESS = 0
   #CAPTURE_CONTRAST
   #CAPTURE_HUE
   #CAPTURE_SATURATION
   #CAPTURE_SHARPNESS
   #CAPTURE_GAMMA
   #CAPTURE_COLORENABLE
   #CAPTURE_WHITEBALANCE
   #CAPTURE_BACKLIGHTCOMPENSATION
   #CAPTURE_GAIN
   #CAPTURE_PAN
   #CAPTURE_TILT
   #CAPTURE_ROLL
   #CAPTURE_ZOOM
   #CAPTURE_EXPOSURE
   #CAPTURE_IRIS
   #CAPTURE_FOCUS
   #CAPTURE_PROP_MAX
 EndEnumeration
 
;/* Gets value (0..1) of a camera property (see CAPTURE_PROPERTIES, above) */
PrototypeC.f getCapturePropertyValueProc(deviceno, prop)

;/* Gets whether the property is set To automatic (see CAPTURE_PROPERTIES, above) */
PrototypeC getCapturePropertyAutoProc(deviceno, prop);

;/* Set camera property To a value (0..1) And whether it should be set To auto. */
PrototypeC setCapturePropertyProc(deviceno, prop, value.f, autoval);

;gets the range and Default value of a specified video property
;pMin.l = 0: pMax.l = 0
;PrototypeC getRange(deviceno,prop,pMin,pMax);

;/* Returns the ESCAPI DLL version. 0x200 For 2.0 */
PrototypeC ESCAPIDLLVersionProc()

; marked as "internal" in the example
PrototypeC initCOMProc()

;/* initCaptureWithOptions allows additional options To be given. Otherwise it's identical with initCapture
PrototypeC initCaptureWithOptionsProc(deviceno, *aParams.SimpleCapParams, aOptions)


Global countCaptureDevices.countCaptureDevicesProc
Global initCapture.initCaptureProc
Global deinitCapture.deinitCaptureProc
Global doCapture.doCaptureProc
Global isCaptureDone.isCaptureDoneProc
Global initCOM.initCOMProc
Global getCaptureDeviceName.getCaptureDeviceNameProc
Global getCapturePropertyValue.getCapturePropertyValueProc
Global getCapturePropertyAuto.getCapturePropertyAutoProc
Global setCaptureProperty.setCapturePropertyProc 
Global ESCAPIDLLVersion.ESCAPIDLLVersionProc
Global initCaptureWithOptions.initCaptureWithOptionsProc

Macro MyGetFunction(var, dll, function)
  var = GetFunction(dll, function)
  If var = 0
    Debug "Unsupported function : " + function
    error = #True
  EndIf
EndMacro

Procedure setupESCAPI()
   
  ; load library
  capdll = OpenLibrary(#PB_Any, "escapi.dll")
  If capdll = 0
    ProcedureReturn 0
  EndIf
 
  Define init
 
   ;/* Fetch function entry points */
  Define error = #False
  MyGetFunction(countCaptureDevices    , capdll, "countCaptureDevices")
  MyGetFunction(initCapture            , capdll, "initCapture")
  MyGetFunction(deinitCapture          , capdll, "deinitCapture")
  MyGetFunction(doCapture              , capdll, "doCapture")
  MyGetFunction(isCaptureDone          , capdll, "isCaptureDone")
  MyGetFunction(initCOM                , capdll, "initCOM")
  MyGetFunction(getCaptureDeviceName   , capdll, "getCaptureDeviceName")
  MyGetFunction(ESCAPIDLLVersion       , capdll, "ESCAPIDLLVersion")
  ;MyGetFunction(initCaptureWithOptions , capdll, "initCaptureWithOptions")
  MyGetFunction(getCapturePropertyValue, capdll, "getCapturePropertyValue")
  MyGetFunction(getCapturePropertyAuto , capdll, "getCapturePropertyAuto")
  MyGetFunction(setCaptureProperty     , capdll, "setCaptureProperty")
 
  If error
    Debug "Error while getting some dll functions."
  EndIf
   
   ;/* Verify DLL version */
   If ESCAPIDLLVersion() < $200
     ProcedureReturn 0
   EndIf
 
   ;/* Initialize COM.. */
   initCOM();
 
  ; returns number of devices found
  ProcedureReturn countCaptureDevices()
EndProcedure
Post Reply