Re: Another Webcam Demo Program
Posted: Tue Sep 05, 2017 2:30 pm
djes, what version of the 2.4 library did you compiled? 2.4.13.3?
http://www.purebasic.com
https://www.purebasic.fr/english/
Yes, the latest 2.4AAT wrote:djes, what version of the 2.4 library did you compiled? 2.4.13.3?
That's why I've given up on OpenCV.djes wrote:opencv 3.3 is not compatible with JHPJHP's great pb implementation, and compiled 2.4 is not recognised by his pbi . It seems that I have the _ name mangling and other problems that I don't know now how to resolve.
Does this do moving video or just still images? Would you be willing to compile it with the reordered mediaSubtypes?AAT wrote:I will edit cap_dshow.cpp tomorrow and load all dll-s if this is necessary for someone.
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;
I didn't said that the prototypes were bad, I said that the DLL and LIB that I get from compilation had _ (underscore) name mangling problem and that *I* didn't know how to resolve that by now (I haven't time to do it). As I just installed VC for this special purpose, having only compiled the native opencv package (and not all the recommended stuff), no doubt it lacks some configuration.AAT wrote:chris319, you can download Opencv2.4.13.3 VC10 Dll-s with reordered mediaSubtypes (MEDIASUBTYPE_MJPG - first): http://rgho.st/84FfzcJrp (30 days!)
I don't think that there are any troubles with "...name mangling and other problems...": opencv 2.4 PB prototypes basically the same from 2013-2014, from JHPJHP project beginning.
Me too. I've never used Visual Studio before.djes wrote:... As I just installed VC for this special purpose, having only compiled the native opencv package...
Windows 10, OpenCV 2.4.13.3, CMake 2.8.12.1, MS Visual Studio 2010 Express (I've tried at first with 2017 community). I've tried a lot of things, still has these "_" in the .lib files (and polink error). Maybe I have something installed on my PC changing the default compiling options (I've removed MinGW). Or maybe I don't do what is needed. Do you follow some specific rules to compile ?AAT wrote:Me too. I've never used Visual Studio before.djes wrote:... As I just installed VC for this special purpose, having only compiled the native opencv package...
What version of Windows, Visual Studio and CMake did you use?.
Code: Select all
;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
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 IAMVideoProcAmpVtbl
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
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
;/* 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.IAMVideoProcAmpVtbl
*v = AllocateMemory(SizeOf(IAMVideoProcAmpVtbl))
;*object.procAmp = #Null ;createObject
;*object\Set(0,0,0)
;*v\VTable = ?Set
;*v\IAMVideoProcAmpVtbl = ?Set
ProcedureReturn *v
EndProcedure
*object.IAMVideoProcAmpVtbl = createObject()
;*object\IAMVideoProcAmpVtbl = ?Set
;*v\IAMVideoProcAmpVtbl = ?Set
;*object\Set(0,0,0)
;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