Click here to Skip to main content
15,901,284 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.CV.CvEnum;
using System.Security.Cryptography;


namespace AITest
{ 
    public partial class Form1 : Form
{
        Image<Bgr, byte> imgInput;
        private Bitmap img;
        bool show = false;
        private VideoCapture _capture = null;
       private CascadeClassifier _cascadeClassifier;
    //Image imgInput = new Image();
        public Form1()
    {
        InitializeComponent();
        _capture = new VideoCapture();
        _cascadeClassifier = new CascadeClassifier(Application.StartupPath + "/haarcascade_frontalface_default.xml");
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

    private void ProcessFrame(object sender, EventArgs arg)
    {
        var imageFrame = _capture.QueryFrame().ToImage<Bgr, byte>();
        if (imageFrame != null)
        {
            var grayframe = imageFrame.Convert<Gray, byte>();
            var faces = _cascadeClassifier.DetectMultiScale(grayframe, 1.1, 10, Size.Empty);
            foreach (var face in faces)
            {
                imageFrame.Draw(face, new Bgr(Color.Red), 3);
                }
        }
            //imgInput = new Image<Bgr, byte>(ofd.FileName);
            //pictureBox1.Image = imgInput; 
 
            pictureBox1.Image = imageFrame.Bitmap;---Iam getting error here
        }

    private void button1_Click(object sender, EventArgs e)
    {
        if (_capture != null)
        {
            Application.Idle += ProcessFrame;
        }
    }

    private void button2_Click(object sender, EventArgs e)
    {
        if (_capture != null)
        {
            Application.Idle -= ProcessFrame;
        }
    }
}
}


What I have tried:

Iam working on facerecognication system in c# but facing an error near "
pictureBox1.Image = imageFrame.Bitmap
" could you please help on this
Posted

1 solution

Assuming this is EmguCV, QueryFrame returns a Mat, and calling ToImage on that returns an EmguCV Image class instance - which is not related to the .NET Image class - so it doesn't support a Bitmap property: Image(TColor, TDepth) Class[^] which the PictureBox class expects.

You may be able to convert it - SO seems to think you can: https://stackoverflow.com/questions/15406235/convert-emgucv-image-to-system-drawing-bitmap[^] - but ToBitmap isn't listed in the EmguCV Image documentation so I have no idea if it will work ...
 
Share this answer
 

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