videocapture aus der ablage in das fenster

Fragen zu Grafik- & Soundproblemen und zur Spieleprogrammierung haben hier ihren Platz.
super_castle
Beiträge: 557
Registriert: 29.11.2005 15:05

videocapture aus der ablage in das fenster

Beitrag von super_castle »

mit diesem programm wird links im fenster das originalcapturevideobild vom roboter(videofunk) dargestellt
und rechts im fenster wird mit dem knopf "schnapp" ein bild zum auswerten aus der ablage dargestellt.
dieses rechte bild werte ich nach hindernissen aus und gebe dem roboter ein steuersignal über rs232
zum neuen verhalten. je nach auswertezeit kannn dann immer ein bild nach bedarf geladen werden. natürlich wird dieser vorgang automatisiert.
"benötigt wird eine wintv-karte mit fbas- oder normalen eingang" und am eingang das videosignal

mfg castle

1. programm "fenster.pb"

Code: Alles auswählen

Global hWnd

Enumeration
  #Window_0
EndEnumeration

;- Gadget Constants
;
Enumeration
  #Frame3D_0
  #Frame3D_1
  #Button_0
EndEnumeration

Enumeration
  #ImageGadget_0
EndEnumeration

Procedure Open_Window_0()
  hWnd = OpenWindow(#Window_0, 0, 0, 780, 350,  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar , "New window ( 0 )")
  CreateGadgetList(WindowID())
  Frame3DGadget(#Frame3D_0, 120, 20, 310, 310, "")
  Frame3DGadget(#Frame3D_1, 445, 20, 310, 310, "")
  ButtonGadget(#Button_0, 20, 40, 65, 25, "schnapp")
EndProcedure

2. programm "hauptprogramm.pb"

Code: Alles auswählen

; PureBasic Visual Designer v3.92 build 1460

IncludeFile "fenster.pb"

#WM_CAP_START = #WM_USER
#WM_CAP_SET_CALLBACK_ERROR = #WM_CAP_START + 2
#WM_CAP_SET_CALLBACK_STATUS = #WM_CAP_START + 3
#WM_CAP_SET_CALLBACK_YIELD = #WM_CAP_START + 4
#WM_CAP_SET_CALLBACK_FRAME = #WM_CAP_START + 5
#WM_CAP_SET_CALLBACK_VIDEOSTREAM = #WM_CAP_START + 6
#WM_CAP_SET_CALLBACK_WAVESTREAM = #WM_CAP_START + 7
#WM_CAP_DRIVER_CONNECT = #WM_CAP_START + 10
#WM_CAP_DRIVER_DISCONNECT = #WM_CAP_START + 11
#WM_CAP_DRIVER_GET_CAPS = #WM_CAP_START + 14
#WM_CAP_DLG_VIDEOFORMAT = #WM_CAP_START + 41
#WM_CAP_DLG_VIDEOSOURCE = #WM_CAP_START + 42
#WM_CAP_DLG_VIDEODISPLAY = #WM_CAP_START + 43
#WM_CAP_SET_PREVIEW = #WM_CAP_START + 50
#WM_CAP_SET_PREVIEWRATE = #WM_CAP_START + 52
#WM_CAP_GET_STATUS = #WM_CAP_START + 54
#WM_CAP_FILE_SAVEDIB = #WM_CAP_START + 25
#WM_CAP_SET_SCALE = #WM_CAP_START + 53
#WM_CAP_SET_CALLBACK_CAPCONTROL = #WM_CAP_START + 85
#WM_CAP_EDIT_COPY = #WM_CAP_START + 30
#WM_CAP_GRAB_FRAME = #WM_CAP_START+60

Open_Window_0()
OpenLibrary(0, "AVICAP32.DLL")

hRobby = CallFunction(0, "capCreateCaptureWindowA", "BLUBBER", #WS_VISIBLE + #WS_CHILD, 120, 30, 310, 300, hWnd, 0)
SendMessage_(hRobby, #WM_CAP_DRIVER_CONNECT, 0 , 0) 
SendMessage_(hRobby, #WM_CAP_SET_SCALE , 1 , 0)
SendMessage_(hRobby, #WM_CAP_SET_PREVIEWRATE, 50, 0)
SendMessage_(hRobby, #WM_CAP_SET_PREVIEW, 1 , 0)

Repeat ; Start of the event loop
  
  Event = WaitWindowEvent() ; This line waits until an event is received from Windows
  
  WindowID = EventWindowID() ; The Window where the event is generated, can be used in the gadget procedures
  
  GadgetID = EventGadgetID() ; Is it a gadget event?
  
  EventType = EventType() ; The event type
  
  If Event = #PB_EventGadget
    
    If GadgetID = #Button_0
      If Link <> 0 
        CreateImage(0, 310, 300)
        StartDrawing( ImageOutput() )
        DrawImage(Link, 0,0,310, 300 ) 
        StopDrawing()
        ImageGadget( #Window_0, 445,30,310,300,UseImage(0)) 
      EndIf
    EndIf
    
  EndIf
  
  SendMessage_(hRobby, #WM_CAP_GRAB_FRAME, 0 , 0)
  SendMessage_(hRobby, #WM_CAP_EDIT_COPY, 0 , 0)
  Link = GetClipboardData(#PB_ClipboardImage)
  
  Delay(1)
Until Event = #PB_Event_CloseWindow ; End of the event loop

SendMessage_(hRobby, #WM_CAP_SET_PREVIEW, 0, 0)
SendMessage_(hRobby, #WM_CAP_DRIVER_DISCONNECT, "BLUBBER", 0)
CloseWindow(0)
CloseLibrary(0)


End
;