hola quiero capturar imagenes de la camara web de mi notebook...
ya tengo un codigo pero usa la funcion sendmessage y hace pasar la imagenes capturadas por el clipboard. :-\
les agradeceria mucho si me alcanzasen un codigo q no use este mismo metodo.
probaste esto ?
Capturar la webCam (http://www.recursosvisualbasic.com.ar/htm/listado-api/222-capturar-webcam-con-sendmessage-capCreateCaptureWindow.htm)
:o
busque un monton no puedo creer q me haya olvidado de esa pagina :P
el primero esta incompleto y es como decia yo pero el segundo esta perfecto muchas gracias ;-)
unm seba123neo problemaa :P
cundo quiero:Private Sub Timer1_Timer()
Dim x As Integer
Dim y As Integer
For x = 0 To 480 / 10
For y = 0 To 640 / 10
Me.BackColor = GetPixel(Picture1.hdc, x, y)
Next
Next
End Sub
el color que saca getpixel es siempre el background del dc delpicture
que queres hacer?
mmm es complejo ya se como lo voi a hacer nose si se tildara mucho desp lo paso a c++...
en fin lo que quiero es poder por ejemplo encontrar un punto de tal color en la imagen y ver donde esta (x,y) y con eso pordria hacer muchas cositas :P como identificar formas...
pero bue
primero lo primero no? je
poriams decirme como puedo hacer?
proba algo asi:
Option Explicit
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function SetPixelV Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long
Private Sub Command1_Click()
Dim vEscalaForm As Integer, vPicEscala As Integer
Dim X As Long, Y As Long, vAlto As Long, vAncho As Long
vEscalaForm = Me.ScaleMode
vPicEscala = Picture1.ScaleMode
Me.ScaleMode = 3
Picture1.ScaleMode = 3
vAncho = Picture1.width
vAlto = Picture1.height
Me.Cls
For X = 0 To vAncho
For Y = 0 To vAlto
If Picture1.Point(X, Y) = 6522062 Then
SetPixelV Me.hdc, X, Y, GetPixel(Picture1.hdc, X, Y)
End If
DoEvents
Next
DoEvents
Next
Me.ScaleMode = vEscalaForm
Picture1.ScaleMode = vPicEscala
End Sub
Private Sub Form_Load()
With Picture1
.AutoSize = True
.Picture = LoadPicture(Environ("windir") & "\Santa Fe.bmp")
End With
End Sub
esto hace como un escaneo de los pixeles de la imagen y va sacando el color de ese pixel escaneado, con un simple if podes sacar los colores que te interesen y volcarlos en otro lado, por ejemplo aca se saca un determinado color y vuelca "solo ese color" en el formulario...
saludos.
jojo muy bueno :P... solo q ese codigo es el q estoy probando y no me saca el color del pixel..
probe con picture.point(x,y), getpixel recorriendo la imagen con el for anidado y no hace mas q darme en todos los pixeles un mismo color el de backgound :-\.
te dejo lo que copypaste hasta ahora :silbar:
form1
Option Explicit
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Dim temp As Long
' botón que inicia la captura
'''''''''''''''''''''''''''''''''''''''
Private Sub Command1_Click()
Dim temp As Long
hwdc = capCreateCaptureWindow("CapWindow", ws_child Or ws_visible, _
0, 0, 320, 240, Picture1.hwnd, 0)
If (hwdc <> 0) Then
temp = SendMessage(hwdc, wm_cap_driver_connect, 0, 0)
temp = SendMessage(hwdc, wm_cap_set_preview, 1, 0)
temp = SendMessage(hwdc, WM_CAP_SET_PREVIEWRATE, 30, 0)
temp = SendMessage(hwdc, WM_CAP_SET_SCALE, True, 0)
'esto hace que la imagen recibida por el dispositivo se ajuste
'al tamaño de la ventana de captura (justo lo que yo buscaba)
DoEvents
startcap = True
Else
MsgBox "No hay Camara Web", 48, "Error"
End If
End Sub
' botón para detener la captura
'''''''''''''''''''''''''''''''''''''''
Private Sub Command2_Click()
temp = DestroyWindow(hwdc)
If startcap = True Then
temp = SendMessage(hwdc, WM_CAP_DRIVER_DISCONNECT, 0&, 0&)
DoEvents
startcap = False
End If
End Sub
' Botón que abre el dialogo de formato
''''''''''''''''''''''''''''''''''''''''''''
Private Sub Command3_Click()
If startcap = True Then
temp = SendMessage(hwdc, WM_CAP_DLG_VIDEOFORMAT, 0&, 0&)
DoEvents
End If
End Sub
' Mostrar dialogo de Configuracion de la WebCam
''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Command4_Click()
Dim temp As Long
If startcap = True Then
temp = SendMessage(hwdc, WM_CAP_DLG_VIDEOCONFIG, 0&, 0&)
DoEvents
End If
End Sub
Private Sub Form_Load()
Command1.Caption = "Iniciar"
Command2.Caption = "Detener"
Command3.Caption = "Formato"
Command4.Caption = "Configurar"
Me.Caption = "Capturador de Web Cam"
End Sub
Private Sub Form_Resize()
On Error Resume Next
Move (Screen.Width - Width) \ 29, (Screen.Height - Height) \ 29
End Sub
Private Sub Form_Unload(Cancel As Integer)
temp = DestroyWindow(hwdc)
If startcap = True Then
temp = SendMessage(hwdc, WM_CAP_DRIVER_DISCONNECT, 0&, 0&)
DoEvents
startcap = False
End If
End Sub
Private Sub Timer1_Timer()
Dim x As Integer
Dim y As Integer
For x = 0 To 480 / 10
For y = 0 To 640 / 10
Me.BackColor = Picture1.Point(x, y)
Next
Next
End Sub
modulo
Option Explicit
' declaraciones Api, constantes, variables
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Const ws_child = &H40000000
Public Const ws_visible = &H10000000
Public Const WM_USER = 1024
Public Const wm_cap_driver_connect = WM_USER + 10
Public Const wm_cap_set_preview = WM_USER + 50
Public Const WM_CAP_SET_PREVIEWRATE = WM_USER + 52
Public Const WM_CAP_DRIVER_DISCONNECT = WM_USER + 11
Public Const WM_CAP_DLG_VIDEOFORMAT = WM_USER + 41
Public Const WM_CAP_DLG_VIDEOCONFIG = WM_USER + 42
Public Const WM_CAP_SET_SCALE = WM_USER + 53
'Api para crear la ventana de captura
Public 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
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Public Declare Function DestroyWindow Lib "user32" (ByVal hndw As Long) As Boolean
'Solo 16 Bits (vb2, vb3 y vb4 de 16)
'Declare Function SendMessage Lib "User" ( _
ByVal hWnd As Integer, _
ByVal wMsg As Integer, _
ByVal wParam As Integer, _
lParam As Any) As Long
'Api para crear la ventana de captura
'Declare Function capCreateCaptureWindow Lib "avicap.dll" ( _
ByVal lpszWindowName As String, _
ByVal dwStyle As Long, _
ByVal x As Integer, _
ByVal y As Integer, _
ByVal nWidth As Integer, _
ByVal nHeight As Integer, _
ByVal hwndParent As Integer, _
ByVal nID As Integer) As Long
'Declare Function DestroyWindow Lib "User" (ByVal hndw As Integer) As Integer
Public hwdc As Long
Public startcap As Integer
sabes lo que pasa, intenta hacer bitblt al picture donde tenes la captura y pintarlo en otro picture, fijate que te va a quedar negro o del color de fondo del picture de la captura. tenes que usar otro metodo, donde puedas obtener la imagen.
nose si me entendiste, pero con eso, por lo menos yo, no podia obtener la foto de la webcam, era imposible. habia que buscar otro metodo como el del clipobard o otro que habia hecho cobein (que no recuerdo si usaba el clipboard)
saludos
jeje se coco eso es lo que quiero .. si alguien conoce un metodo q funcione y nouse el clipboard ;-)
yo uso esto no es lo mejor porque guarda la imagen en un archivo y depues la lee nuevamente, pero es mejor que el portapapeles.
Private Const GET_FRAME As Long = 1084
Private Const WM_USER = &H400
Private Const WM_CAP_START = WM_USER
Private Const WM_CAP_FILE_SAVEDIB = WM_CAP_START + 25
Public Function GetFrameWebCam() As StdPicture
On Error Resume Next
Dim Nombre As String
If mCapHwnd <> 0 Then
Nombre = StrConv(App.Path & "\TMPfoto.bmp", vbFromUnicode)
SendMessage mCapHwnd, GET_FRAME, ByVal 0, ByVal 0
SendMessage mCapHwnd, WM_CAP_FILE_SAVEDIB, 0, StrPtr(Nombre)
Set GetFrameWebCam = LoadPicture(App.Path & "\TMPfoto.bmp")
Kill App.Path & "\TMPfoto.bmp"
End If
End Function
despues para la rutina de analizar la imagen utilizo esto metodo que es mucho mas rapido que usar getpixel
Option Explicit
Private Declare Function OleTranslateColor Lib "OLEPRO32.DLL" (ByVal OLE_COLOR As Long, ByVal HPALETTE As Long, pccolorref As Long) As Long
Private Declare Function GetObjectAPI Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function VarPtrArray Lib "msvbvm50.dll" Alias "VarPtr" (Ptr() As Any) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Private Type SAFEARRAYBOUND
cElements As Long
lLbound As Long
End Type
Private Type SAFEARRAY2D
cDims As Integer
fFeatures As Integer
cbElements As Long
cLocks As Long
pvData As Long
Bounds(0 To 1) As SAFEARRAYBOUND
End Type
Private Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Public Sub AnalizeCapture(ByVal hBmp As StdPicture)
Dim bDib() As Byte
Dim X As Long, Y As Long
Dim xEnd As Long
Dim SA As SAFEARRAY2D
Dim tBmp As BITMAP
Dim R As Byte, G As Byte, B As Byte
GetObjectAPI hBmp, Len(tBmp), tBmp
With SA
.cbElements = 1
.cDims = 2
.Bounds(0).lLbound = 0
.Bounds(0).cElements = tBmp.bmHeight
.Bounds(1).lLbound = 0
.Bounds(1).cElements = tBmp.bmWidthBytes
.pvData = tBmp.bmBits
End With
CopyMemory ByVal VarPtrArray(bDib), VarPtr(SA), 4
xEnd = (tBmp.bmWidth - 1) * 3
For Y = 0 To tBmp.bmHeight - 1
For X = 0 To xEnd Step 3
B = CLng(bDib(X, Y))
G = CLng(bDib(X + 1, Y))
R = CLng(bDib(X + 2, Y))
'Debug.Print r,g,b
Next
Next
CopyMemory ByVal VarPtrArray(bDib), 0&, 4
End Sub
osea tendrias que llamar todo asi
call AnalizeCapture(GetFrameWebCam)
y bueno despues vos hace el resto.
hola LeandroA voy a probar en una de esas locas casualidades va..jaja
el codigo que hice es para detectar una forma y ver como se mueve con la camara tendria q ser muy rapido.. si alguien tiene algomas directo gracias!