Feeling ambitious and having no success compiling OpenCV, I see that escapi has some facility for controlling a webcam's proc amp. I'm having trouble getting the OOP interface to the IAMVideoProcAmp interface in DirectShow. Any help is appreciated.
https://www.google.com/search?q=iamvide ... 8&oe=utf-8All code posted here works, but need help getting the IAMVideoProcAmp interface to work. I don't think I'm setting things up properly at lines 8, 14 and 125 of escapi.pbi, below.
Code:
;WORKS WITH ESCAPI
;UPDATED 8/28/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 = 640;DesktopWidth(0)
Global HEIGHT = 360;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
;procamp\Set(#CAPTURE_BRIGHTNESS, 128, #VideoProcAmp_Flags_Manual)
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)
Repeat: Until isCaptureDone(#DEVICE) <> #False
;PIXEL-BY-PIXEL READING AND WRITING
hm1 = *writebuffer + (HEIGHTM1 * pitch)
*bufoff = *buf
;Goto skip
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
skip:
SetGadgetState(0, ImageID(1))
now.f = ElapsedMilliseconds()
fps.f = now.f-then.f
If fps > 0:fps$ = StrF((1/fps)*1000,2) ;:EndIf
If (1/fps)*1000 < 10: fps$ = "0" + fps$: EndIf
EndIf
DrawText(100, 200, fps$+" fps",#White)
then.f = ElapsedMilliseconds()
;StopDrawing()
Until Quit = #True
StopDrawing()
deinitCapture(#DEVICE)
FreeImage(1)
FreeMemory(scp\mTargetBuf)
CloseWindow(1)
Else
Debug "Init capture failed."
EndIf
End
Here is the modified version of escapi.pbi.
Code:
;/* Extremely Simple Capture API */
Structure SimpleCapParams
*mTargetBuf ; Must be at least mWidth * mHeight * SizeOf(int) of size!
mWidth.l
mHeight.l
EndStructure
Structure procAmpSet
property.l
lvalue.l
Flags.l
EndStructure
Structure udtSelf
*VTable
text1.s
EndStructure
#VideoProcAmp_Flags_Auto = 1
#VideoProcAmp_Flags_Manual = 2
;C style Interface
; typedef struct IAMVideoProcAmpVtbl
;Structure IAMVideoProcAmpVtbl
Interface procAmp
; HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
; IAMVideoProcAmp * This,
; /* [in] */ REFIID riid,
; /* [iid_is][out] */
; __RPC__deref_out void **ppvObject);
;
;ULONG (STDMETHODCALLTYPE *AddRef)(IAMVideoProcAmp * This)
; ULONG ( STDMETHODCALLTYPE *Release )(
; IAMVideoProcAmp * This);
;
; HRESULT ( STDMETHODCALLTYPE *GetRange )(
; IAMVideoProcAmp * This,
; /* [in] */ long Property,
; /* [out] */
; __out long *pMin,
; /* [out] */
; __out long *pMax,
; /* [out] */
; __out long *pSteppingDelta,
; /* [out] */
; __out long *pDefault,
; /* [out] */
; __out long *pCapsFlags);
;
; HRESULT ( STDMETHODCALLTYPE *Set )(
; IAMVideoProcAmp * This,
Set(property.l,lvalue.l,Flags.l)
;property.l ;/* [in] */
; lValue.l /* [in] */ long
; /* [in] */ long Flags);
;
; HRESULT ( STDMETHODCALLTYPE *Get )(
; IAMVideoProcAmp * This,
; /* [in] */ long Property,
; /* [out] */
; __out long *lValue,
; /* [out] */
; __out long *Flags);
EndInterface
;*object.procAmp = #Null ;createObject
;*object\Set(0,0,0)
;/* 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()
;chris319
Enumeration CAPTURE_PROPETIES
#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
Procedure CreateObject()
Protected *v.procAmpSet
*v = AllocateMemory(SizeOf(procAmpSet))
; *v\VTable = ?Procedures
ProcedureReturn *v
EndProcedure
procAmp.IAMVideoProcAmp = CreateObject()
;see file strmif.h lines 9954,10110
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
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