Re: Another Webcam Demo Program
Posted: Fri Sep 01, 2017 1:59 am
There ara much tutorials. Forexample http://docs.opencv.org/2.4/doc/tutorial ... stall.html
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
//The video types we support
//in order of preference
mediaSubtypes[0] = MEDIASUBTYPE_MJPG;
mediaSubtypes[1] = MEDIASUBTYPE_RGB24;
mediaSubtypes[2] = MEDIASUBTYPE_RGB32;
mediaSubtypes[3] = MEDIASUBTYPE_RGB555;
mediaSubtypes[4] = MEDIASUBTYPE_RGB565;
mediaSubtypes[5] = MEDIASUBTYPE_YUY2;
mediaSubtypes[6] = MEDIASUBTYPE_YVYU;
mediaSubtypes[7] = MEDIASUBTYPE_YUYV;
mediaSubtypes[8] = MEDIASUBTYPE_IYUV;
mediaSubtypes[9] = MEDIASUBTYPE_UYVY;
mediaSubtypes[10] = MEDIASUBTYPE_YV12;
mediaSubtypes[11] = MEDIASUBTYPE_YVU9;
mediaSubtypes[12] = MEDIASUBTYPE_Y411;
mediaSubtypes[13] = MEDIASUBTYPE_Y41P;
mediaSubtypes[14] = MEDIASUBTYPE_Y211;
mediaSubtypes[15] = MEDIASUBTYPE_AYUV;
//non standard
mediaSubtypes[16] = MEDIASUBTYPE_Y800;
mediaSubtypes[17] = MEDIASUBTYPE_Y8;
mediaSubtypes[18] = MEDIASUBTYPE_GREY;
mediaSubtypes[19] = MEDIASUBTYPE_I420;
Escapi, OpenCV or the chromium code?I've compiled it and got the unused initCaptureWithOptions() function to receive raw data. But it's not faster with my camera.
escapi requests a format it can easily convert to the target format, and if it doesn't get one, the camera just fails. It's entirely possible that the camera driver does something horrible just to satisfy the request, and some other (still acceptable) format would work faster. However, detecting such would be non-trivial, and might easily break.
Escapi.chris319 wrote:Escapi, OpenCV or the chromium code?I've compiled it and got the unused initCaptureWithOptions() function to receive raw data. But it's not faster with my camera.
Jari says:escapi requests a format it can easily convert to the target format, and if it doesn't get one, the camera just fails. It's entirely possible that the camera driver does something horrible just to satisfy the request, and some other (still acceptable) format would work faster. However, detecting such would be non-trivial, and might easily break.
Not certainly in that way: many errors appear when compiling the latest versions of OpenCV. There is no problem with CMake.chris319 wrote:... You seem to be having better luck with GCC.
Code: Select all
;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
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
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