我试图在vb.net中使用emgu.cv lib进行轮廓功能。问题是我的var没有定义。这应该是我已经导入的lib emgu.cv。
Dim borderPen As New Pen(Color.FromArgb(150, 0, 255, 0))
Dim processor As ImageProcessor
Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs)
Dim borderPen As New Pen(Color.FromArgb(150, 0, 255, 0))
If RadioButton1.Checked = True Then
For Each contour As var In processor.contours
If contour.Total > 1 Then
e.Graphics.DrawLines(Pens.Red, contour.ToArray())
End If
Next
End If
SyncLock processor.foundTemplates
For Each found As FoundTemplateDesc In processor.foundTemplates
If found.template.name.EndsWith(".png") OrElse found.template.name.EndsWith(".jpg") Then
DrawAugmentedReality(found, e.Graphics)
Continue For
End If
Next
End SyncLock
End Sub
Private Sub DrawAugmentedReality(found As FoundTemplateDesc, gr As Graphics)
Dim fileName As String = "C:\Users\pnasguna\Desktop\A56.jpg"
Dim AugmentedRealityImages As New Dictionary(Of String, Image)()
Dim img As Image = AugmentedRealityImages(fileName)
Dim p As Point = found.sample.contour.SourceBoundingRect.Center()
Dim state = gr.Save()
gr.TranslateTransform(p.X, p.Y)
gr.RotateTransform(CSng(180.0F * found.angle / Math.PI))
gr.ScaleTransform(CSng(found.scale), CSng(found.scale))
gr.DrawImage(img, New Point(-img.Width / 2, -img.Height / 2))
gr.Restore(state)
End Sub
由于未定义var,我无法编译。如何解决这个问题?
答案 0 :(得分:2)
您收到Type <typename> is not defined错误,因为未定义类型var
。您可以通过执行以下步骤之一来解决此问题:
的
For Each contour In processor.contours
的
For Each contour As <THE_CORRECT_TYPE> In processor.contours
<强> Emgu 强>
查看emgu
的source code(用C#编写),ImageProcessor.cs
文件将显示contours
的数据类型:< / p>
public List<Contour<Point>> contours;
翻译成vb.net:
Public contours As List(Of Contour(Of Point))
<强>解决方案强>
因此,使用此信息,可以轻松选择正确的数据类型。
For Each contour As Contour(Of Point) In Me.processor.contours
注意:您总是将Option Strict设置为On
。