@Dadido3
Der Link zu Deinem Beispiel existiert leider nicht mehr. Könntest Du (oder wer anders) bitte nochmal so nett sein und ein Beispiel irgendwo hochladen?
Danke,
Morty
VideoCapture
Vielen Dank Dadido3 und auch dir X360 Andy, wegen des Stichwortes Avcicap32, dadurch bin ich auf diesen Beitrag gestoßen. VidCapDll.dll ist erheblich schneller. Ich habe bisher nur 4-5 Bilder/ Sekunde geschafft, jetzt sind es 25. Das Programm von Dadido3 habe ich so geändert, dass die Farben richtig sind. Meine Webcam macht nur 320x240 Pixel. Dadurch konnte ich nicht alles testen und stelle hier mal die „abgespeckte“ Variante rein. Achtung es wird eine Datei unter C: erzeugt (zum kontrollieren des Interrupts). Es sollte einfach sein, die komfortable Variante von Dadido3 zu ändern. Übrigens, die Avcicap32 wird auch nicht mehr weiterentwickelt.
Code: Alles auswählen
; ##########################################################
; # VidCapture by http://www.codevis.com/ #
; # #
; # Example by David Vogel (Xaardas, Dadido3) #
; # Farben verändert, komprimiert (gpphj) #
; # Purebasic 4.20 #
; # #
; ##########################################################
; ##################### Variablen ##########################
#CVIMAGETYPE_RGB24 = 1 ; 8-bit red, green, blue triplets
#Breite =320
#Hoehe =240
#Tiefe = 3
#Laenge = 1
#SIZE = #Breite*#Hoehe*#Tiefe*#Laenge
Structure CVIMAGESTRUCT
Version.l ; Structure Version (1)
ImageType.l ; Type of image
BytesPerPixel.l ; # of bytes per pixel (3)
NumChannels.l ; Number of channels (e.g. 3 for RGB, 1 for greyscale)
ImageWidth.l ; Width of image in pixels
ImageHeight.l ; Height of image in pixels
ImageDataSize.l ; Size of image in bytes. Redundant, but quick For checks
PixelDataPtr.l ; Pointer to raw pixel data (typically r,g,b format)
EndStructure
Structure VidCap_Mode
xRes.l
yRes.l
frameRate.l
vidFormat.l
EndStructure
Structure VidCapSystem
vidCapSystem.l
CapSystem.l
Devices.l
Device.l
Modes.l
Mode.l
Mode_Values.VidCap_Mode
EndStructure
Structure cBGR
b.b
g.b
r.b
EndStructure
Global *bild = AllocateMemory(#SIZE)
Global VidCapSystem.VidCapSystem
Global hbmp.l=CreateImage(3,320,240,24)
; ########################################## Librarys ##############################################
Import "VidCapDll.lib"
CVAcquireVidCap (*vidCapSystem)
CVReleaseVidCap (vidCapSystem )
CVGetNumDevices (vidCapSystem )
CVGetDeviceName (vidCapSystem , deviceNum, *devNameBuffer, *nameBufLen)
CVDevConnect (vidCapSystem , devIndex)
CVDevDisconnect (vidCapSystem )
CVDevGetProperty(CapSystem , property , *curValue , *defValue, *minValue , *maxValue , *minstep)
CVDevSetProperty(CapSystem , property , newValue)
CVDevGetNumModes(vidCapSystem )
CVDevGetModeInfo(vidCapSystem , modeIndex, *xRes , *yRes , *frameRate , *vidFormat)
CVDevStartCap (vidCapSystem , modeIndex, imageType , callback , *cbUserParam, *capHandle)
CVDevStopCap (vidCapSystem , capHandle)
EndImport
; ########################################## Procedur FrameCallback ############################################
Procedure FrameCallback(CVRES.l, *Image.CVIMAGESTRUCT, *Userparam)
Protected *Pointer.cBGR
Protected ausgabe.s, zeit.s, start.l, stop.l
Protected *Color.cBGR, r.b
start=ElapsedMilliseconds()
*Pointer = *Image\PixelDataPtr
CopyMemory(*Pointer, *bild, #SIZE)
*Color = *bild
For k=0 To #SIZE-3 Step 3 ;
r= *Color\b
*Color\b= *Color\r
*Color\r =r
*Color + 3
Next
SetBitmapBits_(ImageID(3),#SIZE,*bild)
StartDrawing(WindowOutput(0))
DrawImage(ImageID(3), 0, 0)
StopDrawing()
ausgabe="Cam "
stop=ElapsedMilliseconds()
zeit.s=FormatDate("%hh:%ii:%ss", Date())
ausgabe+" CPU Zeit "+Str(stop-start)+" zeit "+zeit
WriteStringN(0,ausgabe)
ProcedureReturn #True
EndProcedure
; ########################################## Init ############################################
Path$ ="C:\"
Datei$=FormatDate("%yy%mm%dd_%hh%ii%ss.txt", Date())
CreateFile (0,Path$+Datei$)
WriteStringN(0,"Programm: Capture Test.pb")
OpenWindow(0, 0, 0, #Breite, #Hoehe,"Capture Test", #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_MinimizeGadget)
CVAcquireVidCap (@VidCapSystem\VidCapSystem)
VidCapSystem\Device = 0
CVDevConnect(VidCapSystem\VidCapSystem, VidCapSystem\Device)
CVDevStartCap(VidCapSystem\VidCapSystem, VidCapSystem\Mode, #CVIMAGETYPE_RGB24, @FrameCallback(), 0, @VidCapSystem\CapSystem)
; ########################################## Hauptprogramm ############################################
Repeat
Repeat
Event = WindowEvent()
If Event = #PB_Event_Gadget
Select EventGadget()
EndSelect
ElseIf Event = #PB_Event_CloseWindow
Quit = 1
EndIf
Until Event = 0
Delay(10)
Until Quit = 1 Or GetAsyncKeyState_(#VK_ESCAPE)
; ############################################# Ende #############################################
CVDevStopCap(VidCapSystem\VidCapSystem, VidCapSystem\CapSystem)
CVDevDisconnect(VidCapSystem\VidCapSystem)
CVReleaseVidCap(VidCapSystem\VidCapSystem)
CloseWindow(0)