Escapi64 capture vidéo photo [Résolut]

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Ekim
Messages : 215
Inscription : dim. 24/juin/2018 1:20

Escapi64 capture vidéo photo [Résolut]

Message par Ekim »

Bonsoirs à tous :D

Comme vous l'aurez compris, je persiste toujours à vouloir créer une version Pb une petite appli pour faire de photos HD 8) 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é :oops:

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
Sa serait chouette si vous pouvez proposer quelques chose :wink:
Dernière modification par Ekim le dim. 26/mars/2023 1:02, modifié 1 fois.
Avatar de l’utilisateur
Ar-S
Messages : 9539
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: Escapi64 capture vidéo photo

Message par Ar-S »

Tu as une webcam qui fait du 3264*2448 ? 8O
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Avatar de l’utilisateur
falsam
Messages : 7317
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: Escapi64 capture vidéo photo

Message par falsam »

Tout comme Ar-S je me suis posé la question sur ton format d'image et pourquoi tu sauvegardes au format PNG. Mais qu'importe j'ai corrigé ton code. A compiler sans le débug.

Code : Tout sélectionner

Structure SimpleCapParams
  *mTargetBuf ; Must be at least mWidth * mHeight * SizeOf(int) of size! 
  mWidth.l
  mHeight.l
EndStructure

;/* Return the number of capture devices found */
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
  
  ;/* Verify DLL version */
  If ESCAPIDLLVersion() < $200
    ProcedureReturn 0
  EndIf
  
  ;/* Initialize COM.. */
  initCOM();  
  
  ; returns number of devices found
  ProcedureReturn countCaptureDevices()
EndProcedure

;Test Area
device = 0

count = setupESCAPI()
Debug "init: " + Str(count)

If count = 0
  End
EndIf

name$ = Space(1000)
getCaptureDeviceName(device, @name$, 1000)
name$ = PeekS(@name$, -1, #PB_Ascii)
Debug "name: " + name$

scp.SimpleCapParams
scp\mWidth = 3264
scp\mHeight = 2448
scp\mTargetBuf = AllocateMemory (scp\mWidth * scp\mHeight * 4)


UsePNGImageEncoder()
countImage.i = 0

If initCapture(device, @scp)
  Debug "cap init successful"  
  
  If OpenWindow(0, 0, 0, 810, 480, name$, #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
    Image_Preview = ImageGadget(#PB_Any, 40, 0, 760, 440, 0)
    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, "^")
    
    Quit = 0
    
    ; Boucle principale
    Repeat
      doCapture(device)
      
      ; Boucle de capture 
      ; isCaptureDone retourne 1 quand la capture est terminée
      ; Les évenements se gérent dans cette boucle
      While isCaptureDone(device) = 0
        Select WaitWindowEvent(100) 
          Case #PB_Event_CloseWindow
            Quit = 1
            
          Case #PB_Event_Gadget
            If IsImage(image)
              countImage + 1
              If SaveImage(image, "Capture " + Str(countImage) + ".png", #PB_ImagePlugin_PNG)  
                MessageRequester("Information", "Image sauvegarder")  
              EndIf   
            EndIf     
        EndSelect      
    Wend
    
    ; La capture est effectuée et les evenements sont traités
    ; Libération de l'image capturée précédement si existant
    If IsImage(image)
      FreeImage(image)
    EndIf
    
    ; Transfert dans une nouvelle image
    image = CreateImage(#PB_Any, scp\mWidth, scp\mHeight, 32)    
    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)
          rgb   = RGB((pixel >> 16) & $FF, (pixel >> 8) & $FF, pixel & $FF)
          Plot(x, y, rgb)
        Next
      Next
      StopDrawing()
      
      ; Copie de "Image" dans "ImagePreview"
      ; "Image" est préservée pour sauvegarde eventuelle 
      CreateImage(0, 760, 440, 32)
      CopyImage(image, 0)
      
      ; La taille de la capture est plus grande que la préview
      ResizeImage(0, 760, 440)
      SetGadgetState(Image_Preview, ImageID(0))
      
      ; Liberation de l'image de prévisualisation
      If IsImage(0)
        FreeImage(0)
      EndIf
      
    EndIf            
  Until Quit
  deinitCapture(device)
Else
  Debug "init capture failed!"
EndIf 
EndIf
End
Configuration : Windows 11 Famille 64-bit - PB 6.20 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Ekim
Messages : 215
Inscription : dim. 24/juin/2018 1:20

Re: Escapi64 capture vidéo photo [Résolut]

Message par Ekim »

Salut @Ar-S, impressionnante la résolution pas vrai? :D
il s'agit d'une camera industriel que j'ai pourtant récupéré dans un container poubelle d'une société en liquidation judiciaire :lol:

Salut @falsam, tu es un géni, un grand merci) pour le côté 'saccadé' je trouverais une solution mais ce n'est franchement pas dramatique :wink:

vous êtes chouettes, encore merci)
Avatar de l’utilisateur
falsam
Messages : 7317
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: Escapi64 capture vidéo photo [Résolut]

Message par falsam »

Puisque le sujet est résolu, je vous propose de découvrir (ou redécouvrir) ce code de détection de mouvements créer par GallyHC.

Vous devez vous procurer les dll 32 ou 64 bits de escapi qui doivent se trouver dans le meme dossier que ce code.
Vous pouvez obtenir ces dll ainsi que le code de GallyHC en cliquant sur ce lien
https://github.com/pbcodex/escapi/archi ... master.zip

Code : Tout sélectionner

; ****************************************************************************
;Simple detect by GallyHC                                                    *
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************

DisableASM
EnableExplicit

; ****************************************************************************
; ****************************************************************************
; ****************************************************************************

DeclareModule PureMoveDetect
  ;
  DisableASM
  EnableExplicit
  ;
  ;
  ;
  Structure ESCAPI_PARAMETERS
    differentiel.i
    minimumpoint.i
    minimumcounter.i
    xy_pixelsize.i
    xy_pixelzone.i
    colorshade.i
    grayscale.i
    gaussian.i
    viewresult.b
    viewdetect.b
  EndStructure
  ;
  ; VALEURS GLOBALE DE LA DETECTION AVEC ESCAPI.
  ;
  Global escapi_parameters.ESCAPI_PARAMETERS
  escapi_parameters\differentiel    = 80          ; Facteur de détection
  escapi_parameters\minimumpoint    = 10          ; Nombre mininum de points pour la détection
  escapi_parameters\minimumcounter  = 2           ; Nombre de cadre avant détection
  escapi_parameters\xy_pixelsize    = 2           ; taille des pixel de détection (1,2,4,8,16)
  escapi_parameters\colorshade      = 1           ; nombre de teinte de couleurs (1,2,4,8,16,32,64)
  escapi_parameters\grayscale       = #False      ; Met la détection en gris
  escapi_parameters\gaussian        = #True       ; Met la détection avec mode gaussian
  ;
  escapi_parameters\viewresult      = #True       ; Affichage du resultat de traitement.
  escapi_parameters\viewdetect      = #True       ; Affichage des points de détection.
  ;
  ; VALEURS GLOBALE DE LA DETECTION AVEC ESCAPI.
  ;
  Declare Escapi_OpenCapture  ()
  Declare Escapi_CloseCapture ()
  
EndDeclareModule

Module PureMoveDetect
  ;
  DisableASM
  EnableExplicit
  ;
  ;
  ;
  #ESCAPI_WIDTH       = 640
  #ESCAPI_HEIGHT      = 400
  #ESCAPI_WIDTH_M1    = #ESCAPI_WIDTH  - 1
  #ESCAPI_HEIGHT_M1   = #ESCAPI_HEIGHT - 1
  ;
  ; 
  ;
  Structure ESCAPI_RGB
    r.l
    g.l
    b.l
  EndStructure
  Structure ESCAPI_CAPPARAMS
    *mTargetBuf
    mWidth.l
    mHeight.l
  EndStructure
  ;
  ;
  ;
  PrototypeC countCaptureDevicesProc()
  PrototypeC initCaptureProc(deviceno, *aParams.ESCAPI_CAPPARAMS)
  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
  ;
  Global.i escapi_device
  Global Font_ID1.i = LoadFont(#PB_Any, "Century Gothic", 10, #PB_Font_Bold | #PB_Font_HighQuality)
  ;
  ;
  ;
  Procedure Escapi_Setup()
    ;
    ;
    ;
    Protected initCOM.initCOMProc
    ;
    CompilerSelect #PB_Compiler_Processor
      CompilerCase #PB_Processor_x86
        Protected.i escapidll = OpenLibrary(#PB_Any, "escapi_x32.dll")
      CompilerCase #PB_Processor_x64
        Protected.i escapidll = OpenLibrary(#PB_Any, "escapi_x64.dll")
    CompilerEndSelect
    ;
    If escapidll = 0
      ProcedureReturn 0
    EndIf
    ;
    countCaptureDevices     = GetFunction(escapidll, "countCaptureDevices")
    initCapture             = GetFunction(escapidll, "initCapture")
    deinitCapture           = GetFunction(escapidll, "deinitCapture")
    doCapture               = GetFunction(escapidll, "doCapture")
    isCaptureDone           = GetFunction(escapidll, "isCaptureDone")
    initCOM                 = GetFunction(escapidll, "initCOM")
    getCaptureDeviceName    = GetFunction(escapidll, "getCaptureDeviceName")
    ESCAPIDLLVersion        = GetFunction(escapidll, "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
  ;
  ;
  ;
  Procedure Escapi_OpenCapture()
    ;
    ;
    ;
    Define.i escapi_buffersize  = #ESCAPI_WIDTH  * #ESCAPI_HEIGHT  * 4
    Define.i escapi_pixcount    = (#ESCAPI_WIDTH * #ESCAPI_HEIGHT) - 2
    Define.i escapi_offset      = 0
    Define.i escapi_pitch       = 0
    Define.i escapi_number      = 0
    Define.i escapi_quit        = #False
    Define.i escapi_detect      = #False
    Define.i escapi_count       = Escapi_Setup()
    Define.s escapi_name        = Space(255)
    Define.i i, x, y, xx, yy, hm1, colr, colg, colb, diff, cx, cy
    Define  *escapi_readbuffer
    Define  *escapi_writebuffer
    ;
    Dim escapi_tabsaving.ESCAPI_RGB   (#ESCAPI_WIDTH / escapi_parameters\xy_pixelsize, #ESCAPI_HEIGHT / escapi_parameters\xy_pixelsize)
    Dim escapi_tabcapture.ESCAPI_RGB  (#ESCAPI_WIDTH / escapi_parameters\xy_pixelsize, #ESCAPI_HEIGHT / escapi_parameters\xy_pixelsize)
    Dim escapi_tabpointzone           (#ESCAPI_WIDTH / escapi_parameters\xy_pixelsize, #ESCAPI_HEIGHT / escapi_parameters\xy_pixelsize)
    Dim escapi_tabboundbox.point      (1)
    ;
    If escapi_count > 0
      getCaptureDeviceName(escapi_device, @escapi_name, 255)
      ;
      For i=0 To escapi_device
        getCaptureDeviceName(i, @escapi_name, 255)
        Debug PeekS(@escapi_name, -1, #PB_Ascii)
      Next i
      ;
      Define escapi_dll.ESCAPI_CAPPARAMS
      With escapi_dll
        \mWidth             = #ESCAPI_WIDTH
        \mHeight            = #ESCAPI_HEIGHT
        \mTargetBuf         = AllocateMemory(escapi_buffersize)
        *escapi_readbuffer  = \mTargetBuf
      EndWith
      ;
      If initCapture(escapi_device, @escapi_dll)
        ;
        OpenWindow(#PB_Any, 50, 50, #ESCAPI_WIDTH, #ESCAPI_HEIGHT, PeekS(@escapi_name, -1, #PB_Ascii), #PB_Window_SystemMenu)
        Define.i escapi_canva = CanvasGadget(#PB_Any, 0, 0, #ESCAPI_WIDTH, #ESCAPI_HEIGHT)
        ;
        If doCapture(escapi_device) <> 0
          Repeat
            ;
            doCapture(escapi_device)
            While isCaptureDone(escapi_device) = #False
              If WaitWindowEvent(1) = #PB_Event_CloseWindow
                escapi_quit = #True
                Break
              EndIf
              ;
              Delay(2)
            Wend
            ;
            StartDrawing(CanvasOutput(escapi_canva))
              *escapi_writebuffer = DrawingBuffer()
              escapi_pitch        = DrawingBufferPitch()
            StopDrawing()
            ;
            ; AFFICHAGE ET STOCKAGE DES POINTS DE LA CAPTURE.
            ;
            escapi_offset = 0
            FreeArray(escapi_tabcapture())
            Dim escapi_tabcapture.ESCAPI_RGB  (#ESCAPI_WIDTH / escapi_parameters\xy_pixelsize, #ESCAPI_HEIGHT / escapi_parameters\xy_pixelsize)
            For y = 0 To #ESCAPI_HEIGHT_M1 Step 1
              hm1 = *escapi_writebuffer + ((#ESCAPI_HEIGHT_M1 - y) * escapi_pitch)
              For x = 0 To #ESCAPI_WIDTH_M1 Step 1
                ;
                If escapi_parameters\viewresult = #False
                  PokeL(hm1 + x * 3, PeekL(*escapi_readbuffer + escapi_offset))
                EndIf
                ;
                diff = PeekL(*escapi_readbuffer + escapi_offset)
                With escapi_tabcapture(x / escapi_parameters\xy_pixelsize, y / escapi_parameters\xy_pixelsize)
                  If \r > 0 Or \g > 0 Or \b > 0
                    \r = (\r + (diff >> 16) & $ff) / 2
                    \g = (\g + (diff >> 8 ) & $ff) / 2
                    \b = (\b + (diff >> 0 ) & $ff) / 2
                  Else
                    \r = (diff >> 16) & $ff
                    \g = (diff >> 8 ) & $ff
                    \b = (diff >> 0 ) & $ff
                  EndIf
                EndWith
                escapi_offset + 4
              Next x
            Next y
            ;
            ; ROUTINE DE TRAITEMENT DE LA DETECTION.
            ;
            escapi_count = 0
            escapi_tabboundbox(0)\x = #ESCAPI_WIDTH
            escapi_tabboundbox(0)\y = #ESCAPI_HEIGHT
            escapi_tabboundbox(1)\x = 0
            escapi_tabboundbox(1)\y = 0
            StartDrawing(CanvasOutput(escapi_canva))
              DrawingMode(#PB_2DDrawing_Default)
              DrawingFont(FontID(Font_ID1))
              ;
              If escapi_parameters\viewresult = #True
                Box(0, 0, #ESCAPI_WIDTH, #ESCAPI_HEIGHT, $ff)
              EndIf
              For y = 0 To #ESCAPI_HEIGHT_M1 Step 1
                For x = 0 To #ESCAPI_WIDTH_M1 Step 1
                  escapi_detect = #False
                  ;
                  colr = escapi_tabcapture(x / escapi_parameters\xy_pixelsize, y / escapi_parameters\xy_pixelsize)\r
                  colg = escapi_tabcapture(x / escapi_parameters\xy_pixelsize, y / escapi_parameters\xy_pixelsize)\g
                  colb = escapi_tabcapture(x / escapi_parameters\xy_pixelsize, y / escapi_parameters\xy_pixelsize)\b
                  ;
                  If escapi_parameters\gaussian = #True
                    If x > 1 And x < #ESCAPI_WIDTH_M1 - escapi_parameters\xy_pixelsize And y > 1 And y < #ESCAPI_HEIGHT_M1 - escapi_parameters\xy_pixelsize
                      colr = 0
                      colg = 0
                      colb = 0
                      For yy = -1 To 1 Step 1
                        For xx = -1 To 1 Step 1
                            colr + escapi_tabcapture((x + xx) / escapi_parameters\xy_pixelsize, (y + yy) / escapi_parameters\xy_pixelsize)\r
                            colg + escapi_tabcapture((x + xx) / escapi_parameters\xy_pixelsize, (y + yy) / escapi_parameters\xy_pixelsize)\g
                            colb + escapi_tabcapture((x + xx) / escapi_parameters\xy_pixelsize, (y + yy) / escapi_parameters\xy_pixelsize)\b
                        Next xx
                      Next yy 
                      colr / 9
                      colg / 9
                      colb / 9
                    EndIf
                  EndIf
                  ;
                  If escapi_parameters\grayscale = #True
                    If escapi_parameters\colorshade = 1
                      diff = (colr + colg + colb) / 3
                    Else
                      diff = (((colr + colg + colb) / 3) / escapi_parameters\colorshade) * escapi_parameters\colorshade
                    EndIf
                    colr = diff
                    colg = diff
                    colb = diff
                  Else
                    If escapi_parameters\colorshade > 1
                      colr = (colr / escapi_parameters\colorshade) * escapi_parameters\colorshade
                      colg = (colg / escapi_parameters\colorshade) * escapi_parameters\colorshade
                      colb = (colb / escapi_parameters\colorshade) * escapi_parameters\colorshade
                    EndIf
                  EndIf
                  ;
                  diff = 0
                  diff + Abs (escapi_tabsaving(x / escapi_parameters\xy_pixelsize, y / escapi_parameters\xy_pixelsize)\r - colr)
                  diff + Abs (escapi_tabsaving(x / escapi_parameters\xy_pixelsize, y / escapi_parameters\xy_pixelsize)\g - colg)
                  diff + Abs (escapi_tabsaving(x / escapi_parameters\xy_pixelsize, y / escapi_parameters\xy_pixelsize)\b - colb)
                  If x > 1 And x < #ESCAPI_WIDTH_M1 - escapi_parameters\xy_pixelsize And y > 1 And y < #ESCAPI_HEIGHT_M1 - escapi_parameters\xy_pixelsize
                    If diff > escapi_parameters\differentiel
                      escapi_count + 1
                      escapi_detect = #False
                      ;
                      If escapi_tabboundbox(0)\x > x
                        escapi_tabboundbox(0)\x = x
                      EndIf
                      If escapi_tabboundbox(0)\y > y
                        escapi_tabboundbox(0)\y = y
                      EndIf
                      If escapi_tabboundbox(1)\x < x
                        escapi_tabboundbox(1)\x = x
                      EndIf
                      If escapi_tabboundbox(1)\y < y
                        escapi_tabboundbox(1)\y = y
                      EndIf
                      ;
                      If escapi_parameters\viewresult = #True
                        If escapi_parameters\viewdetect = #True
                          Box(x, y, escapi_parameters\xy_pixelsize, escapi_parameters\xy_pixelsize, $ff00)
                        Else
                          Box(x, y, escapi_parameters\xy_pixelsize, escapi_parameters\xy_pixelsize, RGB(colr, colg, colb))
                        EndIf
                      EndIf
                    Else
                      If escapi_parameters\viewresult = #True
                        Box(x, y, escapi_parameters\xy_pixelsize, escapi_parameters\xy_pixelsize, RGB(colr, colg, colb))
                      EndIf
                    EndIf
                  EndIf
                  ;
                  escapi_tabpointzone(x / escapi_parameters\xy_pixelsize, y / escapi_parameters\xy_pixelsize) = escapi_detect
                  ;
                  escapi_tabsaving(x / escapi_parameters\xy_pixelsize, y / escapi_parameters\xy_pixelsize)\r = ((escapi_tabsaving(x / escapi_parameters\xy_pixelsize, y / escapi_parameters\xy_pixelsize)\r + colr)*100) / 200
                  escapi_tabsaving(x / escapi_parameters\xy_pixelsize, y / escapi_parameters\xy_pixelsize)\g = ((escapi_tabsaving(x / escapi_parameters\xy_pixelsize, y / escapi_parameters\xy_pixelsize)\g + colg)*100) / 200
                  escapi_tabsaving(x / escapi_parameters\xy_pixelsize, y / escapi_parameters\xy_pixelsize)\b = ((escapi_tabsaving(x / escapi_parameters\xy_pixelsize, y / escapi_parameters\xy_pixelsize)\b + colb)*100) / 200
                  ;
                  x + (escapi_parameters\xy_pixelsize - 1)
                Next x
                y + (escapi_parameters\xy_pixelsize - 1)
              Next y
              ;
              ; ROUTINE D'AFFICHAGE DE LA ZONE DE DETECTION.
              ;
              If escapi_count > escapi_parameters\minimumpoint
                escapi_number + 1 
                If escapi_number > escapi_parameters\minimumcounter
                  escapi_tabboundbox(0)\x = (escapi_tabboundbox(0)\x / escapi_parameters\xy_pixelsize) * escapi_parameters\xy_pixelsize
                  escapi_tabboundbox(0)\y = (escapi_tabboundbox(0)\y / escapi_parameters\xy_pixelsize) * escapi_parameters\xy_pixelsize
                  escapi_tabboundbox(1)\x = (escapi_tabboundbox(1)\x / escapi_parameters\xy_pixelsize) * escapi_parameters\xy_pixelsize
                  escapi_tabboundbox(1)\y = (escapi_tabboundbox(1)\y / escapi_parameters\xy_pixelsize) * escapi_parameters\xy_pixelsize
                  ;
                  DrawingMode(#PB_2DDrawing_AlphaBlend)
                  Box(escapi_tabboundbox(0)\x, escapi_tabboundbox(0)\y, escapi_tabboundbox(1)\x - escapi_tabboundbox(0)\x + escapi_parameters\xy_pixelsize, escapi_tabboundbox(1)\y - escapi_tabboundbox(0)\y + escapi_parameters\xy_pixelsize, $80000000) 
                  DrawingMode(#PB_2DDrawing_Default)
                  DrawText(escapi_parameters\xy_pixelsize + 4, escapi_parameters\xy_pixelsize + 4, " Movement detected ", $ffff)
                  LineXY(escapi_tabboundbox(0)\x, escapi_tabboundbox(0)\y, escapi_tabboundbox(1)\x + escapi_parameters\xy_pixelsize, escapi_tabboundbox(0)\y, $00ffff)
                  LineXY(escapi_tabboundbox(0)\x, escapi_tabboundbox(0)\y, escapi_tabboundbox(0)\x, escapi_tabboundbox(1)\y + escapi_parameters\xy_pixelsize, $00ffff)
                  LineXY(escapi_tabboundbox(1)\x + escapi_parameters\xy_pixelsize, escapi_tabboundbox(0)\y, escapi_tabboundbox(1)\x + escapi_parameters\xy_pixelsize, escapi_tabboundbox(1)\y + escapi_parameters\xy_pixelsize, $00ffff)
                  LineXY(escapi_tabboundbox(0)\x, escapi_tabboundbox(1)\y + escapi_parameters\xy_pixelsize, escapi_tabboundbox(1)\x + escapi_parameters\xy_pixelsize, escapi_tabboundbox(1)\y + escapi_parameters\xy_pixelsize, $00ffff)
                  LineXY(escapi_tabboundbox(0)\x, escapi_tabboundbox(0)\y + 1, escapi_tabboundbox(1)\x + escapi_parameters\xy_pixelsize, escapi_tabboundbox(0)\y + 1, $00ffff)
                  LineXY(escapi_tabboundbox(0)\x + 1, escapi_tabboundbox(0)\y, escapi_tabboundbox(0)\x + 1, escapi_tabboundbox(1)\y + escapi_parameters\xy_pixelsize, $00ffff)
                  LineXY(escapi_tabboundbox(1)\x + escapi_parameters\xy_pixelsize - 1, escapi_tabboundbox(0)\y, escapi_tabboundbox(1)\x + escapi_parameters\xy_pixelsize - 1, escapi_tabboundbox(1)\y + escapi_parameters\xy_pixelsize, $00ffff)
                  LineXY(escapi_tabboundbox(0)\x, escapi_tabboundbox(1)\y + escapi_parameters\xy_pixelsize - 1, escapi_tabboundbox(1)\x + escapi_parameters\xy_pixelsize, escapi_tabboundbox(1)\y + escapi_parameters\xy_pixelsize - 1, $00ffff)
                EndIf
              Else
                escapi_number = 0
              EndIf
              ;
              ;DrawingMode(#PB_2DDrawing_Default)
              ;DrawText(escapi_parameters\xy_pixelsize + 4, #ESCAPI_HEIGHT - (TextHeight("A") + escapi_parameters\xy_pixelsize + 4), " " + FormatDate("%dd/%mm/%yyyy - %hh:%ii:%ss" + " ", Date()), $ffff)
            StopDrawing()
            ;
          Until escapi_quit
        Else
          MessageRequester("Error", "Capture failed.")
        EndIf
        ;
        FreeMemory(escapi_dll\mTargetBuf)
        ;
      Else
        MessageRequester("Error", "Init capture failed.")
      EndIf
      ;
      deinitCapture(escapi_device)
    Else
      MessageRequester("Error", "Unable to initialize ESCAPI.")
    EndIf
  
  EndProcedure
  ;
  Procedure Escapi_CloseCapture()
    ;
    ;
    ;
    deinitCapture(escapi_device)
    
  EndProcedure

EndModule

; ****************************************************************************
; ****************************************************************************
; ****************************************************************************

PureMoveDetect::Escapi_OpenCapture()
PureMoveDetect::Escapi_CloseCapture()
Configuration : Windows 11 Famille 64-bit - PB 6.20 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Ekim
Messages : 215
Inscription : dim. 24/juin/2018 1:20

Re: Escapi64 capture vidéo photo [Résolut]

Message par Ekim »

Hello @falsam, effectivement c'est super intéressant, et ça détecte même quant il n'y pas la mise au point
c'est super cool pour le partage, encore merci :D
Répondre