我拍摄了一段视频并取出了一段视频,将其转换为位图,现在我可以将其显示在图片框上。
我有一些浮点数,它是图像类中GoodFeaturesToTrack()函数的返回值。
现在我想在我的照片上绘制/显示不同的Xi,Yi上的那些点/标记;
怎么可能这样做?我必须使用哪个命令?
答案 0 :(得分:0)
为PictureBox.Paint
事件添加处理程序并在那里进行绘制。如果需要刷新PictureBox控件上的绘图调用Invalidate()
以重绘。
void PictureBox_Paint(object sender, PaintEventArgs e) {
// draw points from var pointsList = List<Point>
foreach (Point p in pointsList) {
e.Graphics.DrawEllipse(Pens.Yellow, p.X - 2, p.Y - 2, 4, 4);
}
}
答案 1 :(得分:0)
在将图像转换为普通位图之前,您可以使用内置的OpenCV函数在找到的要素点周围进行渲染。这也会快得多,因为图像类将与原始内存一起使用而不是发出图形调用。
这是一个(不完整的)例子来说明这一点。注意:您可能需要调整对包装器声明的CV签名的调用:
private int maxPointCount = 16;
private CvPoint2D32f[] points = new CvPoint2D32f[maxPointCount];
private CvImage grayImage = new CvImage(size, CvColorDepth.U8, CvChannels.One);
private CvImage eigenValues = new CvImage(size, CvColorDepth.F32, CvChannels.One);
private CvImage tempImage = new CvImage(size, CvColorDepth.F32, CvChannels.One);
public int FeatureRadius { get; set; }
private CvScalar featureColor;
public Color FeatureColor
{
get
{
return Color.FromArgb((byte)featureColor.Value2, (byte)featureColor.Value1, (byte)featureColor.Value0);
}
set
{
featureColor.Value0 = value.B;
featureColor.Value1 = value.G;
featureColor.Value2 = value.R;
}
}
public void Process(CvImage input, CvImage output)
{
CV.ConvertImage(input, grayImage);
CV.GoodFeaturesToTrack(grayImage, eigenValues, tempImage, points, ref maxPointCount, 0.01, 10, IntPtr.Zero, 3, 0, 0.04);
CV.Copy(input, output);
// This draws a circle around the feature points found
for (int i = 0; i < pointCount; i++)
CV.Circle(output, new CvPoint((int)points[i].X, (int)points[i].Y), FeatureRadius, featureColor);
}