Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am working on a project and I need to convert c# code to work in wpf environment.

The code is :


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.Util;
using Emgu.CV.Structure;
using Emgu.CV.CvEnum;


namespace capture
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Capture cap;
        private HaarCascade haar;

        private void Form1_Load(object sender, EventArgs e)
        {
            // passing 0 gets zeroth webcam
            cap = new Capture(0);
            // adjust path to find your xml
            haar = new HaarCascade("haarcascade_mcs_mouth.xml");

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            using (Image<Bgr, byte> nextFrame = cap.QueryFrame())
            {
                if (nextFrame != null)
                {
                    // there's only one channel (greyscale), hence the zero index
                    //var faces = nextFrame.DetectHaarCascade(haar)[0];
                    Image<Gray, byte> grayframe = nextFrame.Convert<Gray, byte>();
                    var faces =
                            grayframe.DetectHaarCascade(
                                    haar, 1.4, 4,
                                    HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
                                    new Size(nextFrame.Width / 8, nextFrame.Height / 8)
                                    )[0];

                    foreach (var face in faces)
                    {
                        //int x = face.rect.Height;
                        //nextFrame.Draw(face.rect, new Bgr(100, double.MaxValue, 0), 3);
                        //label1.Text = face.rect.Top.ToString();
                        label1.Text = face.rect.Height.ToString();

                    }
                    pictureBox1.Image = nextFrame.ToBitmap();
                }
            }

        }
    }
}




Is there anyone help me to convert it to work in wpf environment

[edit]Code block added to improve readability - OriginalGriff[/edit]
Posted
Updated 23-Dec-10 14:16pm
v3

1 solution

The only way to convert it to WPF is to do it by hand (manually).

You could also use the WPF/Winform Interoperability to bring the whole form over as is, but that's kinda ugly, and is not, of course, pure WPF. If you do decide to go this route, I would put the Winform form into its own assembly, and use it that way.

Google is your friend.

 
Share this answer
 
v2
Comments
assma eissa ramadan 23-Dec-10 16:37pm    
i will try to convert manual
but can you help in it ?

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