473,322 Members | 1,690 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

How to connect a camera to my VB.net app?

Ive got a project needing to establish a video stream from a camera
connected to a USB port.

Is there an established way to call out a camera connection dialog box and
assign the stream to the project? Something like

make video object on Form1, drag/drop borders
dim VidBox As New VideoBox
dim VidStream As New VideoStream

IF (cameraConnectionStream.DialogResultOK = true) Then

Start Thread VideoInputStream(VidStream, VidBox)

EndIF

Ive been doing some searches but havent found much yet, is there a common
way to do this??

thanks
Dec 25 '05 #1
3 29244
Hi,

What kind of camera?

Ken
----------
"Brad Rogers" <br*************@yahoo.com> wrote in message
news:JbFrf.2259$wQ3.1980@trnddc05...
Ive got a project needing to establish a video stream from a camera
connected to a USB port.

Is there an established way to call out a camera connection dialog box and
assign the stream to the project? Something like

make video object on Form1, drag/drop borders
dim VidBox As New VideoBox
dim VidStream As New VideoStream

IF (cameraConnectionStream.DialogResultOK = true) Then

Start Thread VideoInputStream(VidStream, VidBox)

EndIF

Ive been doing some searches but havent found much yet, is there a common
way to do this??

thanks

Dec 26 '05 #2
Any kind of generic camera including the cheap pc cameras.

There should be some list of all possible camera types, whether usb,
firewire or from an All-In-Wonder kind of board with video Input.

So the computer should be smart enough and load up the 100 or so possible
types and end up with a list of active camera connections and let me choose.

If I have a Kodak Easy Share sw and some generic PC camera sw, once its
connected, the sw suite should startup and launch its own program.

Im guessing that the controls for these are on the computer and could
somehow be invoked programmatically? If not then perhaps only whatever
generic nonlicense camera drivers that I could control in vb.net

Right now Id like to find a video box and wire up some code to take the
video stream from any camera

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:Oj**************@TK2MSFTNGP09.phx.gbl...
Hi,

What kind of camera?

Ken
----------
"Brad Rogers" <br*************@yahoo.com> wrote in message
news:JbFrf.2259$wQ3.1980@trnddc05...
Ive got a project needing to establish a video stream from a camera
connected to a USB port.

Is there an established way to call out a camera connection dialog box and assign the stream to the project? Something like

make video object on Form1, drag/drop borders
dim VidBox As New VideoBox
dim VidStream As New VideoStream

IF (cameraConnectionStream.DialogResultOK = true) Then

Start Thread VideoInputStream(VidStream, VidBox)

EndIF

Ive been doing some searches but havent found much yet, is there a common way to do this??

thanks


Dec 26 '05 #3
That the class I use for it.

Imports System.Drawing
Imports System.Windows.Forms
Public Class EDCaptureCam
#Region "API"
Private Declare Function capCreateCaptureWindow Lib "avicap32.dll" Alias
"capCreateCaptureWindowA" ( _
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 Integer, _
ByVal nID As Integer) As Integer
Private Declare Function capGetVideoFormatSize Lib "avicap32.dll" Alias
"capGetVideoFormatSize" (ByVal hwnd As Integer) As Long

Private Declare Function SendMessage Lib "user32.dll" Alias
"SendMessageA" ( _
ByVal hwnd As Integer, _
ByVal wMsg As Integer, _
ByVal wParam As Integer, _
ByRef lParam As Integer) As Integer

Private Structure VIDEOHDR
Dim lpData As Integer '// address of video buffer
Dim dwBufferLength As Integer '// size, in bytes, of the Data buffer
Dim dwBytesUsed As Integer '// see below
Dim dwTimeCaptured As Integer '// see below
Dim dwUser As Integer '// user-specific data
Dim dwFlags As Integer '// see below
<VBFixedArray(3)> Dim dwReserved() As Integer '// reserved; do not
use}
End Structure
Private Delegate Function CallBackDelegate(ByVal hwnd As IntPtr, ByRef
lpVHdr As VIDEOHDR) As IntPtr
Private delCallBack As CallBackDelegate = New CallBackDelegate(AddressOf
FrameCallbackTarget)
Private Declare Function SendMessage2 Lib "user32.dll" Alias
"SendMessageA" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As
IntPtr, ByVal lParam As CallBackDelegate) As IntPtr
Private Const WM_USER As Long = &H400
Private Const WM_CAP_DRIVER_CONNECT As Long = WM_USER + 10
Private Const WM_CAP_DRIVER_DISCONNECT As Long = WM_USER + 11
Private Const WM_CAP_GRAB_FRAME As Long = WM_USER + 60
Private Const WM_CAP_EDIT_COPY As Long = WM_USER + 30
Private Const WS_CHILD = &H40000000
Private Const WS_VISIBLE = &H10000000

Private Const WM_CAP_START = WM_USER

Private Const WM_CAP_SET_CALLBACK_ERROR = WM_CAP_START + 2
Private Const WM_CAP_SET_CALLBACK_STATUS = WM_CAP_START + 3
Private Const WM_CAP_SET_CALLBACK_YIELD = WM_CAP_START + 4
Private Const WM_CAP_SET_CALLBACK_FRAME = WM_CAP_START + 5
Private Const WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START + 6
Private Const WM_CAP_SET_CALLBACK_WAVESTREAM = WM_CAP_START + 7

Private Const WM_CAP_DRIVER_GET_CAPS = WM_CAP_START + 14

Private Const WM_CAP_DLG_VIDEOFORMAT = WM_CAP_START + 41
Private Const WM_CAP_DLG_VIDEOSOURCE = WM_CAP_START + 42
Private Const WM_CAP_DLG_VIDEODISPLAY = WM_CAP_START + 43

Private Const WM_CAP_SET_PREVIEW = WM_CAP_START + 50
Private Const WM_CAP_SET_OVERLAY = WM_CAP_START + 51
Private Const WM_CAP_SET_PREVIEWRATE = WM_CAP_START + 52
Private Const WM_CAP_GET_STATUS = WM_CAP_START + 54

Private Const WM_CAP_SET_CALLBACK_CAPCONTROL = WM_CAP_START + 85
Private Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal
hdc As IntPtr, ByVal x As Integer, ByVal y As Integer) As Integer
Private Declare Function GetWindowDC Lib "user32" Alias "GetWindowDC"
(ByVal hwnd As Integer) As Integer
Private Declare Function DestroyWindow Lib "user32" Alias
"DestroyWindow" (ByVal hwnd As Integer) As Integer

Private Structure POINTAPI
Dim x As Integer
Dim y As Integer
End Structure
Private Structure RECTAPI
Dim Left As Integer
Dim Top As Integer
Dim Right As Integer
Dim Bottom As Integer
End Structure
Private Declare Function FillRect Lib "user32" (ByVal hdc As IntPtr,
ByRef lpRect As RECTAPI, ByVal hBrush As IntPtr) As Integer
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As
Integer) As IntPtr

Private Structure CAPSTATUS
Dim uiImageWidth As Integer '// Width of the
image
Dim uiImageHeight As Integer '// Height of the
image
Dim fLiveWindow As Integer '// Now Previewing
video?
Dim fOverlayWindow As Integer '// Now Overlaying
video?
Dim fScale As Integer '// Scale image to
client?
Dim ptScroll As POINTAPI '// Scroll position
Dim fUsingDefaultPalette As Integer '// Using default
driver palette?
Dim fAudioHardware As Integer '// Audio hardware
present?
Dim fCapFileExists As Integer '// Does capture file
exist?
Dim dwCurrentVideoFrame As Integer '// # of video frames
cap'td
Dim dwCurrentVideoFramesDropped As Integer '// # of video frames
dropped
Dim dwCurrentWaveSamples As Integer '// # of wave samples
cap'td
Dim dwCurrentTimeElapsedMS As Integer '// Elapsed capture
duration
Dim hPalCurrent As Integer '// Current palette
in use
Dim fCapturingNow As Integer '// Capture in
progress?
Dim dwReturn As Integer '// Error value after
any operation
Dim wNumVideoAllocated As Integer '// Actual number of
video buffers
Dim wNumAudioAllocated As Integer '// Actual number of
audio buffers
End Structure
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As
Integer, _
ByRef lParam As CAPSTATUS) As Boolean

#End Region
Public Enum PurgeSurplus As Byte
Far = 0
Big = 1
End Enum

Public Event Refreshed(ByVal pBitMap As Bitmap)
'Public Event Filter(ByVal pRects As Collection)
Public HWnd As Integer
Public HDc As Integer
Private mWidth, mHeight As Integer
Private mRate As Integer
Private mbRunning As Boolean
Public Sub Dispose()
If HWnd <> 0 Then
StopCap()
SendMessage(HWnd, WM_CAP_DRIVER_DISCONNECT, 0, 0)
DestroyWindow(HWnd)
HWnd = 0
End If
End Sub
Protected Overrides Sub Finalize()
Dispose()
MyBase.Finalize()
End Sub

Public Sub New()
End Sub
Public Sub Initialize(ByVal pHwndParent As IntPtr, ByVal psDriver As
String)
Dispose()
mWidth = 640
mHeight = 480
HWnd = capCreateCaptureWindow("EDCaptureCam", _
WS_CHILD + WS_VISIBLE, 1 - mWidth,
1 - mHeight, _
mWidth, _
mHeight, _
pHwndParent.ToInt64, 0)

SendMessage(HWnd, WM_CAP_DRIVER_CONNECT, 0, 0)

'First image to get size
Dim s As CAPSTATUS
SendMessage(HWnd, WM_CAP_GET_STATUS,
System.Runtime.InteropServices.Marshal.SizeOf(s), s)
mWidth = s.uiImageWidth
mHeight = s.uiImageHeight
'If Not Clipboard.GetDataObject Is Nothing Then
' SendMessage(HWnd, WM_CAP_GRAB_FRAME, 0, 0)
' SendMessage(HWnd, WM_CAP_EDIT_COPY, 0, 0)
' With New
Bitmap(CType(Clipboard.GetDataObject.GetData(Windo ws.Forms.DataFormats.Bitma
p, True), Image))
' mWidth = .Width
' mHeight = .Height
' End With
'End If
End Sub
Public Sub ConfigFormat()
StopCap()
SendMessage(HWnd, WM_CAP_DLG_VIDEOFORMAT, 0, 0)
'First image to get size
Dim s As CAPSTATUS
SendMessage(HWnd, WM_CAP_GET_STATUS,
System.Runtime.InteropServices.Marshal.SizeOf(s), s)
mWidth = s.uiImageWidth
mHeight = s.uiImageHeight
End Sub
Public Sub ConfigDevice()
StopCap()
SendMessage(HWnd, WM_CAP_DLG_VIDEOSOURCE, 0, 0)
End Sub
Public Sub ConfigDisplay()
StopCap()
SendMessage(HWnd, WM_CAP_DLG_VIDEODISPLAY, 0, 0)
End Sub
Public Function StartCap(ByVal pRate As Integer) As Boolean
If HWnd = 0 Then
MsgBox("Not initialized")
Return False
End If
StopCap()
mRate = pRate
Try
HDc = GetWindowDC(HWnd)
SendMessage(HWnd, WM_CAP_SET_PREVIEWRATE, pRate, 0)
SendMessage(HWnd, WM_CAP_SET_PREVIEW, 1, 0)
SendMessage2(New IntPtr(HWnd), WM_CAP_SET_CALLBACK_FRAME, New
IntPtr(0), delCallBack)
mbRunning = True
Catch ex As Exception
MsgBox(ex.Message)
End Try

Return mbRunning
End Function
Public Sub StopCap()
mbRunning = False
Try
If HWnd > 0 Then
SendMessage2(New IntPtr(HWnd), WM_CAP_SET_CALLBACK_FRAME,
New IntPtr(0), Nothing)
SendMessage(HWnd, WM_CAP_SET_PREVIEW, 0, 0)
End If
mBitMapPrev = Nothing
Catch ex As Exception

End Try
End Sub
Public ReadOnly Property Width() As Integer
Get
Return mWidth
End Get
End Property
Public ReadOnly Property Height() As Integer
Get
Return mHeight
End Get
End Property
Private Function FrameCallbackTarget(ByVal hwnd As IntPtr, ByRef lpVHdr
As VIDEOHDR) As IntPtr
Dim lBitMap24 As New Bitmap(mWidth, mHeight, mWidth * 3,
Imaging.PixelFormat.Format24bppRgb, New System.IntPtr(lpVHdr.lpData))
Dim lBitMap As New Bitmap(lBitMap24) 'Convertit en 32

lBitMap.RotateFlip(RotateFlipType.RotateNoneFlipXY )
RaiseEvent Refreshed(lBitMap)

End Function
End Class
Dec 27 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: leegold2 | last post by:
I can connect in the php by using 'root' and the root pw. But when I tried adding a user ( sarah ) with GRANT I cannot connect from php. The php is simple, what am I overlooking? Again putting the...
6
by: Newbie | last post by:
I am doing some robotics projects but my main area of interest is trying out several algorithms for the processing of the stream of data coming from the video. I am wondering what type of camera...
1
by: Pola | last post by:
I am working with IIS. I am using ISAPI Extension dll, that runs on the web server. I am working on the appl that have to receive images(jpeg from video camera) in the real time. the client...
2
by: Stupid48 | last post by:
I have this Pentax Optio camera and I want to access it via vb.net. I would like to write something where I can snap the picture from the application and it automatically acquires the image from...
2
by: MDausmann | last post by:
Hi I have a camera that mounts as a folder when I plug it in and is available in explorer. I thought it would be possible to access the images on the camera using normal file operations but I...
6
by: ink | last post by:
Hi I am developing on a Symbol MC70 devices and in the past they have always realised an SDK for development including Symbol.Camera Wrapper. However it seems that for the MC35 they are not, or...
2
by: dcblair | last post by:
Hi guys and girls. I can't seem to figure this one out. Here is my setup: Speedtouch 536 DSL Modem, Nexxt 4 Port Wireless Router, CNET CIC 920W Wireless IP Camera. The camera is set up in...
1
by: nilesh3 | last post by:
Hi,Please tell me that how to connect ip camera with vb application and how capture videos in picture box?????????Thank u
3
by: Jajjo | last post by:
Hey there. I have made a new camera system and I'm having a sort-of issue. The attached image (Untitled.jpg) will be the image I refer to when I say pink, orange, green or whatever. The black...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.