-2

I am working on a C# windows form application. How can i edit my code in a way that when more than 2 faces is being detected by my webcam.

More information:

When "FaceDetectedLabel.Text = "Faces Detected : " + cam.facesdetected.ToString();" becomes Face Detected: 2 or more...

How can i do the following:

  • Minimize all program running except my application.

Here is my code:

namespace PBD
{
    public partial class MainPage : Form
    {
        //declaring global variables
        private Capture capture;        //takes images from camera as image frames

        public MainPage()
        {
            InitializeComponent();
        }

        private void ProcessFrame(object sender, EventArgs arg)
        {
            Wrapper cam = new Wrapper();

            //show the image in the EmguCV ImageBox
            WebcamPictureBox.Image = cam.start_cam(capture).Resize(390, 243, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC).ToBitmap();
            FaceDetectedLabel.Text = "Faces Detected : " + cam.facesdetected.ToString();
        }

        private void MainPage_Load(object sender, EventArgs e)
        {

            #region if capture is not created, create it now
            if (capture == null)
            {
                try
                {
                    capture = new Capture();
                }
                catch (NullReferenceException excpt)
                {
                    MessageBox.Show(excpt.Message);
                }
            }
            #endregion

            Application.Idle += ProcessFrame;
        }
Joe Doyle
  • 6,363
  • 3
  • 42
  • 45
Derek
  • 239
  • 1
  • 7
  • 15
  • 1
    Possible Duplicate: http://stackoverflow.com/questions/785054/minimizing-all-open-windows-in-c-sharp – NET3 Dec 04 '12 at 16:57
  • I am unsure how can i call the function when more than two faces is being detected. How can i do that? – Derek Dec 04 '12 at 17:01
  • @Derek This question is likely to get closed as it is too broad. I advise you to break your problem up into separate logical / functional problems and solve them each in isolation - and only then try to put them together into a final solution. – tomfanning Dec 04 '12 at 17:02
  • Related post - [How to Minimise other windows while your application is running C#](https://stackoverflow.com/q/46154112/465053) – RBT Jan 13 '22 at 11:55

1 Answers1

3

check this post:

How to programmatically minimize opened window folders

You'll have to enumerate all processes and exclude the current one (yours) instead of getting the "explorer" one. I'd suggest also putting exception handling and some checks in place since not all processes have windows to be minimized

Also this post for the log off part:

Log off user from Win XP programmatically in C#

Community
  • 1
  • 1
Sten Petrov
  • 10,943
  • 1
  • 41
  • 61