Escapi64 capture vidéo photo [Résolut]
Publié : ven. 24/mars/2023 23:23
Bonsoirs à tous
Comme vous l'aurez compris, je persiste toujours à vouloir créer une version Pb une petite appli pour faire de photos HD
via une petite préview vidéo de la webcam
Pour ce faire, j'ai tout simplement adapté un code en Pb que j'avais trouvé sur le réseau, malheureusement, je n'obtient pas le résultat escompté
Je vous met en lien le fichier (Library) nécessaire pour le fonctionnement du code en question (côte à côte avec le fichier source Pb)
version 64 https://github.com/pbcodex/escapi/blob/ ... pi_x64.dll
version 32 https://github.com/pbcodex/escapi/blob/ ... pi_x32.dll
Voici le code à hospitaliser:
Le but étant d'avoir un preview vidéo 760*440
puis quand je presse le bouton "OK" une capture photo 3264*2448 s'opère aussitôt
Sa serait chouette si vous pouvez proposer quelques chose 

Comme vous l'aurez compris, je persiste toujours à vouloir créer une version Pb une petite appli pour faire de photos HD

Pour ce faire, j'ai tout simplement adapté un code en Pb que j'avais trouvé sur le réseau, malheureusement, je n'obtient pas le résultat escompté

Je vous met en lien le fichier (Library) nécessaire pour le fonctionnement du code en question (côte à côte avec le fichier source Pb)
version 64 https://github.com/pbcodex/escapi/blob/ ... pi_x64.dll
version 32 https://github.com/pbcodex/escapi/blob/ ... pi_x32.dll
Voici le code à hospitaliser:
Le but étant d'avoir un preview vidéo 760*440
puis quand je presse le bouton "OK" une capture photo 3264*2448 s'opère aussitôt
Code : Tout sélectionner
UsePNGImageEncoder()
Structure SimpleCapParams
*mTargetBuf
mWidth.l
mHeight.l
EndStructure
PrototypeC countCaptureDevicesProc()
PrototypeC initCaptureProc(deviceno, *aParams.SimpleCapParams)
PrototypeC deinitCaptureProc(deviceno)
PrototypeC doCaptureProc(deviceno)
PrototypeC isCaptureDoneProc(deviceno)
PrototypeC getCaptureDeviceNameProc(deviceno, *namebuffer, bufferlength)
PrototypeC ESCAPIDLLVersionProc()
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()
CompilerSelect #PB_Compiler_Processor
CompilerCase #PB_Processor_x86
Protected.i capdll = OpenLibrary(#PB_Any, "escapi_x32.dll")
CompilerCase #PB_Processor_x64
Protected.i capdll = OpenLibrary(#PB_Any, "escapi_x64.dll")
CompilerEndSelect
If capdll = 0
ProcedureReturn 0
EndIf
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
If ESCAPIDLLVersion() < $200
ProcedureReturn 0
EndIf
initCOM();
ProcedureReturn countCaptureDevices()
EndProcedure
device = 0
count = setupESCAPI()
If count = 0
End
EndIf
name$ = Space(1000)
getCaptureDeviceName(device, @name$, 1000)
name$ = PeekS(@name$, -1, #PB_Ascii)
scp.SimpleCapParams
scp\mWidth = 3264;
scp\mHeight = 2448;
scp\mTargetBuf = AllocateMemory(scp\mWidth * scp\mHeight * 4)
image = CreateImage(#PB_Any, 3264, 2448)
Window_1 = OpenWindow(#PB_Any, 0, 0, 800, 480, "TST01", #PB_Window_SystemMenu)
If Window_1
Image_Preview = ImageGadget(#PB_Any, 40, 0, 760, 440, ImageID(image))
Button_Shot = ButtonGadget(#PB_Any, 0, 70, 40, 90, "OK")
Button_Next = ButtonGadget(#PB_Any, 0, 170, 40, 20, "v")
Button_Back = ButtonGadget(#PB_Any, 0, 40, 40, 20, "^")
HideGadget(Image_Preview,0)
If initCapture(device, @scp)
AddWindowTimer(Window_1,1,1)
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
Select EventGadget()
Case Button_Shot:Debug "Shot OK"
If IsImage(image)
CopyImage(image,2)
ResizeImage(2,760,440,#PB_Image_Smooth)
SetGadgetState(Image_Preview, ImageID(2))
HideGadget(Image_Preview,0)
If SaveImage(image,"\tst"+Str(Random(9))+".png",#PB_ImagePlugin_PNG)
Debug "Succefull save"
EndIf
EndIf
EndSelect
doCapture(device)
If isCaptureDone(device) <> 0
Break
EndIf
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)
r.l = (pixel >> 16) & $FF
g.l = (pixel >> 8 ) & $FF
b.l = pixel & $FF
rgb = RGB(r,g,b)
Plot(x,y,rgb)
Next
Next
StopDrawing()
EndIf
EndSelect
ForEver
deinitCapture(device)
Else
Debug "Pas de capture possible!"
EndIf
EndIf
End
