尝试启动网络摄像头时出错: System.TypeInitializationException
尝试:
Dim capWebcam As Capture
Try
capWebcam = New Capture() <<<<<<<here
Catch ex As Exception
Me.Text = ex.Message
Return
End Try
我已将此DLL添加到项目中:
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
我尝试了一百种可能性而没有:(
该项目有一个表格,人们可以选择图像文件或网络摄像头,选择颜色RGB选项,并将检测圆形,线条和多边形。 这是一个大代码,但在这里(编辑 - &gt;我尝试使代码更小,所以我删除了没有更改网络摄像头的代码,如果出现一些未关闭的IF,可能是因为我编辑了它) :
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