【发布时间】:2017-08-25 11:01:45
【问题描述】:
我正在学习 OpenCV 和 EmguCV。我通过尝试从我的网络摄像头获取图像而成功,现在我正在尝试以灰度方式获取这些图像。
实现这一目标后,我的目的是识别和跟踪颜色,因此我尝试获取 HVS 格式的图像以过滤图像以仅以白色显示我要查找的颜色,而将图像的其余部分显示为黑色(希望你能理解我的解释)
现在,我只想使用以下代码从我的网络摄像头获取该灰度的图像:
Imports Emgu.CV
Imports Emgu.CV.Util
Imports Emgu.CV.Structure
Imports System.Drawing
Public Class Form1
Dim capturez As Capture = New Capture
Dim radius As Decimal = 50.0F
Dim x As Decimal
Dim y As Decimal
Private Sub Timer1_Tick() Handles Timer1.Tick
'Define x and y to determinate the position of the circle in the PictureBox
x = PictureBox1.Width / 2 - radius
y = PictureBox1.Height / 2 - radius
'PointF type defines the X and Y position of the future circle in the PictureBox
Dim point1 As New PointF(x, y)
Dim circle As CircleF = New CircleF(point1, radius)
Dim img As Image(Of Bgr, Byte) = capturez.QueryFrame()
'Convert camera capture from BGR to HVS
Dim hvs_frame As Image(Of Hsv, Byte) = img.Convert(Of Hsv, Byte)()
'Obtain the three channels that compose the HVS image (hue, saturation and value)
Dim channels As Image(Of Gray, Byte)() = hvs_frame.Split()
'Remove all pixels from the hue channel that are not in the range [40, 60]
CvInvoke.cvInRangeS(channels(0), New Gray(200).MCvScalar, New Gray(255).MCvScalar, channels(0))
'Display converted frame
PictureBox1.Image = channels(0).ToBitmap()
'When commenting the .CopyBlank() property, the back color of the PictureBox remains transparent
'When uncomment this, the back color of the PictureBox becomes black
Dim imageCircle As Image(Of Bgr, Byte) = img '.CopyBlank()
imageCircle.Draw(circle, New Bgr(Color.Brown), 2)
PictureBox1.Image = imageCircle.ToBitmap()
End Sub
使用此代码,我只获取 BGR 中的图像,我不知道为什么,因为我在“PictureBox1.Image”中指定了我想要该灰度的图像。
请帮帮我=(
如果需要,我正在使用 OpenCV 2.4.9 和 EmguCV 2.4.0 ...
非常感谢!
【问题讨论】:
-
接受答案会将问题标记为“已解决”。您无需将其弹出到标题中。尽可能保持清洁。
标签: vb.net opencv image-processing emgucv