# VBForums CodeBank > CodeBank - Visual Basic .NET >  [Vb.Net] WebCam Class (ICam)

## Pino

Ok I Wrote this class to get to grips with the .NET enviroment so the coding may not be the best but it works. I've also attatached a project which uses the class its all simple enough  :Smilie:  

The class will make it easy for your app to view a webcamera set FPS etc.

Ok the class,

First 3 variables which can be changed within the class are, 



```
    Private CamFrameRate As Integer = 15
    Private OutputHeight As Integer = 240
    Private OutputWidth As Integer = 360
```

*
CamFrameRate* - Starting frame rate how much of a gap there is between frames 15ms (About 65 FPS) NOTE - You can changes the FPS through a sub this is just the initial frame rate.
*
OutputHeight/OutputWidth* - Fairly self explanitory, just sets the dimensions of output. 


VB Code:
Public iRunning As Boolean

This can be called at anytime and will return if the camera is running or not


VB Code:
Messagebox.show Mycam.Irunning

*How To Use The Class*


VB Code:
Private myCam As iCam
 Set myCam = New iCam

From here you can call a range of functions using the syntax,


VB Code:
mycam.[Function Name]

*Functions*

*initCam(ByVal parentH As Integer)*
- This is where it all starts you must call this to set the camera up first
ParentH is where we want to prievew, so if we have a pictureBox on our form, named picoutput.


VB Code:
myCam.initCam(Me.picOutput.Handle.ToInt32)

*resetCam()*
- If you need to reset the camera call this function, you most proberly wont but its here incase you do


VB Code:
MyCam.ResetCam()

*setFrameRate(ByVal iRate As Long)*
- Here you can set the frame rate by passing FPS it will then be converted into how much time between frames.


VB Code:
myCam.setFrameRate(25)
*
closeCam()*
- Allways call when closing the application, just clears things up.


VB Code:
myCam.CloseCam()
*
copyFrame(ByVal src As PictureBox, ByVal rect As RectangleF)*
- This sub returns an image of the current frame. You need to pass to it the source picture box (Where the camera image is) and then a rectangle specifying size dimensions.


VB Code:
Me.picStill.Image = myCam.copyFrame(Me.picOutput, New RectangleF(0, 0, _
                            Me.picOutput.Width, Me.picOutput.Height))

*FPS()*
- This sub returns the current FPS

VB Code:
MessageBox.Show MyCam.Fps()


As I say code may not be great but it works good, and i just hope sompeople may find it useful. I'd appriciate people not replying here but Pm'ing me with any problems since i'd like to keep this thread as clean as possible!

_Pino_

----------


## nightkids31

Is there a motion detection function included?..

----------


## Pino

> I'd appriciate people not replying here but Pm'ing me with any problems since i'd like to keep this thread as clean as possible!


No motion detection, but it can copy a frame so you just need to compare 2 frames. Please Pm me with any furthor problems  :Smilie:

----------


## Wokawidget

OK, this is my conversion, it's in 2005. The only difference I think is the Running property as 2003 doesn't support Public and Friend property with the same name.

VB Code:
Imports System.Windows.Forms
Imports System.Drawing
 Public Class WebCamera
 #Region "Api/constants"
     Private Const WS_CHILD As Integer = &H40000000
    Private Const WS_VISIBLE As Integer = &H10000000
    Private Const SWP_NOMOVE As Short = &H2S
    Private Const SWP_NOZORDER As Short = &H4S
    Private Const WM_USER As Short = &H400S
    Private Const WM_CAP_DRIVER_CONNECT As Integer = WM_USER + 10
    Private Const WM_CAP_DRIVER_DISCONNECT As Integer = WM_USER + 11
    Private Const WM_CAP_SET_VIDEOFORMAT As Integer = WM_USER + 45
    Private Const WM_CAP_SET_PREVIEW As Integer = WM_USER + 50
    Private Const WM_CAP_SET_PREVIEWRATE As Integer = WM_USER + 52
    Private Const WM_CAP_GET_FRAME As Long = 1084
    Private Const WM_CAP_COPY As Long = 1054
    Private Const WM_CAP_START As Long = WM_USER
    Private Const WM_CAP_STOP As Long = (WM_CAP_START + 68)
    Private Const WM_CAP_SEQUENCE As Long = (WM_CAP_START + 62)
    Private Const WM_CAP_SET_SEQUENCE_SETUP As Long = (WM_CAP_START + 64)
    Private Const WM_CAP_FILE_SET_CAPTURE_FILEA As Long = (WM_CAP_START + 20)
     Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Short, ByVal lParam As String) As Integer
    Private 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 hWndParent As Integer, ByVal nID As Integer) As Integer
    Private Declare Function capGetDriverDescriptionA Lib "avicap32.dll" (ByVal wDriver As Short, ByVal lpszName As String, ByVal cbName As Integer, ByVal lpszVer As String, ByVal cbVer As Integer) As Boolean
  
#End Region
     Public Event ImageChanged()
     Private _Device As String
    Private _hWnd As Integer
    Private lwndC As Integer
     Public _Running As Boolean
     Private _FramesPerSecond As Integer = 10
    Private OutputHeight As Integer = 240
    Private OutputWidth As Integer = 360
     Private _LoggingFrameSpan As Integer = 0
    Private _LoggingFilename As String = String.Empty
    Private _LoggingCount As Integer = 0
     Private WithEvents _Picture As PictureBox
     Public Property Running() As Boolean
        Get
            Return _Running
        End Get
        Friend Set(ByVal value As Boolean)
            _Running = value
        End Set
    End Property
     Public Property FramesPerSecond() As Integer
        Get
            Return _FramesPerSecond
        End Get
        Set(ByVal value As Integer)
            _FramesPerSecond = value
            ResetCamera()
        End Set
    End Property
     Public ReadOnly Property CurrentImage() As Image
        Get
            Dim CurrentPic As Image = Nothing
            If Not (_Picture Is Nothing) Then
                Return _Picture.Image
            End If
            Return CurrentPic
        End Get
    End Property
     Public Sub StartFeed()
        If Me.Running Then
            Throw New CameraAlreadyRunningException
        Else
            Try
                _Picture = New PictureBox
                _hWnd = capCreateCaptureWindowA(_Device, WS_VISIBLE Or WS_CHILD, 0, 0, OutputWidth, CShort(OutputHeight), _Picture.Handle.ToInt32, 0)
                SetupCamera()
            Catch Ex As Exception
                _Picture = Nothing
                Throw Ex
            End Try
        End If
    End Sub
     Public Sub EndFeed()
        If Me.Running Then
            SendMessage(_hWnd, WM_CAP_DRIVER_DISCONNECT, 0, CType(0, String))
            _Picture = Nothing
            Me.Running = False
        Else
            Throw New CameraNotRunningException
        End If
    End Sub
     Public Sub ResetCamera()
        If _Running Then
            EndFeed()
            Application.DoEvents()
            SetupCamera()
        Else
            Throw New CameraNotRunningException
        End If
    End Sub
     Private Sub SetupCamera()
        If SendMessage(_hWnd, WM_CAP_DRIVER_CONNECT, CType(_Device, Short), CType(0, String)) = 1 Then
             Dim CameraFrameRate As Short = CType(1000 \ _FramesPerSecond, Short)
             SendMessage(_hWnd, WM_CAP_SET_PREVIEWRATE, CameraFrameRate, CType(0, String))
            SendMessage(_hWnd, WM_CAP_SET_PREVIEW, 1, CType(0, String))
            Me.Running = True
        Else
            Me.Running = False
            Throw New CameraSetupFailedException
        End If
    End Sub
     Public Sub StartLogging(ByVal Folder As String, ByVal GroupFilename As String, ByVal FrameSpan As Integer)
        _LoggingFrameSpan = FrameSpan
         Dim Filename As String = Folder
         If Not Filename.EndsWith("\") Then
            Filename &= "\"
        End If
        Filename &= GroupFilename
        _LoggingFilename = Filename
    End Sub
     Public Sub StopLogging()
        _LoggingFrameSpan = 0
        _LoggingFilename = String.Empty
        _LoggingCount = 0
    End Sub
     Private Sub _Picture_BackgroundImageChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles _Picture.BackgroundImageChanged
        If _LoggingFrameSpan > 0 Then
            Dim LogImage As Boolean = _LoggingCount = 0 OrElse (_LoggingCount Mod _LoggingFrameSpan) = 0
            _LoggingCount += 1
            If LogImage Then
                LogCurrentImage()
            End If
        End If
        RaiseEvent ImageChanged()
    End Sub
     Private Sub LogCurrentImage()
        CurrentImage.Save(_LoggingFilename & _LoggingCount.ToString)
    End Sub
 End Class
I also created some custom exceptions:

VB Code:
Public Class CameraNotRunningException
    Inherits Exception
     Public Sub New()
        MyBase.New("Camera is not currently running")
    End Sub
End Class
 Public Class CameraSetupFailedException
    Inherits Exception
     Public Sub New()
        MyBase.New("Camera setup failed")
    End Sub
End Class
 Public Class CameraAlreadyRunningException
    Inherits Exception
     Public Sub New()
        MyBase.New("Camera is already running")
    End Sub
End Class
Now to use this code you need to do something like:

VB Code:
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
        _Camera = New WebCamLib.WebCamera
        _Camera.StartFeed()
    End Sub
     Private Sub btnEnd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnd.Click
        If _Camera.Running Then
            _Camera.EndFeed()
        End If
        _Camera = Nothing
    End Sub
     Private Sub _Camera_ImageChanged() Handles _Camera.ImageChanged
        Dim NewImage As Image = _Camera.CurrentImage
         'display image on form
     End Sub
I haven't had time to really test this, it's merely an alpha release. As you can see you can start logging at any time by using the StartLogging sub.
The logging I hope to seperate into a seperate class that deals soley with logging.

ANyways, have a play, tell me where I have gone wrong.

Woof

----------


## edid

Hi,
I changed WebCamViewer to get the real frame rate using the CallBack function and I get about 6 frames per second.
Can you really have a 25 frames/s ?

----------


## Wokawidget

What did u change? Pino's vb6 version, or my .NET conversion?

Woof

----------


## edid

I changed .Net code.

----------


## Pino

Woka!

My Code was .net! 

My code was .Net 2003 wokas is .net 2005

----------


## ini_hendry

are these code applicable to all webcam ?
i'm using logitech quickcam express

woka's code consist of WebCamLib ? 
what is it ? i got an error when debugging

----------


## lalala

If another application is using the web cam and we start our application, a selection device window apears, what can I do to not see this window? (sorry for my english, is not perfect) I been waiting for a solution for this problem for like two weeks, can someone help me?

----------


## edid

Hi,
I get the solution, after a long an hard job !
See VB.NET sources here : http://edid.free.fr/shared/webcam/index.php
Solution is in the registry database.

----------


## Wokawidget

Nice code...just looking at it now.
Although he's used the VisualBasic namespace I believe, and the code in certain places is a little left to be desired  :Frown:  Could really do with going through and tidying all the lose ends etc.

I actually cannot get it to work either...but am still working on that.

Woka

----------


## edid

I'll be happy you give me advices.

----------


## Wokawidget

Well remove the VisualBasic reference from the project.

Then slowly convert the code to "proper" .NET, ie:


VB Code:
strText = Len(strUsername)
would change to:

VB Code:
strText = strUsername.Length

Others include:


VB Code:
Err.raise(-1, "Class Name", "Err Description")
changes to:

VB Code:
Throw New Exception("Err Description")
and

VB Code:
MsgBox("Hello!")
to

VB Code:
MessageBox.Show("Hello!")

The code itself isn't the neatest. Poor error handling, poor variable naming and the code construction isn't the best.

An example of this would be:

VB Code:
Module MTools
    Public Function MREG_GetRoot(ByVal psNom As String, Optional ByVal pbReadOnly As Boolean = False) As Microsoft.Win32.RegistryKey
        Dim lRegRoot As Microsoft.Win32.RegistryKey
        Dim lsRegRoot As String
        lsRegRoot = UCase(psNom.Split("\")(0))
        Select Case UCase(lsRegRoot)
            Case "HKEY_CURRENT_USER"
                MREG_GetRoot = Microsoft.Win32.Registry.CurrentUser
            Case "HKEY_LOCAL_MACHINE"
                MREG_GetRoot = Microsoft.Win32.Registry.LocalMachine
            Case "HKEY_CLASSES_ROOT"
                MREG_GetRoot = Microsoft.Win32.Registry.ClassesRoot
            Case "HKEY_CURRENT_CONFIG"
                MREG_GetRoot = Microsoft.Win32.Registry.CurrentConfig
            Case "HKEY_USERS"
                MREG_GetRoot = Microsoft.Win32.Registry.Users
            Case Else
                Err.Raise(-1, "MREG_GetRoot", "Unknown root : " & psNom)
        End Select
        If InStr(psNom, "\") > 0 Then
            lsRegRoot = psNom.Substring(InStr(psNom, "\"))
            If lsRegRoot <> "" Then
                MREG_GetRoot = MREG_GetRoot.OpenSubKey(lsRegRoot, Not pbReadOnly)
            End If
        End If
    End Function
End Module
This should be changed to:

VB Code:
Public Class MTools
    Public Shared Function MREG_GetRoot(ByVal psNom As String, Optional ByVal pbReadOnly As Boolean = False) As Microsoft.Win32.RegistryKey
        
    Dim lsRegRoot As String = (psNom.Split("\")(0)).ToUpper()
     Dim regKey As Microsoft.Win32.RegistryKey     
     Select Case lsRegRoot
            Case "HKEY_CURRENT_USER"
                regKey = Microsoft.Win32.Registry.CurrentUser
            Case "HKEY_LOCAL_MACHINE"
                regKey = Microsoft.Win32.Registry.LocalMachine
            Case "HKEY_CLASSES_ROOT"
                regKey = Microsoft.Win32.Registry.ClassesRoot
            Case "HKEY_CURRENT_CONFIG"
                regKey = Microsoft.Win32.Registry.CurrentConfig
            Case "HKEY_USERS"
                regKey = Microsoft.Win32.Registry.Users
            Case Else
                Throw New Exception("Unknown root : " & psNom)
        End Select
         If psNom.Contains("\") Then
            lsRegRoot = psNom.Substring(psNom.IndexOf("\"))
            If lsRegRoot.Length > 0 Then
                regKey = regKey.OpenSubKey(lsRegRoot, Not pbReadOnly)
            End If
        End If
     return regKey
        
    End Function
End Class
Just daft things like that throughout the entire code, makes it hard to follow. Still can't get it working on my pc. I keep getting object not set errors.

Will take a few hours to convert completely, and then a few more to iron out all the bugs.

Hope that helps.

WOka

----------


## Matt_4

I want to save each 10 Sekonds a new picture.
In the following function i don´t know how I can pass the new picture form the cam to bmp.
The bmp.Save function is running correctly, I already tested it.


Private Sub Save()
Me.Show()
Dim myCam As New iCam
Dim i As Integer = 0
Dim numerOfPicture As String
Dim bmp As Bitmap
numerOfPicture = i.ToString
bmp = '**********this line is the problem**********
bmp.Save("C:\Pictures\Picture" + numerOfPicture + ".bmp")
i = i + 1
Me.Close()
End Sub



I tried to use the origin code by change it a little, but I got a big Problem.
The following changes work correctly if I click the button every 10 Sekonds.
Now the problem: If I let the Button click by software, in the pictureBox is no longer the picture but a part of the 
desktop which is seen right behind the pictureBox.

Private myCam As iCam

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.picOutput.SizeMode = PictureBoxSizeMode.StretchImage
myCam = New iCam
myCam.initCam(Me.picOutput.Handle.ToInt32)
End Sub

Private Sub cmdViewStill_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdViewStill.Click
If myCam.iRunning Then
Dim a As FrmImage
a = New FrmImage

a.picImage.Image = myCam.copyFrame(Me.picOutput, New RectangleF(0, 0, _
Me.picOutput.Width, Me.picOutput.Height))
Me.Show()
Else
MessageBox.Show("Camera Is Not Running!")
End If
End Sub

Now I want to save the picture:

Private Sub Save()
Me.Show()
Dim myCam As New iCam
Dim i As Integer = 0
Dim numerOfPicture As String
Dim bmp As Bitmap
numerOfPicture = i.ToString
bmp = CType(picImage.Image, Bitmap)
bmp.Save("C:\Pictures\Picture" + numerOfPicture + ".bmp")
i = i + 1
Me.Close()
End Sub

and this works If I click the button who is starting Save(), but If I let the Button click by software,
in the pictureBox is no longer the picture but a part of the 
desktop which is seen right behind the pictureBox.
So I thought don´t use a button but a funtion wich starts without a button to take a picture every 10 Sekonds.
-> The same result:In the pictureBox is the desktop which is seen right behind the pictureBox.
-> And in the file it is also.

Could somebody show me a line of code with wich I can save the taken picture of the cam directly in a bitmap.
Then I could simply save the bitmap.

That means to replace these 2 lines:

a.picImage.Image = myCam.copyFrame(Me.picOutput, New RectangleF(0, 0, _
Me.picOutput.Width, Me.picOutput.Height))

in something like:

Dim bmp as Bitmap
bmp = '*****here should the cam pass one picture to bmp so I can save bmp direktly*****

I would be obliged if somebody could help me.

I use WinXP and
VisualBasic Express

----------


## jinx101

I downloaded the original source for VS2003 Framework 1.1 and it appeared to work fine.  I wanted to use the 2005 Framework 2.0 copy that Wokawidget posted though.  I put it into VS2005 and it compiled without errors.  I can start and stop the webcam (the green light goes on and off) however the ImageChanged event never seems to fire even when the cam is on (I put logging in that event in the class to verify it... I also kept tabs on the _Picture variable and it doesn't appear to have anything, like the system isn't returning it).

I know the class is talking to the web cam somewhat because it will turn it on and off, but I can't see to pull the images from it.  Thoughts?  

Here's the example code from my form that's trying to use the class:


vb Code:
Private WithEvents _Camera As WebCamera
     Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        _Camera = New WebCamera
        _Camera.StartFeed()
    End Sub
     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        _Camera = New WebCamera
        _Camera.StartFeed()
    End Sub
     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If _Camera.Running Then
            _Camera.EndFeed()
        End If
    End Sub
     Private Sub _Camera_ImageChanged() Handles _Camera.ImageChanged
        Me.Text = "Changed at " & Now().ToString
        Dim NewImage As Image = _Camera.CurrentImage
        PictureBox1.Image = NewImage
        NewImage.Dispose()
        NewImage = Nothing
    End Sub

----------


## gonkowonko

thanks for this code its ace.

One little problem i have found, im using VS 2008 and have managed to get an application to work on my laptop which opens up a 348x270 capture window, enables to user to press "Take Photo" and save. Perfect yeah...

Well now ive tried transferring the application it to another PC i only get half of the picture box showing (capture frame) and the other half is the form behind coming through, as if the window isnt redrawing corrrectly  :Frown:  so you dont get a proper image being viewed let alone saved? Does that make sense?

Any suggestions?

----------


## yz4now

Hello,

This code is amazing  :Smilie: 
I as wondering if there would be a way to add effects to the webcam stream. Like black and white, filters etc.

Let me know.

Thanks, Adam.

----------


## Pino

I'm not too sure if you can add any affects to the stream. I'll have a look into it if I get a few minutes!

 :Thumb:

----------


## Didius

Thanks for the great code.

I am trying to modify the code so that I can capture the image not just with a button, but also when the user presses the button on the webcam. 

Any suggestions?

Thanks,
Didius

----------


## Pino

Didius, 

Thanks! As for your question, I'm not too sure that would involve looking at the hardware you are using.

Thanks

----------


## makko

Ok ... i managed to capture images from webcam ... but I need to send those images to another computer ... like an livestream ... how can I do that ?

----------


## jaguar22

I took the time to register for the forum just so that I could properly thank pino for this code. it was precisely what I need for a project I'm working on. this was after trying several others that didn't work or didn't work well. thanks!

----------


## Pino

> I took the time to register for the forum just so that I could properly thank pino for this code. it was precisely what I need for a project I'm working on. this was after trying several others that didn't work or didn't work well. thanks!


Thats really great to hear! 

Good luck with the project!

Pino

----------


## makko

well jaguar ...

I think too the pino's code is great ... but too advanced for what I need right now ... 

a great code that works can be found at http://www.webtropy.com/articles/art7-2.asp ... it's easy to use too

pino thanks for the code

----------


## Pino

> well jaguar ...
> 
> I think too the pino's code is great ... but too advanced for what I need right now ... 
> 
> a great code that works can be found at http://www.webtropy.com/articles/art7-2.asp ... it's easy to use too
> 
> pino thanks for the code


Too advanced? The code above uses the exact same method. My class just provides a simple interface.

Pino

----------


## OuTa-SyNc

great webcam code, by far the best way of doing it in VB, I've added motion detection to it, pic below, this is my first attempt at motion detection so the code maybe very grude.



I will post the source later when I've cleaned it up a little.

I thought i would add the motion detection with a visual twist, you can see what motion has been picked up by the green indicator.  I also added track bars which control how sensitive it is, and also the object size it responds to.  Might be handy for a security thing, you can set the size to only go off to people and not a cat for example.

Kind Regards,
OuTa-SyNc

----------


## Mark Lloyd Duatin

> great webcam code, by far the best way of doing it in VB, I've added motion detection to it, pic below, this is my first attempt at motion detection so the code maybe very grude.
> 
> 
> 
> I will post the source later when I've cleaned it up a little.
> 
> I thought i would add the motion detection with a visual twist, you can see what motion has been picked up by the green indicator.  I also added track bars which control how sensitive it is, and also the object size it responds to.  Might be handy for a security thing, you can set the size to only go off to people and not a cat for example.
> 
> Kind Regards,
> OuTa-SyNc








Sir i was Looking for this type of application can you please post a draft here or email me perhaps. I need this for my thesis im gonna add  sms features to it and post it here. please please please  :Big Grin: .....

----------


## OuTa-SyNc

here you go...full source iCam with Motion detection

ignore the commented out lines, these are for a project I'm working on.  Like I said the method I used may be grude but it works...and at the same speed as the webcam.  It uses 2 timers, each is set with an interval the same as the frame rate (i.e. if the cam is set to 30 FPS then the timer interval would be 33) but I changed it to 30.

If anyone can improve it please post back, as I would like an optimised version myself  :Smilie:

----------


## Mark Lloyd Duatin

removed for privacy purposes

----------


## OuTa-SyNc

does anyone know how I can hide the cam picturebox and display only the output produced from the motion detection?

If I set the cam picturebox to visible = false nothing works because the camera output is not being produced, basically I want to get the frames from the camera, add my motion detection method to it and display the results in the output picturebox only.  I've tried rendering over the image set in the cam picturebox but with no luck.

Not sure if anyone has noticed but if you place anything in front of the picturebox with the cam running then it is treader as output produced from the cam???

Thanks in advance

----------


## Mark Lloyd Duatin

hey since you helped me haha im helping you too here i solved the problem and added a feature where you can select the device where the program will get the image. 


do re upload your webcam motion detection using my code here. i used copying from the clipboard and retrieving it.. 

if anyone can optimize this please do so thnx

----------


## jhnoh

Hello,
a simply great class. 
How can I get a second camera? I'm testing it now with two cameras.  :Confused:  

Thanks.

----------


## alikh

hi every body this class is a develop on icam
and can capture image with no problem  even when the window is minimized
no problem .with time adding .auto capturing and ...... :Cool:

----------


## Holm76

Hi guys

If I was to use this class without using a picturebox to show the webcam feed all the time but rather initiate the camera and then when buttons are clicked grab a picture then how would I go about doing that?

I can only initiate the camera with a handle to a picturebox as of now

----------


## Holm76

Ok so I found a somewhat workable solution to my own problem.

As wrote if I placed the picturebox outside the form the GrabIt picture is black also if I make the picturebox 0,0 in size the picture would be black.

So what I did was to leave the picturebox at 1,1 in size and place it somewhere on the main form where it is unnoticed and I can now GrabIt and get perfect webcam shot when buttons are clicked.

----------


## dudemon

> here you go...full source iCam with Motion detection
> 
> ignore the commented out lines, these are for a project I'm working on.  Like I said the method I used may be grude but it works...and at the same speed as the webcam.  It uses 2 timers, each is set with an interval the same as the frame rate (i.e. if the cam is set to 30 FPS then the timer interval would be 33) but I changed it to 30.
> 
> If anyone can improve it please post back, as I would like an optimised version myself


Can someone please re-attach the BBIC.zip?  The website is no-longer.  :Frown:  

Thanks,

D.M

----------


## OuTa-SyNc

I didn't realise that I deleted from my server

iCam with Motion detection

----------


## jamesnguyen_anewtech

This is simpe webcam code. You create simple user interface with startrecord, stoprecord, and stopcam, one listbox contain webcam device. 
change name of button according to name in sourcecode and you can use this code to record webcam

vb.net Code:
Public Class Form1
    Const WM_CAP_START = &H400S
    Const WS_CHILD = &H40000000
    Const WS_VISIBLE = &H10000000
     Const WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10
    Const WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11
    Const WM_CAP_EDIT_COPY = 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 = WM_CAP_START + 53
    Const WM_CAP_SET_PREVIEWRATE = WM_CAP_START + 52
    Const WM_CAP_SET_PREVIEW = WM_CAP_START + 50
     Const SWP_NOMOVE = &H2S
    Const SWP_NOSIZE = 1
    Const SWP_NOZORDER = &H4S
    Const HWND_BOTTOM = 1
    Dim count As Integer = 0
    '--The capGetDriverDescription function retrieves the version 
    ' description of the capture driver--
    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
     '--The capCreateCaptureWindow function creates a capture window--
    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
     '--This function sends the specified message to a window or windows--
    Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
       (ByVal hwnd As Integer, ByVal Msg As Integer, _
        ByVal wParam As Integer, _
       <MarshalAs(UnmanagedType.AsAny)> ByVal lParam As Object) As Integer
     '--Sets the position of the window relative to the screen buffer--
    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
     '--This function destroys the specified window--
    Declare Function DestroyWindow Lib "user32" _
       (ByVal hndw As Integer) As Boolean
     '---used to identify the video source---
    Dim VideoSource As Integer
    '---used as a window handle---
    Dim hWnd As Integer
     Private Sub Form1_Load( _
       ByVal sender As System.Object, _
       ByVal e As System.EventArgs) Handles MyBase.Load
        btnStartRecording.Enabled = True
        btnStopRecording.Enabled = False
        '---list all the video sources---
        ListVideoSources()
        VideoSource = 0
        PreviewVideo(pbctrl)
        
    End Sub
    Private Sub ListVideoSources()
        Dim DriverName As String = Space(80)
        Dim DriverVersion As String = Space(80)
        For i As Integer = 0 To 9
            If capGetDriverDescriptionA(i, DriverName, 80, _
               DriverVersion, 80) Then
                lstVideoSources.Items.Add(DriverName.Trim)
            End If
        Next
    End Sub
    '---list all the video sources---
    Private Sub lstVideoSources_SelectedIndexChanged( _
       ByVal sender As System.Object, ByVal e As System.EventArgs) _
       Handles lstVideoSources.SelectedIndexChanged
        '---check which video source is selected---
        VideoSource = lstVideoSources.SelectedIndex
        '---preview the selected video source
        PreviewVideo(pbCtrl)
    End Sub
    '---preview the selected video source---
    Private Sub PreviewVideo(ByVal pbCtrl As PictureBox)
        hWnd = capCreateCaptureWindowA(VideoSource, _
            WS_VISIBLE Or WS_CHILD, 0, 0, 0, _
            0, pbCtrl.Handle.ToInt32, 0)
         If SendMessage( _
           hWnd, WM_CAP_DRIVER_CONNECT, _
           VideoSource, 0) Then
             '---set the preview scale---
            SendMessage(hWnd, WM_CAP_SET_SCALE, True, 0)
            '---set the preview rate (ms)---
            SendMessage(hWnd, WM_CAP_SET_PREVIEWRATE, 30, 0)
            '---start previewing the image---
            SendMessage(hWnd, WM_CAP_SET_PREVIEW, True, 0)
            '---resize window to fit in PictureBox control---
            SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, _
               pbCtrl.Width, pbCtrl.Height, _
               SWP_NOMOVE Or SWP_NOZORDER)
        Else
            '--error connecting to video source---
            DestroyWindow(hWnd)
        End If
    End Sub
    '---stop the preview window---
    Private Sub btnStopCamera_Click( _
       ByVal sender As System.Object, _
       ByVal e As System.EventArgs) _
       Handles btnStopCamera.Click
        StopPreviewWindow()
    End Sub
    '--disconnect from video source---
    Private Sub StopPreviewWindow()
        SendMessage(hWnd, WM_CAP_DRIVER_DISCONNECT, VideoSource, 0)
        DestroyWindow(hWnd)
    End Sub
    '---Start recording the video---
    Private Sub btnStartRecording_Click( _
       ByVal sender As System.Object, _
       ByVal e As System.EventArgs) _
       Handles btnStartRecording.Click
        btnStartRecording.Enabled = False
        btnStopRecording.Enabled = True
        '---start recording---
        SendMessage(hWnd, WM_CAP_SEQUENCE, 0, 0)
    End Sub
    '---stop recording and save it on file---
    Private Sub btnStopRecording_Click( _
       ByVal sender As System.Object, _
       ByVal e As System.EventArgs) _
       Handles btnStopRecording.Click
        btnStartRecording.Enabled = True
        btnStopRecording.Enabled = False
        '---save the recording to file---
        SendMessage(hWnd, WM_CAP_FILE_SAVEAS, 0, "C:\Users\Public\Videos\Sample Videos\recordedvideo.avi")
     End Sub
End Class

----------


## ^Clark^

very nice class...

however i think this will be great if there is a record functionality. :Wink:

----------


## Pino

> very nice class...
> 
> however i think this will be great if there is a record functionality.


Watch this space.

----------


## ^Clark^

ok ill watch for it... you're fast to reply huh...

----------


## Pino

Email Notifications FTW  :Smilie: 

I'm working on a C# Class for this now, since my skill base has swifted away from VB. However the DLL release will be find for using with VB

----------


## ^Clark^

wow that will be great... now i see you shifted to c# :big yellow:

----------


## miitiicoo

Hi everyone.. finally i founded someone that is working on my problem..
unfortunely i'm not a good developer and i'm trying to solve my big trouble..
I need to create something "fun" for the kids in an hospitality centre.. they need to register themself (i created a small VB6 application with Ms Access) but we need also a picture of them. I can create a button that call an external exe (created with modern system ...) and this program create a fun picture (with png background, like Happy Birthday, Baloons..etc etc)
For this reason i'm trying to help this friend of mine with the creation of this simple software..
if anyone can help me, i will be appreciate very much.. it's for a good thing.
I downloaded the EDID software.. and i'm able to see webcam in the form, but i cannot customize the effects..
i attached here with the post the picture of my "desire"..
thank you very much everybody!

----------


## miitiicoo

nobody can help me with any advices?
 :Frown:

----------


## Pino

I'd post that question in the MainForum since its not really to do with the webcam feed. 

As for the re-write I'm working on, I'm likly going to drop it. The recording of video is effectivly useless without compression (1 sec = 1Meg). The support for adjusting FPS is not very good. 

Suppose I could re-write it using DirectShow but documentation is limited to C++  :Frown:

----------


## tripes

hi pino i have used your code the WebCamVewer and i have a problem... it starts me camera but all i see is black, even the snapshots are black! i dont know what to do, pls help.. :Frown:

----------


## Pino

> hi pino i have used your code the WebCamVewer and i have a problem... it starts me camera but all i see is black, even the snapshots are black! i dont know what to do, pls help..


Which camera do you have?

----------


## tripes

i dont remember the model of the camera, but is a built-on Webcam on my hp pavilion dv9000 labtop...

----------


## Pino

> i dont remember the model of the camera, but is a built-on Webcam on my hp pavilion dv9000 labtop...


Can any other webcam applications use your camera?

----------


## tripes

if i understand well you are asking me if another application is using the camera the same time... there is no other app that uses the webcam that time

----------


## Pino

Have you ever used your webcam with any other application?

----------


## tripes

yes i have with skype and msn

----------


## jaimetalmaster

Exactly same problem as tripes...and yup, I've used my webcam before, in fact, I use it daily.

Hope you can help!

----------


## tripes

pino i forgot to tell you that i used my cam with the app "Cyberlink YouCam" as with msn and skype...

----------


## alex.xz

i have the same problem!!! please help if you can  :Frown:

----------


## Damiano

I found the code very very usefull. However I have almost the same problem as the other guys, my ViewFinder is black, BUT the capture works fine. I'm using the built in camera of an HP pavilion dv2000 (Manufacturer: Microsoft)
Any idea??

----------


## Fiziks07

Here is the icam class used in a motion detector. 

I was too lazy to rename some of the labels and such but its not that bad i promise.

all the main guts of the program are commented and named.
I just left the unimportant stuff default.


Attachment 71112

----------


## Pino

Invalid Link

----------


## namrekka

I want to make a note regarding "motion detection".

Comparing 2 images pixel by pixel will not guarantee to detect a motion. Also changing light etc will cause a detection. Its better to divide the image in several areas. In each area the avarage is taken. Then the ratios between the areas can be used as detection. Averaging of several areas can be time consuming. However certain algoritms like "integral image" can be used and are fast.

----------


## Fiziks07

namrekka

thank you for the input. I didn't think to go about it in such a way but the more i think about it the more that makes sense. I've already started working on it. Thanks  :Smilie:

----------


## stoui333

Hey Pino that`s a great code!

I was wondering if you could help me a little bit with your class!

I don`t understand the following:

1) these are used inside the copyFrame function what are they exactly?

Dim HDC1 As IntPtr = srcPic.GetHdc
Dim HDC2 As IntPtr = srcMem.GetHdc

BitBlt(HDC2, 0, 0, CInt(rect.Width), _
CInt(rect.Height), HDC1, CInt(rect.X), CInt(rect.Y), 13369376)

copyFrame = CType(srcBmp.Clone(), Bitmap)

srcPic.ReleaseHdc(HDC1)
srcMem.ReleaseHdc(HDC2)
srcPic.Dispose()
srcMem.Dispose()

2) and this bitmapdirect class what does it do exactly?

Public Class BitmapDirect



i`m trying to implement your code for a motion detection one!

Thanks in advance!

----------


## red00dragon

Hi

Do everyone know a possible way to catch de button press event form the button of my webcam? My app should recognize when someone presses the button of my webcam.

I'm happy about every information that solves my problem  :Smilie:

----------


## Pino

> Hi
> 
> Do everyone know a possible way to catch de button press event form the button of my webcam? My app should recognize when someone presses the button of my webcam.
> 
> I'm happy about every information that solves my problem


Using the method above, i dont think is possible. You will need to interact directly with the camera and to do that you will need to use the driver provided.

Pino

----------


## Addy

This is a great thread.

I would like to know, do I need one class for each web cam.  for example i want to put this on a passworded website, but i need the ability for 6 web cams.  Is this possible with the code on here ?

Thanks.

Addy

----------


## wbphelps

I have been experimenting with this and find there is a significant problem. The technique used to capture frames from the camera video is actually capturing the current displayed screen image. As such, it captures whatever is displayed on the screen, which includes any other windows that might be on top of the one with the camera image.

It seemed like a great idea until I started working on motion detection and started seeing unexpected motion when other windows were active.

It would seem that the only reliable way to capture an image from the camera might be sending the WM_CAP_EDIT_COPY message after all...

William

----------


## rdollc

Hello everyone.
I have downloaded & compiled ICam and have it working on my local machine. Now I am needing to be able to broadcast the video to a website. Can anyone help me in accomplishing this. Also, will this handle audio also?

----------


## illskills

> Is there a motion detection function included?..


this is pretty easy to implement

----------


## illskills

> Hello everyone.
> I have downloaded & compiled ICam and have it working on my local machine. Now I am needing to be able to broadcast the video to a website. Can anyone help me in accomplishing this. Also, will this handle audio also?


search for http file streaming ;0) dont know how to stream audio but pictures should be pretty straight forward

and does this control support multiple cameras ?

----------


## Wokawidget

Motion Detection:

I wrote some motion detection code to catch the dog dumping in my front garden  :Smilie: 

Attached is the source project for this.

Run it. Click button 1 to start camera.
The slider adjusts the sensitivity of the motion detection.

The SecurityCam::GetMotion method is responsible for detecting motion.
This can be coded to look for specific colors.
ie. I set it up so it only detected white moving objects, as I knew the dog was whitish and not blue  :Smilie: 

Hope this helps.
#
Woka

----------


## SirPereira

Wokawidget your last source works fine... everything, starts the cam and everything, but don't show any image..

----------


## SirPereira

Anyone?

----------


## Wokawidget

Any errors?
Works fine on my test pcs.
Have you got the shutter/cover open on your web cam?

Woka

----------


## SirPereira

> Any errors?
> Works fine on my test pcs.
> Have you got the shutter/cover open on your web cam?
> 
> Woka


No errors, everything in my cam is ok (because I can open it in whatever other place - including MSN).

Btw, do you know some code like this for vb6?

----------


## jack_landers

thx for the code Pino.....it was a great help for me
btw... I have one problem here.... which is why after I have complied the code...
the webcam image that I have capture is not at the center meaning I was in front of the webcam already.. and the webcam image should have shown an image of myself in the center rite, but the result is the image of myself is on the right hand side only.........

----------


## SirPereira

jack, could you get image from the webcam?

----------


## jack_landers

> jack, could you get image from the webcam?



can....
actually my problem is the size of the picture box....
everything is working fine now.....

but I am having problems using the luxand FaceSDK.....which is so far no one help me........T_T

----------


## Hamdycam

Thank you!!

 This usefulness works perfectly.

 But I have a doubt: Since it is possible to conceal the floating picture that goes out " origin of video "?? I need to conceal it. Thank you

----------


## blaczk

i need help..
this progrma hung up line "SendMessage(hWnd, WM_CAP_DRIVER_DISCONNECT, CamSource, 0)"

this my coding,,,


vb.net Code:
Imports System
Imports System.IO
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
 Public Class Form1
    Inherits System.Windows.Forms.Form
    Const WM_CAP_START = &H400S
    Const WS_CHILD = &H40000000
    Const WS_VISIBLE = &H10000000
     Const WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10
    Const WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 12
    Const WM_CAP_EDIT_COPY = 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 = WM_CAP_START + 53
    Const WM_CAP_SET_PREVIEWRATE = WM_CAP_START + 52
    Const WM_CAP_SET_PREVIEW = WM_CAP_START + 50
     Const SWP_NOMOVE = &H2S
    Const SWP_NOSIZE = 1
    Const SWP_NOZORDER = &H4S
    Const HWND_BOTTOM = 1
    '--The capGetDriverDescription function retrieves the version 
    ' description of the capture driver--
    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
     '--The capCreateCaptureWindow function creates a capture window--
    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
     '--This function sends the specified message to a window or windows--
    Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
       (ByVal hwnd As Integer, ByVal Msg As Integer, _
        ByVal wParam As Integer, _
       <MarshalAs(UnmanagedType.AsAny)> ByVal lParam As Object) As Integer
     '--Sets the position of the window relative to the screen buffer--
    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
     '--This function destroys the specified window--
    Declare Function DestroyWindow Lib "user32" _
       (ByVal hndw As Integer) As Boolean
     '---used to identify the video source---
    Dim CamSource As Long
    '---used as a window handle---
    Dim hWnd As Integer
    Private Sub cameraSource()
        Dim DriverName As String = Space(80)
        Dim DriverVersion As String = Space(80)
        For i As Integer = 0 To 9
            If capGetDriverDescriptionA(i, DriverName, 80, _
               DriverVersion, 80) Then
                ListBox1.Items.Add(DriverName.Trim)
            End If
        Next
    End Sub
    Private Sub previewCamera(ByVal pbCtrl As PictureBox)
        hWnd = capCreateCaptureWindowA(CamSource, _
        WS_VISIBLE Or WS_CHILD, 0, 0, 0, _
        0, pbCtrl.Handle.ToInt32, 0)
        If SendMessage( _
           hWnd, WM_CAP_DRIVER_CONNECT, _
           CamSource, 0) Then
            '---set the preview scale---
            SendMessage(hWnd, WM_CAP_SET_SCALE, True, 0)
            '---set the preview rate (ms)---
            SendMessage(hWnd, WM_CAP_SET_PREVIEWRATE, 30, 0)
            '---start previewing the image---
            SendMessage(hWnd, WM_CAP_SET_PREVIEW, True, 0)
            '---resize window to fit in PictureBox control---
            SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, _
               pbCtrl.Width, pbCtrl.Height, _
               SWP_NOMOVE Or SWP_NOZORDER)
        Else
            '--error connecting to video source---
            DestroyWindow(hWnd)
        End If
    End Sub
    Private Sub stopPreviewCamera()
        SendMessage(hWnd, WM_CAP_DRIVER_DISCONNECT, CamSource, 0)
        DestroyWindow(hWnd)
    End Sub
     Private Sub Form1_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 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
        '---preview the selected video source
    End Sub
    'stop preview
    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
    ' recording
    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
    ' stop recording and ask to save video
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        SendMessage(hWnd, WM_CAP_FILE_SAVEAS, 0, "C:\RecordedVideo.avi")
        Button2.Enabled = True
        Button3.Enabled = False
    End Sub
    ' preview
    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

i need solution please help me,,

----------


## CanaanP

I have previewed the badgersecuritycam project listed in this thread... I am wondering if there is a way to grab the rgb values of detected moving objects? For example, if I wanted to look specifically for something yellow, or red. Is that possible? If so can someone recommend how to implement it?

----------


## etilcool

hi. i am having problem to create a gui to produce a webcam video. can anyone help of got sample code to generate this. and did anyone know or interrelate to do face detection. anybody did this before.....plz help me

----------


## [gja]

Hello Pino,

Can you guide me if what to changed in your code so that it can start 2 camera?because i need to capture image from both camera simultaneously in 1 button hit..

hope u can help me.thanks

----------


## FriendOfGhost

dear friends,

Imagine a conveyor band with boxed moving over it. they pass in front of the camera one by one. I need to get picture each of boxes but I don't know how. how can I decide when I get the picture ? I cannot use conveyor speed and timing because boxes are in different shapes and the space among them are not even. if camera is 30fps and a box passes by in front of camera in 3 seconds, it means there are 3x30=90 pictures. of course I should select the one that centers the box in the camera but I don't know how. also moving speed is not constant. I need an algorithm that says "okay there's a box in front of me, lets get the picture and save it".

can anyone obtain me information or sample that gets pictures of boxes while they are passing by in front of camera ?

 in other words, you'll wave your hand at the camera and on each pass it will get ONE picture of your hand, roughly at the middle of camera.

----------


## BlindSniper

> dear friends,
> 
> Imagine a conveyor band with boxed moving over it. they pass in front of the camera one by one. I need to get picture each of boxes but I don't know how. how can I decide when I get the picture ? I cannot use conveyor speed and timing because boxes are in different shapes and the space among them are not even. if camera is 30fps and a box passes by in front of camera in 3 seconds, it means there are 3x30=90 pictures. of course I should select the one that centers the box in the camera but I don't know how. also moving speed is not constant. I need an algorithm that says "okay there's a box in front of me, lets get the picture and save it".
> 
> can anyone obtain me information or sample that gets pictures of boxes while they are passing by in front of camera ?
> 
>  in other words, you'll wave your hand at the camera and on each pass it will get ONE picture of your hand, roughly at the middle of camera.


You could code it to check if the colour of the picture in the middle is different from what the conveyor usually is(assuming the conveyor is more or less the same colour everywhere.)

----------


## Jigabyte

Hi,

Exellent code. I have a problem tho. I am testing it on a tablet which has two cameras. I see the WDM Image Capture but when I run it it prompts for a capture source which show front and rear camera but when I select one nothing happens.

Help help plz.

Jiggy!

----------


## fiedzback

Hello pino and everyone. I have a problem with my project that using class cam. I want my application to recording video. It's Work! But freeze when start recording video until i hit a key or hit mouse. Timer wont run when recording video. any solution? Help me..
sorry my bad english

----------


## Rixterz

Please don't doubt yourself! This code is awesome and has given me the power to complete my project. I'd recommend it to anyone!
Thanks for posting!  :Smilie:

----------


## Armstrong

> thnx so much i will be working with this.. well as i can see you used the lockbits. i saw that in c# and add me up in YM macrulz2004.. haha.. il add saving of image when motion detected plus sms sending when motion detected plus email.. i did it back in vb6,0.. thanx so much dont forget to add me. we can work with this together haha thnx


the website is not working, I can not download the file. Can any good people re-attach the detection file? Thanks

----------


## computerschrat

I have a  problem using ICam with two cameras. 
The cams are declares as

    Private Cam1 As iCam
    Private Cam2 As iCam

then I call the initialization

        Cam1.initCam(Me.pbCam1.Handle.ToInt32)
        Cam2.initCam(Me.pbCam2.Handle.ToInt32)

where pbCam1 and pbCam2 are the two pictureboxes for the preview window.

Starting the device selection dialog for the first camera opens and everything works fine for the first cam.
Initialization of the second cam most times causes an "Error setting up camera"
I then changed my code to start the initialization of both cameras separately with a click to a button. When I wait several seconds after initialization of the first cam the second one comes up with its own device select dialog and then it works. When I run in debug mode and run step by step through the code of initCam I never run into an error.
Does anybody know this problem and a solution for it?

Thanks in advance
computerschrat

----------


## Rixterz

computerschrat,

As iCam is the name of the class, you cannot initiate 2 instances of it. 
Therefore, i suggest that you use 
Application.Run(New iCam()) # then, in each iCam, do iCam.initcam(~~~)
I'm really not sure if this works but it sounds good enough to me
Application.Run(New iCam()) 'purposely written twice for 2 cameras
so that you get 2 iCams without confusing the debugger- it knows that your code only allows one camera, and when you tell it to make 2, it gets all hot and bothered  :Smilie: 
Hope this helps
Rixterz
###I CHANGED THIS POST SO YOU SHOULD RE-READ IT!###
By the way, kommen Sie aus Deutschland?

----------


## computerschrat

Rixterz,

Thank you for the quick response. I will try as soon as possible and then let you know if I was succsessful. As I will be off for some days that may take a while.

Regards
computerschrat

----------


## sabirpaints

Very Very Helpful I just sign up this site to say thank for this clas. Thanks Alot @pino

----------

