none
Auflösung WebCam RRS feed

  • Frage

  • Hallo zusammen,

    ich bin nun schon seit längerem an meiner Anwendung zugange. Es funktioniert mittlerweile auch alles, doch ich bin nicht zufrieden mit der Kamera, die ich innerhalb der Anwendung anspreche. Es ist eine 3Megapixel-Kamera (demnach ca. 2016x1512 Pixel möglich) Genaue Kamerabeschreibung: "USB2.0 UVC 3.0M DocCam"... Ich habe den aktuellen treiber drauf und und und.... Wenn ich mit der vorgegebenen Software am Tablet ein Foto schieße, wird dieses mit einer Auflösung von 1600x1200 gespeichert und die Qualität ist super. Kann allerdings noch besser sein mit der Kamera. Wenn ich allerding ein Foto in meiner Anwendung schieße, wird es immer nur in 640x480 gespeichert und diese Fotos sind einfach nicht zu gebrauchen. Ich habe jetzt schon einiges gelesen. ICam-Klasse, DirecktShow blabla bla... Habe auch einiges davon ausprobiert. Aber es gab lediglich eine Änderung. das LiveBild der Cam war in super Qualität. Sobald ich speicher, wieder nur diese 640x480 und das Foto kann in den Mülleimer... Kann mir hier jemand weiter helfen? Ich arbeite an einer Wpf-Anwendung und schreibe diese in Visual Basic....

    Das Tablet ist ein Motion c5t Intel Core i5

    Mit freundlichen Grüßen

    R. K.


    Dienstag, 18. Februar 2014 14:32

Antworten

  • Ich habe es nun geschafft. Und zwar arbeite ich mit der ersten Variante. 

    Hier fehlte nur eine Zeile.....   "VideoCaptureSource.DesiredFrameSize = New Size(1600, 1200)"

    Ich erreiche nun eine Auflösung von 1600x1200 und eine Größe von 7,32 MB...

    Hier der fertige Code.....

    Imports AForge.Video
    Imports AForge.Video.DirectShow
    Imports AForge.Controls
    Imports AForge.Math
    Imports AForge.Imaging
    Imports System
    Imports System.Reflection
    Imports System.Runtime.InteropServices
    Imports System.IO
    Imports System.Drawing.Imaging
    Imports System.Text
    Imports API
    Imports System.ComponentModel
    Imports System.Drawing.Drawing2D
    Imports System.Drawing
    Imports Microsoft.VisualBasic.ControlChars
    Imports System.Windows.Forms
    
    Public Class WebCamView
        Dim VideoCaptureSource As VideoCaptureDevice
        Dim VideoDevices As New FilterInfoCollection(FilterCategory.VideoInputDevice)
    
        Private Sub WebCamView_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            VideoCaptureSource = New VideoCaptureDevice(VideoDevices(0).MonikerString)
            VideoCaptureSource.DesiredFrameSize = New Size(1600, 1200)
            VideoSourcePlayer1.VideoSource = VideoCaptureSource
            Call VideoSourcePlayer1.Start()
    
    
        End Sub
    
        Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
            VideoSourcePlayer1.SignalToStop()
            VideoSourcePlayer1.WaitForStop()
            VideoDevices = Nothing
            VideoCaptureSource = Nothing
        End Sub
    
        Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            Me.Close()
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim strFilename As String
            strFilename = "Image-" & Format(Now, "yyyy-MMM-dd, H-mm-ss-fff") & ".bmp"
    
            Dim Vorschau As New Bitmap(1600, 1200)
            Vorschau = CType(Bitmap.FromHbitmap(VideoSourcePlayer1.GetCurrentVideoFrame.GetHbitmap), Bitmap)
            Dim Output As New Bitmap(Vorschau.Width, Vorschau.Height, Vorschau.PixelFormat)
            Output.SetResolution(96, 96)
            Using g As Graphics = Graphics.FromImage(Output)
                g.DrawImage(Vorschau, 0, 0)
            End Using
            Output.Save("C:\Users\cwit\Desktop\testfotos" & "\" & strFilename, Imaging.ImageFormat.Bmp)
            Vorschau.Dispose()
            Output.Dispose()
        End Sub
    End Class

    Danke für die Hilfe!!!!!

    • Als Antwort markiert Robbo1984 Mittwoch, 19. Februar 2014 10:47
    • Tag als Antwort aufgehoben Robbo1984 Mittwoch, 19. Februar 2014 10:48
    • Als Antwort markiert Robbo1984 Mittwoch, 19. Februar 2014 10:48
    Mittwoch, 19. Februar 2014 10:47

Alle Antworten

  • Hi,

    zeig doch mal bitte den Code, mit dem Du die Kamera auslöst und vor allen Dingen auch den, mit dem Du das Bild speicherst.


    Gruß, Stefan
    Microsoft MVP - Visual Developer ASP/ASP.NET
    http://www.asp-solutions.de/ - Consulting, Development
    http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community

    Dienstag, 18. Februar 2014 14:47
    Moderator
  • Habe 2 zur Auswahl... bei beiden dasselbe Problem.....

    hier der erste....

    Imports AForge.Video
    Imports AForge.Video.DirectShow
    Imports System
    Imports System.Reflection
    Imports System.Runtime.InteropServices
    Imports System.IO
    Imports System.Drawing.Imaging
    Imports System.Text
    Imports API
    Imports System.ComponentModel
    Imports System.Drawing.Drawing2D
    Imports System.Drawing
    Imports Microsoft.VisualBasic.ControlChars
    Imports System.Windows.Forms
    
    Public Class WebCamView
        Dim VideoCaptureSource As VideoCaptureDevice
        Dim VideoDevices As New FilterInfoCollection(FilterCategory.VideoInputDevice)
    
        Private Sub WebCamView_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            VideoCaptureSource = New VideoCaptureDevice(VideoDevices(0).MonikerString)
            VideoSourcePlayer1.VideoSource = VideoCaptureSource
            Call VideoSourcePlayer1.Start()
    
    
        End Sub
    
        Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
            VideoSourcePlayer1.SignalToStop()
            VideoSourcePlayer1.WaitForStop()
            VideoDevices = Nothing
            VideoCaptureSource = Nothing
        End Sub
    
        Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            Me.Close()
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim Vorschau As New Bitmap(1600, 1200)
            Vorschau = CType(Bitmap.FromHbitmap(VideoSourcePlayer1.GetCurrentVideoFrame.GetHbitmap), Bitmap)
            Dim Output As New Bitmap(Vorschau.Width, Vorschau.Height, Vorschau.PixelFormat)
            Output.SetResolution(96, 96)
            Using g As Graphics = Graphics.FromImage(Output)
                g.DrawImage(Vorschau, 0, 0)
            End Using
            Output.Save("C:\Users\cwit\Desktop\testfotos\abcde.bmp", Imaging.ImageFormat.Bmp)
            Vorschau.Dispose()
            Output.Dispose()
        End Sub
    End Class

    hier der zweite:

    Option Explicit On
    
    Imports System
    Imports System.Reflection
    Imports System.Runtime.InteropServices
    Imports System.IO
    Imports System.Drawing.Imaging
    Imports System.Text
    
    Imports API
    Imports DirectX
    Imports DirectShowLib
    Imports DShowNET
    Imports System.ComponentModel
    Imports System.Drawing.Drawing2D
    Imports System.Drawing
    Imports Microsoft.VisualBasic.ControlChars
    Imports System.Windows.Forms
    
    Public Class Camera
    
        Private mstrBewohnernummer As String
        Private mlngWundeNr As Long
        Private mlngWundverlaufNr As Long
        Private objFotos As Fotos
    
        'Private GrabberStates As WebCamGrabber.StatusEnm() = DirectCast([Enum].GetValues(GetType(WebCamGrabber.StatusEnm)), WebCamGrabber.StatusEnm())
        Private Directory As New DirectoryInfo("..\..\Pictures")
        Private Const mstrPath As String = "C:\Users\Public\Documents\pictures\"
        Private objBitmap As Bitmap
    
        Public Sub New(ByRef Owner As Fotos, ByVal strBewohnernummer As String, ByVal lngWunde As Long, ByVal lngWundverlauf As Long)
    
            ' Dieser Aufruf ist für den Designer erforderlich.
            InitializeComponent()
    
            ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
            mstrBewohnernummer = strBewohnernummer
            mlngWundeNr = lngWunde
            mlngWundverlaufNr = lngWundverlauf
            objFotos = Owner
    
        End Sub
    
        Public videoHandle As IntPtr
    
        Private Declare Auto Function SendMessage Lib "user32" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
        Const EM_LINEFROMCHAR As Integer = &HC9
    
        Const EM_LINEINDEX As Integer = &HBB
    
        Private Declare Auto Function capCreateCaptureWindow Lib "avicap32.dll" (ByVal lpszWindowName As String, ByVal dwStyle As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hWndParent As IntPtr, ByVal nID As Integer) As IntPtr
        Private Const WM_CAP As Short = &H400S
        Private Const WS_CHILD As Integer = &H40000000
        Private Const WS_VISIBLE As Integer = &H10000000
        Private Const WM_USER As Short = &H400S
        Private Const WM_CAP_START As Short = &H400S
        Private Const WM_CAP_EDIT_COPY As Integer = (WM_CAP_START + 30)
        Private Const WM_CAP_DRIVER_CONNECT As Integer = (WM_CAP_START + 10)
        Private Const WM_CAP_SET_PREVIEWRATE As Integer = (WM_CAP_START + 52)
        Private Const WM_CAP_SET_OVERLAY As Integer = (WM_CAP_START + 51)
        Private Const WM_CAP_SET_PREVIEW As Integer = (WM_CAP_START + 50)
        Private Const WM_CAP_DRIVER_DISCONNECT As Integer = (WM_CAP_START + 11)
        Private Const WM_CAP_FILE_SAVEDIB As Long = (WM_USER + 25)
        Private Const WM_CAP_FILE_SAVEAS As Integer = (WM_CAP + 23)
    
        Public Function CreateCaptureWindow(ByRef hWndParent As IntPtr, Optional ByRef x As Integer = 0, Optional ByRef y As Integer = 0, Optional ByRef nWidth As Integer = 1600, Optional ByRef nHeight As Integer = 1200, Optional ByRef nCameraID As Integer = 0) As IntPtr
            Dim previewHandle As IntPtr
            previewHandle = capCreateCaptureWindow("Video", WS_CHILD + WS_VISIBLE, x, y, nWidth, nHeight, hWndParent, 1)
    
            SendMessage(previewHandle, WM_CAP_DRIVER_CONNECT, nCameraID, 0)
            SendMessage(previewHandle, WM_CAP_SET_PREVIEWRATE, 100, 0)
            SendMessage(previewHandle, WM_CAP_SET_OVERLAY, 1, 0)
            SendMessage(previewHandle, WM_CAP_SET_PREVIEW, 1, 0)
            Return previewHandle
        End Function
    
        Public Function CapturePicture(ByRef nCaptureHandle As IntPtr) As System.Drawing.Image
            My.Computer.Clipboard.Clear()
            SendMessage(nCaptureHandle, WM_CAP_EDIT_COPY, 0, 0)
    
            Return My.Computer.Clipboard.GetImage
        End Function
    
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            videoHandle = Me.CreateCaptureWindow(Me.PictureBox1.Handle, 0, 0, 1600, 1200)
            PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
    
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim Path As String
            Path = "C:\Users\cwit\Desktop\testfotos"
            Dim screenshot As New System.Drawing.Bitmap(640, 480)
            screenshot = CapturePicture(videoHandle)
            screenshot.Save(System.IO.Path.Combine(Path, "Test.bmp"), System.Drawing.Imaging.ImageFormat.Bmp)
    
        End Sub
    
        Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            Me.Close()
        End Sub
    
    
    End Class

    Dienstag, 18. Februar 2014 14:54
  • Hi,

    also zumindest beim zweiten Beispiel sollte klar sein, warum da letztendlich 60 * 480 rauskommt. Steht nämlich so im Code:

    Dim screenshot As New System.Drawing.Bitmap(640, 480)

    Damit wird die Grafik auch mit diesem Abmessungen erstellt.

    Beim ersten Beispiel sieht das zwar danach aus als ob die Grafik mit 1600 * 1200 Pixel erstellt werden würde aber lt. dir ist das ja wohl nicht der Fall. Wenn das stimmt, würde ich mal die Zeile mit:

    Output.SetResolution(96, 96)

    weglassen. Ich glaube zwar nicht, dass das irgendwas damit zu tun hat aber man weiß ja nie :)


    Gruß, Stefan
    Microsoft MVP - Visual Developer ASP/ASP.NET
    http://www.asp-solutions.de/ - Consulting, Development
    http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community

    Dienstag, 18. Februar 2014 16:29
    Moderator
  • Hallo,

    also, beim ersten Beispiel habe ich die Werte auch schon geändert. Dann tut sich was aber nur das Bild wird vergrößert. das heißt das schlechte bild wird angezeigt und der Rest des Bildes bleibt weiß. Das heißt von 1600x1200 Pixeln werden 640x480 angezeigt.

    Im zweiten Beispiele ändert sich folgendes. Änder ich die Werte kommt ein Bild raus, das weiter nur 640x480 groß ist aber es entsteht nur ein Ausschnitt des eigentlichen Live Bildes.

    Lasse ich die Zeile weg habe ich ein Foto in noch schlechterer Qualität.

    Ich weiß wirklich nicht weiter...

    Gruß Robert

    Mittwoch, 19. Februar 2014 07:58
  • Ich habe es nun geschafft. Und zwar arbeite ich mit der ersten Variante. 

    Hier fehlte nur eine Zeile.....   "VideoCaptureSource.DesiredFrameSize = New Size(1600, 1200)"

    Ich erreiche nun eine Auflösung von 1600x1200 und eine Größe von 7,32 MB...

    Hier der fertige Code.....

    Imports AForge.Video
    Imports AForge.Video.DirectShow
    Imports AForge.Controls
    Imports AForge.Math
    Imports AForge.Imaging
    Imports System
    Imports System.Reflection
    Imports System.Runtime.InteropServices
    Imports System.IO
    Imports System.Drawing.Imaging
    Imports System.Text
    Imports API
    Imports System.ComponentModel
    Imports System.Drawing.Drawing2D
    Imports System.Drawing
    Imports Microsoft.VisualBasic.ControlChars
    Imports System.Windows.Forms
    
    Public Class WebCamView
        Dim VideoCaptureSource As VideoCaptureDevice
        Dim VideoDevices As New FilterInfoCollection(FilterCategory.VideoInputDevice)
    
        Private Sub WebCamView_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            VideoCaptureSource = New VideoCaptureDevice(VideoDevices(0).MonikerString)
            VideoCaptureSource.DesiredFrameSize = New Size(1600, 1200)
            VideoSourcePlayer1.VideoSource = VideoCaptureSource
            Call VideoSourcePlayer1.Start()
    
    
        End Sub
    
        Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
            VideoSourcePlayer1.SignalToStop()
            VideoSourcePlayer1.WaitForStop()
            VideoDevices = Nothing
            VideoCaptureSource = Nothing
        End Sub
    
        Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            Me.Close()
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim strFilename As String
            strFilename = "Image-" & Format(Now, "yyyy-MMM-dd, H-mm-ss-fff") & ".bmp"
    
            Dim Vorschau As New Bitmap(1600, 1200)
            Vorschau = CType(Bitmap.FromHbitmap(VideoSourcePlayer1.GetCurrentVideoFrame.GetHbitmap), Bitmap)
            Dim Output As New Bitmap(Vorschau.Width, Vorschau.Height, Vorschau.PixelFormat)
            Output.SetResolution(96, 96)
            Using g As Graphics = Graphics.FromImage(Output)
                g.DrawImage(Vorschau, 0, 0)
            End Using
            Output.Save("C:\Users\cwit\Desktop\testfotos" & "\" & strFilename, Imaging.ImageFormat.Bmp)
            Vorschau.Dispose()
            Output.Dispose()
        End Sub
    End Class

    Danke für die Hilfe!!!!!

    • Als Antwort markiert Robbo1984 Mittwoch, 19. Februar 2014 10:47
    • Tag als Antwort aufgehoben Robbo1984 Mittwoch, 19. Februar 2014 10:48
    • Als Antwort markiert Robbo1984 Mittwoch, 19. Februar 2014 10:48
    Mittwoch, 19. Februar 2014 10:47