I have an error when I try to start the webcam: System.TypeInitializationException
When try to:
Dim capWebcam As Capture
Try
capWebcam = New Capture() <<<<<<<here
Catch ex As Exception
Me.Text = ex.Message
Return
End Try
I have this DLL added to the project:
opencv -
calib3d240
contrib240
core240
features2d240
ffmpeg240_64
flann240
gpu240
highgui240
imgproc240
legacy240
ml240
nonfree240
objdetect240
photo240
stitching240
videostab240
And ENGU:
CV.Stitching
CV.UI
CV.GPU
CV.DebuggerVIsualizers.VS2010
CV.ML
CV.OCR
Util
CV
I tried one hundred possibilities and nothing :(
The project has a form that the person can choose an image file or a webcam, choosing colors RGB options and will detect circles, lines and polys. It is a Big code, but is here (EDIT -> I try to make the code smaller so I delete the code that have no changes in the webcam, if appear some IF that is not closed, maybe is because I edited it):
Option Strict On
Imports Emgu.CV
Imports Emgu.CV.CvEnum
Imports Emgu.CV.Structure
Imports Emgu.CV.UI
Public Class frmForm
'Variaveis
Dim capWebcam As Capture
Dim blnWebcamCapturingInProcess As Boolean = False
'Construtor
Sub New()
InitializeComponent() ' Metodo necessario para instanciar o Design
intOrigFormWidth = Me.Width
intOrigFormHeight = Me.Height
intOrigTableLayoutPanelWidth = tlpLabelsAndImageBoxes.Width
intOrigTableLayoutPanelHeight = tlpLabelsAndImageBoxes.Height
End Sub
' Metodos dos componentes _____
Private Sub frmForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load, MyBase.Resize
End Sub
Private Sub frmForm_Resize(sender As System.Object, e As System.EventArgs) Handles MyBase.Resize
'This If Else statement is necessary to throw out the first time the Form1_Resize event is called.
'For some reason, in VB.NET the Resize event is called once before the constructor, then the constructor is called,
'then the Resize event is called each time the form is resized. The first time the Resize event is called
'(i.e. before the constructor is called) the coordinates of the components on the form all read zero,
'therefore we have to throw out this first call, then the constructor will run and get the correct initial
'component location data, then every time after that we can let the Resize event run as expected
If (blnFirstTimeInResizeEvent = True) Then
blnFirstTimeInResizeEvent = False
Else
tlpLabelsAndImageBoxes.Width = Me.Width - (intOrigFormWidth - intOrigTableLayoutPanelWidth)
tlpLabelsAndImageBoxes.Height = Me.Height - (intOrigFormHeight - intOrigTableLayoutPanelHeight)
End If
End Sub
Private Sub rdoImageFile_CheckedChanged(sender As Object, e As EventArgs) Handles rdoImageFile.CheckedChanged
If (rdoImageFile.Checked = True) Then
If (blnWebcamCapturingInProcess = True) Then
RemoveHandler Application.Idle, New EventHandler(AddressOf Me.ProcessImageAndUpdateGUI)
blnWebcamCapturingInProcess = False
End If
ibOriginal.Image = Nothing
ibGrayColorFiltered.Image = Nothing
ibCanny.Image = Nothing
ibCircles.Image = Nothing
ibLines.Image = Nothing
ibTrisRectsPolys.Image = Nothing
lblFile.Visible = True
txtFile.Visible = True
btnFile.Visible = True
End If
End Sub
Private Sub rdoWebCam_CheckedChanged(sender As Object, e As EventArgs) Handles rdoWebCam.CheckedChanged
If (rdoWebCam.Checked = True) Then
Try
capWebcam = New Capture()
Catch ex As Exception
Me.Text = ex.Message
Return
End Try
AddHandler Application.Idle, New EventHandler(AddressOf Me.ProcessImageAndUpdateGUI)
blnWebcamCapturingInProcess = True
lblFile.Visible = False
txtFile.Visible = False
btnFile.Visible = False
End If
End Sub
Private Sub frmForm_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
If (Not capWebcam Is Nothing) Then
capWebcam.Dispose()
End If
End Sub
Private Sub btnFile_Click(sender As Object, e As EventArgs) Handles btnFile.Click
Dim drDialogResult As DialogResult = ofdFile.ShowDialog()
If (drDialogResult = Windows.Forms.DialogResult.OK Or drDialogResult = Windows.Forms.DialogResult.Yes) Then
txtFile.Text = ofdFile.FileName
If (txtFile.Text <> String.Empty) Then
ProcessImageAndUpdateGUI(New Object(), New EventArgs())
End If
End If
End Sub
End Sub
End Class