如何在实时视频C#窗体中检测到的面板中存储多个图像 [英] How to store multiple images in panel detected from live video C# windows forms
本文介绍了如何在实时视频C#窗体中检测到的面板中存储多个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经尝试过这段代码来获取从实时视频中检测到的图像并存储到面板中,但它只拍摄第一个检测到的图像,我想要使用矩形区域检测到所有图像。
我的尝试:
I have tried this code to get the images detected from live video and storing into the panel but it taking only first detected image i want all images detected using Rectangle Area.
What I have tried:
private VideoCapture capture;
private void Form1_Load(object sender, EventArgs e) {
capture = new VideoCapture("C://Users/srinivas/Desktop/small.mp4");
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
Image<Bgr, Byte> CurrentFrame = capture.QueryFrame().ToImage<Bgr,Byte>();
Image<Gray, byte> bWFrame = CurrentFrame.Convert<Gray, byte>();
Rectangle rect=new Rectangle(120,100,240,350);
//CurrentFrame.Draw(rect,new Bgr(Color.DarkSalmon), 1, Emgu.CV.CvEnum.LineType.EightConnected, 0);
long detectionTime;
List<Rectangle> faces = new List<Rectangle>();
List<Rectangle> eyes = new List<Rectangle>();
DetectFace.Detect(CurrentFrame, "haarcascade_frontalface_default.xml", "haarcascade_eye.xml",faces, eyes,out detectionTime);
//DetectFace.Detect(bWFrame, "haarcascade_frontalface_default.xml", "haarcascade_eye.xml", faces, eyes, out detectionTime);
List<PictureBox> pictureBoxList = new List<PictureBox>();
foreach (Rectangle rectface in faces)
{
CurrentFrame.Draw(rectface, new Bgr(Color.DarkSalmon), 1, Emgu.CV.CvEnum.LineType.EightConnected, 0);
bWFrame.Draw(rectface, new Gray(50), 1, Emgu.CV.CvEnum.LineType.EightConnected, 0);
//Rectangle ra = CurrentFrame.ROI;
Bitmap RectAreaImg = CurrentFrame.ToBitmap();
Bitmap ExtractedFace = new Bitmap(rectface.Width, rectface.Height);
Graphics facecanvas = Graphics.FromImage(ExtractedFace);// for a specified image new graphis vl creates
facecanvas.DrawImage(RectAreaImg, 0, 0, rectface, GraphicsUnit.Pixel);// graphics type ki we r gng to draw image
PictureBox pic = new PictureBox();
pic.Image = ExtractedFace;
//pic.Location = new Point(x, y);
pictureBoxList.Add(pic);
foreach (PictureBox p in pictureBoxList)
{
this.panel1.Controls.Add(p);
}
//this.panel1.Controls.Add(pic);
}
imageBox1.Image = CurrentFrame;
//imageBox2.Image = bWFrame;
label1.Text = Convert.ToString(detectionTime);
if(CurrentFrame!=null)
{
CurrentFrame.Dispose();
}
}
推荐答案
我认为您需要更改.Top
在添加图片框之前的值
I think you need to change the.Top
value before adding the picturebox in
this.panel1.Controls.Add(p);
你可以通过将所有高度添加到变量中来实现,例如 int totalHeight
并将其用于.Top值:
You could do this by adding all heights into a variable, e.g. int totalHeight
and using that for the .Top value:
int totalHeight = 0;
foreach (PictureBox p in pictureBoxList)
{
p.Top = totalHeight;
this.panel1.Controls.Add(p);
totalHeight += p.Height;
}
这篇关于如何在实时视频C#窗体中检测到的面板中存储多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文