USUÁRIO:      SENHA:        SALVAR LOGIN ?    Adicione o VBWEB na sua lista de favoritos   Fale conosco 

 

  Fórum

  Visual Basic
Voltar
Autor Assunto:  Capturar imagem no vb via webcam....
Adriano
não registrado
ENUNCIADA !
Postada em 30/01/2009 13:46 hs   
Boa tarde!

Gostaria de saber, como se faz para capturar imagem no vb, utilizando duas webcam no mesmo sistema?
Hora utiliza uma, hora utiliza outra?

obrigado....
   
rdeletric
SÃO JOSÉ DO RIO PRETO
SP - BRASIL
ENUNCIADA !
Postada em 28/08/2009 11:55 hs            
Adriano
Para fixar bem este exemplo cria uma aplicacao com um modulo no form vc cria um command button, um listbox e uma picturebox.

' no modulo:

  Public Declare Function capGetDriverDescriptionA Lib "avicap32.dll" (ByVal wDriver As Long, _
    ByVal lpszName As String, ByVal cbName As Long, ByVal lpszVer As String, _
    ByVal cbVer As Long) As Boolean

' no form:
Private Declare Function capCreateCaptureWindow Lib "avicap32.dll" Alias "capCreateCaptureWindowA" (ByVal lpszWindowName As String, ByVal dwStyle As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hwndParent As Long, ByVal nID As Long) As Long
Private Declare Function SendMessage Lib "USER32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function ReleaseCapture Lib "USER32" () As Long
Private Const WM_CAP_DRIVER_CONNECT As Long = 1034
Private Const WM_CAP_DRIVER_DISCONNECT As Long = 1035
Private Const WM_CAP_GRAB_FRAME As Long = 1084
Private Const WM_CAP_EDIT_COPY As Long = 1054
Private Const WM_CAP_DLG_VIDEOFORMAT As Long = 1065
Private Const WM_CAP_DLG_VIDEOSOURCE As Long = 1066
Private Const WM_CLOSE = &H10
Private mCapHwnd As Long
Private Type POINTAPI
X As Long
Y As Long
End Type

Dim Pt(0 To 2) As POINTAPI

Private Declare Function PlgBlt Lib "gdi32" ( _
ByVal hdcDest As Long, _
lpPoint As POINTAPI, _
ByVal hdcSrc As Long, _
ByVal nXSrc As Long, _
ByVal nYSrc As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal hbmMask As Long, _
ByVal xMask As Long, _
ByVal yMask As Long _
) As Long

Private Sub LoadCamlista()
    Dim strName As String
    Dim strVer As String
    Dim iReturn As Boolean
    Dim X As Long
    
    X = 0
    strName = Space(100)
    strVer = Space(100)
    '
    ' Pegar o nome dos dispositivos instalados
    '

    Do
        '
        '   Pegar os nomes dos drivers e versoes
        '
        iReturn = capGetDriverDescriptionA(X, strName, 100, strVer, 100)

        '
        ' inserir os nomes na lista
        '
        If iReturn Then List1.AddItem Trim$(strName)
        
        X = X + 1
    Loop Until iReturn = False
End Sub


Private Sub Command1_Click()
'desconectar se estiver conectada
SendMessage mCapHwnd, WM_CAP_DRIVER_DISCONNECT, 0, 0
' iniciar a camera selecionada
mCapHwnd = capCreateCaptureWindow(Trim$(List1.Text), 0, 0, 0, 640, 480, Me.hwnd, 0)
        SendMessage mCapHwnd, WM_CAP_DRIVER_CONNECT, 0, 0

Clipboard.Clear
SendMessage mCapHwnd, WM_CAP_GRAB_FRAME, 0, 0
SendMessage mCapHwnd, WM_CAP_EDIT_COPY, 0, 0
Picture1.Picture = Clipboard.GetData
End Sub

Private Sub Form_Load()
LoadCamlista

End Sub


' usando este exemplo vc pode capturar imagens de diversas webcams instaladas em seu PC, pode ate incrementar e capturar em varias picturebox imagens separadas ao mesmo tempo das cams. Espero ter ajudado T+


   
diego
não registrado
ENUNCIADA !
Postada em 07/01/2010 12:20 hs   
este exemplo foi muito bom...

mas eu queria ficar com a imagem aberta na camera antes da captura
   
LCRamos
Pontos: 2843
GOIANIA
GO - BRASIL
ENUNCIADA !
Postada em 08/01/2010 01:48 hs            
Coloque um Timer com Interval = 100
 
Private Sub Timer1_Timer()
    'Captura a imagem atual (COLOCADO NUM TIMER PARA IMAGEM CONTINUA)
    Clipboard.Clear
    SendMessage mCapHwnd, WM_CAP_GRAB_FRAME, 0, 0
    SendMessage mCapHwnd, WM_CAP_EDIT_COPY, 0, 0
    Picture1.Picture = Clipboard.GetData()
End Sub
 
vlu//
   
Alexandre
não registrado
ENUNCIADA !
Postada em 29/06/2011 00:04 hs   
Rapaz, vc foi o cróiz! PARABÉNS!
   
Joao
não registrado
ENUNCIADA !
Postada em 02/07/2011 15:44 hs   
Boas será  que me pode dar uma ajudinha num codigo, eu quero que a webcam grave mas na hora de rodar o projecto a imagem da webcam nao aparece.

CODIGO:
Public Class Gravar_video
    Inherits System.Windows.Forms.Form

    Const WM_CAP_START As Short = &H400S
    Const WS_CHILD As Integer = &H40000000
    Const WS_VISIBLE As Integer = &H10000000
    Const WM_CAP_DRIVER_CONNECT As Integer = WM_CAP_START + 10
    Const WM_CAP_DRIVER_DISCONNECT As Integer = WM_CAP_START + 11
    Const WM_CAP_EDIT_COPY As Integer = WM_CAP_START + 30
    Const WM_CAP_SEQUENCE = WM_CAP_START + 62
    Const WM_CAP_FILE_SAVEAS = WM_CAP_START + 23
    Const WM_CAP_SET_SCALE As Integer = WM_CAP_START + 53
    Const WM_CAP_SET_PREVIEWRATE As Integer = WM_CAP_START + 52
    Const WM_CAP_SET_PREVIEW As Integer = WM_CAP_START + 50
    Const SWP_NOMOVE As Short = &H2S
    Const SWP_NOSIZE As Short = 1
    Const SWP_NOZORDER As Short = &H4S
    Const HWND_BOTTOM As Short = 1


    Declare Function capGetDriverDescriptionA Lib "avicap32.dll" (ByVal wDriverIndex As Short, ByVal lpszName As String, ByVal cbName As Integer, ByVal lpszVer As String, ByVal cbVer As Integer) As Boolean



    Declare Function capCreateCaptureWindowA 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 Short, ByVal hWnd As Integer, ByVal nID As Integer) As Integer


    Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr

    Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer


    Declare Function DestroyWindow Lib "user32" (ByVal hndw As Integer) As Boolean


    Dim CamSource As Integer
    Dim hWnd As Integer
    Dim iDevice As Integer = 0
    Dim hHwnd As Integer



    Private Sub Gravar_video_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        cameraSource()


        Button4.Enabled = False
        Button1.Enabled = False
        Button2.Enabled = False
        Button3.Enabled = False

    End Sub

    Private Sub previewCamera(ByVal pbCtrl As PictureBox)

        Dim iHeight As Integer = PictureBox1.Height
        Dim iWidth As Integer = PictureBox1.Width
        hHwnd = capCreateCaptureWindowA(hWnd, WS_VISIBLE Or WS_CHILD, 0, 0, 640, 480, PictureBox1.Handle.ToInt32, 0)
        If SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, hHwnd, 0) Then
            SendMessage(hHwnd, WM_CAP_SET_SCALE, True, 0)
            SendMessage(hHwnd, WM_CAP_SET_PREVIEWRATE, 66, 0)
            SendMessage(hHwnd, WM_CAP_SET_PREVIEW, True, 0)
            SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, PictureBox1.Width, PictureBox1.Height, SWP_NOMOVE Or SWP_NOZORDER)
            Button3.Enabled = True
            Button1.Enabled = True
            Button2.Enabled = False
        Else
            DestroyWindow(hHwnd)
            Button3.Enabled = False
        End If



    End Sub

    Private Sub cameraSource()

        Dim strName As String = Space(100)
        Dim strVer As String = Space(100)
        Dim bReturn As Boolean
        Dim x As Integer = 0
        Do
            bReturn = capGetDriverDescriptionA(x, strName, 100, strVer, 100)
            If bReturn Then ListBox1.Items.Add(strName.Trim)
            x += 1
        Loop Until bReturn = False

    End Sub

    Private Sub stopPreviewCamera()

        SendMessage(hWnd, WM_CAP_DRIVER_DISCONNECT, CamSource, 0)
        DestroyWindow(hWnd)

    End Sub
    Private Sub ListBox1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
        Label1.Visible = False
        previewCamera(PictureBox1)
        Button1.Enabled = True
        Button4.Enabled = False
        Button2.Enabled = True
    End Sub


    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        CamSource = ListBox1.SelectedIndex


    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        stopPreviewCamera()
        Button4.Enabled = True
        Button1.Enabled = False

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Button3.Enabled = True
        Button2.Enabled = False
        SendMessage(hWnd, WM_CAP_SEQUENCE, 0, 0)

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim save As Integer
        save = MsgBox("Do you want to save your recording video", MsgBoxStyle.YesNo + MsgBoxStyle.Information, "Recording Video")
        If (save = MsgBoxResult.Yes) Then
            Dim saveName As New SaveFileDialog
            saveName.Filter = "Avi file(*.avi)|*.avi"
            If saveName.ShowDialog = Windows.Forms.DialogResult.OK Then
                SendMessage(hWnd, WM_CAP_FILE_SAVEAS, 0, saveName.FileName)
            End If
        End If
        Me.Cursor = System.Windows.Forms.Cursors.Default
        Button2.Enabled = True
        Button3.Enabled = False

    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        CamSource = ListBox1.SelectedIndex
        previewCamera(PictureBox1)
        Button4.Enabled = False
        Button1.Enabled = True

    End Sub
End Class






Se ne puder ajudar seria uma beleza.
   
Página(s): 1/2      PRÓXIMA »


Seu Nome:

Seu eMail:

ALTERAR PARA MODO HTML
Mensagem:

[:)] = 
[:P] = 
[:(] = 
[;)] = 

HTML DESLIGADO

     
 VOLTAR

  



CyberWEB Network Ltda.    © Copyright 2000-2024   -   Todos os direitos reservados.
Powered by HostingZone - A melhor hospedagem para seu site
Topo da página