I finally got 30 fps out of my webcam! Here is what it took:
New webcam (Logitech BRIO -- has a USB 3.0 output)
For 30 fps you MUST use a USB 3.0 connection, so I also had to get a USB 3.0 interface card and cable.
This is using escapi, not OpenCV.
That's it.
Thank you again for your help, AAT.
Here is the updated program. The fps counter is more stable.
Code:
;WORKS WITH ESCAPI
;UPDATED 9/7/2017
;PRESS CTL-Q TO QUIT
;INCORPORATES PROC AMP
ExamineDesktops()
gamma.f = 1.34 ;WEBCAM OUTPUT IS ALREADY GAMMA CORRECTED
#PEDESTAL = 16
gain.f = (235-16)/235
gain * 0.97
factor.f = 255/Pow(255,gamma)
;SET WEBCAM TO DEFAULTS AND SHARPNESS TO 192
;MAKE LUTS
Dim gammaTable.a(256)
For cnt = 0 To 255
gammaTable.a(cnt)=(Pow(cnt,gamma) * factor * gain) + #PEDESTAL
If gammaTable(cnt) > 254: gammaTable(cnt) = 254
EndIf
Next
Dim x3table.l(1921)
For cnt = 0 To 1920
x3table(cnt) = cnt * 3
Next
LoadFont(1,"Arial",24)
IncludeFile "escapi.pbi"
Global WIDTH = DesktopWidth(0)
Global HEIGHT = DesktopHeight(0)
Global WIDTHM1 = WIDTH - 1
Global HEIGHTM1 = HEIGHT - 1
Global pixCount = (WIDTH * HEIGHT) - 2
Global Dim pixcolor.l(WIDTH, HEIGHT): Global Dim unsmoothedY.d(WIDTH, HEIGHT)
Global Dim Cr.d(WIDTH, HEIGHT): Global Dim Y.d(WIDTH, HEIGHT): Global Dim Cb.d(WIDTH, HEIGHT)
Global imHeight, imWidth, xCoord, yCoord,Rd,Gd,Bd
#DEVICE = 0
If setupESCAPI() = #Null
MessageRequester("Error", "Unable to initialize ESCAPI.")
End
EndIf
bufSize = WIDTH * HEIGHT * 4
scp.SimpleCapParams
scp\mWidth = WIDTH
scp\mHeight = HEIGHT
scp\mTargetBuf = AllocateMemory(bufSize)
*buf = scp\mTargetBuf
If initCapture(#DEVICE, @scp)
image = CreateImage(1, WIDTH, HEIGHT, 24)
OpenWindow(1, 0, 0, WIDTH, HEIGHT,"",#PB_Window_BorderLess)
AddKeyboardShortcut(1, #PB_Shortcut_Control|#PB_Shortcut_Q, 113);CTL Q TO QUIT
ImageGadget(0, 0, 0, WIDTH, HEIGHT, ImageID(1))
Quit = #False
StartDrawing(ImageOutput(1))
*writeBuffer = DrawingBuffer()
pitch = DrawingBufferPitch()
StopDrawing()
StartDrawing(WindowOutput(1))
;StartDrawing(ImageOutput(1))
DrawingFont(FontID(1))
Repeat
If WindowEvent() = #PB_Event_Menu And EventMenu() = 113
Quit = #True
EndIf
doCapture(#DEVICE)
;PIXEL-BY-PIXEL READING AND WRITING
hm1 = *writebuffer + (HEIGHTM1 * pitch)
*bufoff = *buf
For y = 0 To HEIGHTM1
For x = 0 To WIDTHM1
x3 = hm1 + x3table(x)
p1.l = PeekL(*bufoff)
PokeA(x3,gammaTable(p1 & 255))
PokeA(x3+1,gammaTable(p1 >> 8 & 255))
PokeA(x3+2,gammaTable(p1 >> 16))
*bufoff + 4
Next
hm1 - pitch
Next
now.f = ElapsedMilliseconds()
fps.f = now.f - then.f
SetGadgetState(0, ImageID(1))
frameCounter + 1
If frameCounter > 100: avgFPS = 30: frameCounter = 1: EndIf
avgFPS + fps
fps = (avgFPS / frameCounter)
If fps > 0:fps$ = Str((1/fps)*1000)
If (1/fps)*1000 < 10: fps$ = "0" + fps$: EndIf
EndIf
DrawText(100, 200, fps$+" fps",#White)
then.f = ElapsedMilliseconds()
Repeat: Until isCaptureDone(#DEVICE) <> #False
Until Quit = #True
StopDrawing()
deinitCapture(#DEVICE)
FreeImage(1)
FreeMemory(scp\mTargetBuf)
CloseWindow(1)
Else
Debug "Init capture failed."
EndIf
End