WebCam "auslesen"



  • Win2k, M Visual C++



  • Also wen die Webcam ihre Bilder auf irgendeinem Server ablegt kann man sie ziemlich easy herunterladen.



  • Ja, über diese Möglichkeit hatte ich auch schon nachgedacht, jedoch ist sie für mein Projekt ungeeignet, da ich die Bilder in Realtime brauche (also mindestens 24 pro Sekunde) ... Das würde so'ne umständliche Servervariante nicht schaffen.

    Das Suchen geht also weiter.

    MFG
    Romeo



  • Wenn die Webcam nen ganz normalen Capture Treiber installiert hat, lässt sich das über DirectShow lösen.



  • Na das hört sich doch schonmal nach was an ... du hast nicht zufällig noch nähere Informationen dazu ???

    Bin aber auch mal am googlen ... mal sehn was es dazu gibt.

    Romeo



  • so habe ich meine webcam ausgelesen:

    #include <windows.h>
    #include <vfw.h>
    #include "resource.h"
    
    #define ID_BUTTON_FOTO	1
    #define ID_BUTTON_CLOSE	2
    #define ID_VIDEO_WINDOW	3
    #define BUTTON_BREITE	60
    #define BUTTON_HOHE		20
    #define FENSTER_BREITE  350
    #define FENSTER_HOHE	320
    #define P_FILM			0
    #define P_FOTO			1
    
    LRESULT	CALLBACK	WndProc				(HWND, UINT, WPARAM, LPARAM) ;
    BOOL				FensterSkalieren	(HWND) ;
    BOOL				ButtonsSkalieren	(HWND, int, int) ;
    BOOL				BildSpeichern		(HWND, PTSTR) ;
    
    TCHAR			szAppName[] = TEXT ("WebCam") ;
    OPENFILENAME	ofn ;
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow){
    	HWND			hwnd ;
        MSG				msg ;
        WNDCLASSEX		wndclassex ;
    	wndclassex.cbSize			= sizeof (WNDCLASSEX) ;
        wndclassex.style			= CS_HREDRAW | CS_VREDRAW ;
        wndclassex.lpfnWndProc		= WndProc ;
        wndclassex.cbClsExtra		= 0 ;
        wndclassex.cbWndExtra		= 0 ;
        wndclassex.hInstance		= hInstance ;
        wndclassex.hIcon			= LoadIcon (hInstance, MAKEINTRESOURCE (101)) ;
        wndclassex.hCursor			= LoadCursor (NULL, IDC_ARROW) ;
        wndclassex.hbrBackground	= (HBRUSH) (COLOR_BTNFACE + 1) ;
        wndclassex.lpszMenuName		= szAppName ;
        wndclassex.lpszClassName	= szAppName ; 
    	wndclassex.hIconSm			= NULL ;
    	RegisterClassEx (&wndclassex) ;
        hwnd = CreateWindowEx (NULL ,
    							szAppName, TEXT ("WebCam"),
    							WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU | WS_CAPTION,
    							CW_USEDEFAULT , CW_USEDEFAULT ,
    							FENSTER_BREITE, FENSTER_HOHE,
    							NULL, LoadMenu (hInstance, MAKEINTRESOURCE (102)), hInstance, NULL) ;
    	ShowWindow (hwnd, iCmdShow) ;
        UpdateWindow (hwnd) ;
        while (GetMessage (&msg, NULL, 0, 0))
        {
             TranslateMessage (&msg) ;
             DispatchMessage (&msg) ;
        }
        return msg.wParam ;
    }
    
    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
    	static	HINSTANCE		hInstance ;
    	static	HWND			hwndVideo ;
    	static	int				iIndex = 0 ;
    	char					szDeviceName[80],
    							szDeviceVersion[80],
    							str[161],
    							szFileName[MAX_PATH] ;
    	static	int				iBreite = 0,
    							iHoche = 0,
    							iPruef = P_FOTO ;
    	switch (message){
    		case WM_CREATE :
    			hInstance = ((LPCREATESTRUCT) lParam) -> hInstance ;
    			CreateWindowEx (NULL, "button", 
    							TEXT ("Foto"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 
    							0, 0, 0, 0,
    							hwnd, (HMENU) ID_BUTTON_FOTO, hInstance, NULL) ;
    			CreateWindowEx (NULL, "button", 
    							TEXT ("Ende"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 
    							0, 0, 0, 0,
    							hwnd, (HMENU) ID_BUTTON_CLOSE, hInstance, NULL) ;
    			hwndVideo = capCreateCaptureWindow(
    							(LPSTR) "Meine WebCam",
    							WS_CHILD | WS_VISIBLE,
    							0, 0, 0, 0,
    							(HWND) hwnd, (int) ID_VIDEO_WINDOW) ; 
    			if (!capDriverConnect (hwndVideo, iIndex)) {
    				MessageBox (hwnd, "Treiber für die Webcam kann nicht geladen werden...", "Fehler", MB_ICONERROR) ;
    				SendMessage (hwnd, WM_DESTROY, 0, 0) ;
    				return 0;
    			}			
    			capPreviewRate (hwndVideo, 33.3) ;
    			capPreview (hwndVideo, TRUE) ;
    			capGetDriverDescription (iIndex, szDeviceName, sizeof (szDeviceName),
    										szDeviceVersion, sizeof (szDeviceVersion)) ;
    			wsprintf (str, "%s, %s", szDeviceName, szDeviceVersion) ;
    			MessageBox (NULL, str, "Verbunden über...", NULL) ;
    			FensterSkalieren (hwnd) ;
    			ButtonsSkalieren (hwnd, iBreite, iHoche) ;
    			return 0 ;
    		case WM_SIZE :
    			iBreite = LOWORD (lParam) ;
    			iHoche = HIWORD (lParam) ;
    			return 0 ;
    		case WM_COMMAND :
    			switch (LOWORD (wParam)){
    				case ID_DATEI_BEENDEN :
    				case ID_BUTTON_CLOSE :
    					SendMessage (hwnd, WM_DESTROY, 0, 0) ;
    					break ;
    				case ID_BUTTON_FOTO :
    					if (iPruef == P_FOTO){
    						SetWindowText (GetDlgItem (hwnd, ID_BUTTON_FOTO), "Film") ;
    						capPreview (hwndVideo, FALSE) ;
    						iPruef = P_FILM ;
    					}
    					else if (iPruef == P_FILM){
    						SetWindowText (GetDlgItem (hwnd, ID_BUTTON_FOTO), "Foto") ;
    						capPreview (hwndVideo, TRUE) ;
    						iPruef = P_FOTO ;
    					}
    
    					break ;
    				case ID_DATEI_SPEICHERN :
    					szFileName[0] = '\0' ;
    					BildSpeichern (hwnd, szFileName) ;
    					capFileSaveDIB (hwndVideo, szFileName) ;
    					break ;
    				case ID_BEARBEITEN_QELLE :
    					capDlgVideoSource(hwndVideo) ;
    					break ;
    				case ID_BEARBEITEN_AUFLOESUNG :
    					capDlgVideoFormat (hwndVideo) ;
    					FensterSkalieren (hwnd) ;
    					ButtonsSkalieren (hwnd, iBreite, iHoche) ;
    					break ;
    				case ID_BEARBEITEN_KOMPRESION:
    					capDlgVideoCompression(hwndVideo) ;
    					break ;
    			}
    			return 0 ;
     		case WM_DESTROY :
    			capPreview (hwndVideo, FALSE) ;
    			capDriverDisconnect (hwndVideo) ;
    			PostQuitMessage (0) ;
    			return 0 ;
    	}
        return DefWindowProc (hwnd, message, wParam, lParam) ;
    }
    
    BOOL BildSpeichern (HWND hParent, PTSTR pstrFileName){
    	ZeroMemory (&ofn, sizeof (OPENFILENAME)) ;
    	ofn.lStructSize			= sizeof (OPENFILENAME) ;
    	ofn.hInstance			= NULL ;
    	ofn.lpstrFilter			= TEXT ("Bilddateiten (*.BMP)\0*.bmp\0") 
    							  TEXT ("Alle Dateien (*.*)\0*.*\0\0") ;
    	ofn.lpstrCustomFilter	= NULL ;
    	ofn.nMaxCustFilter		= 0 ;
    	ofn.nFilterIndex		= 0 ;
    	ofn.nMaxFile			= MAX_PATH ;
    	ofn.nMaxFileTitle		= MAX_PATH ;
    	ofn.lpstrInitialDir		= NULL ;
    	ofn.nFileOffset			= 0 ;
    	ofn.nFileExtension		= 0 ;
    	ofn.lpstrDefExt			= TEXT ("bmp") ;
    	ofn.lCustData			= 0L ;
    	ofn.lpfnHook			= NULL ;
    	ofn.lpTemplateName		= NULL ;
    	ofn.hwndOwner			= hParent ;
    	ofn.lpstrFile			= pstrFileName ;
    	ofn.lpstrFileTitle		= NULL ;
    	ofn.Flags				= OFN_OVERWRITEPROMPT ;
    	return GetSaveFileName (&ofn) ;
    }
    
    BOOL ButtonsSkalieren (HWND hwndParent, int iBreite, int iHoche){
    	MoveWindow (GetDlgItem (hwndParent, ID_BUTTON_CLOSE), 
    				iBreite - BUTTON_BREITE, iHoche - BUTTON_HOHE,
    				BUTTON_BREITE, BUTTON_HOHE, TRUE) ;
    	MoveWindow (GetDlgItem (hwndParent, ID_BUTTON_FOTO), 
    				iBreite - (2 * BUTTON_BREITE) - 5, iHoche - BUTTON_HOHE,
    				BUTTON_BREITE, BUTTON_HOHE, TRUE) ;
    	return TRUE ;
    }
    
    BOOL FensterSkalieren (HWND hParent){
    	CAPSTATUS	CS ;
    	capGetStatus (GetDlgItem (hParent, ID_VIDEO_WINDOW), &CS, sizeof (CAPSTATUS)) ;
    	SetWindowPos (GetDlgItem (hParent, ID_VIDEO_WINDOW), NULL, 0, 0, CS.uiImageWidth,
    					CS.uiImageHeight, SWP_NOZORDER | SWP_NOMOVE) ;
    	SetWindowPos (hParent, NULL, CW_USEDEFAULT, CW_USEDEFAULT, CS.uiImageWidth,
    					CS.uiImageHeight + 75, SWP_NOZORDER | SWP_NOMOVE) ;
    	return TRUE ;
    }
    

    in resource.h ist nur das menu (must du entsprechend den code aendern)



  • Wow, das hätte ich nicht gedacht das in der WinAPI zum ansprechen von Capture devices so einfach funktionien enthalten sind.



  • NA das sieht doch schonmal sehr nett aus, auch wenn ich es jetzt gerade nicht testen kann, weil ich gerade meinen Rechner formatierren musste ...

    In Was für'nem Programm hast dun das Bild dann dargestellt ??? müste ne MFC sein, ne ?

    QAso und kannst du mir die resource.h vielleicht noch geben ??? dann hat man alles schonmal lauffähig beieinander, oder kann auch ohen MEnü nen BIld sehn ???

    Schonmal vielen dank
    Romeo



  • Romeo-G schrieb:

    QAso und kannst du mir die resource.h vielleicht noch geben ??? dann hat man alles schonmal lauffähig beieinander, oder kann auch ohen MEnü nen BIld sehn ???

    du kannst natürlich auch ohne das menue das video sehen... must aber den code bisschen abspaecken (fast die gesammte WM_COMMAND muss raus, bis auf die ID_BUTTON_CLOSE & ID_BUTTON_FOTO).



  • Schick mir doch bitte nochmal dein header File zu ... ich würds halt gerne mal fertig sehn.

    Romeo-G@web.de

    Danke
    Romeo


Anmelden zum Antworten