Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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();
            }
        }
Posted
Updated 23-Jun-17 0:03am
v3

1 solution

I think you need to change the .Top value before adding the picturebox in
C#
this.panel1.Controls.Add(p);
You could do this by adding all heights into a variable, e.g. int totalHeight and using that for the .Top value:
C#
int totalHeight = 0;
foreach (PictureBox p in pictureBoxList)
{
  p.Top = totalHeight;
  this.panel1.Controls.Add(p);
  totalHeight += p.Height;
}
 
Share this answer
 
v2
Comments
sreeenivasa reddy 23-Jun-17 2:51am    
totalheight where i ahve to take...actually it is giving me the only one image at a time

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900