AForge.NET

  :: AForge.NET Framework :: Articles :: Forums ::

Play Action when motion detected

Forum to discuss AForge.NET Framework, its features, API, how-tos, etc.

Play Action when motion detected

Postby dmitryzinatulin » Tue Jun 25, 2019 7:24 pm

Hello! How i can play some action once when motion detected, while action playing (let's say 10 seconds) detector detect nothing, and when action playing was stop detector can detect motion from new frames, I do not know how to put the question :C I need the webacm to recognize motion then when motion detected i can play video in second form, when video in second form was stopped, webcam recognize motion again
and sorry for my eng :)
dmitryzinatulin
 
Posts: 4
Joined: Tue Jun 25, 2019 7:12 pm

Re: Play Action when motion detected

Postby andrew.kirillov » Wed Jun 26, 2019 7:53 am

Hello,

Check sample and documentation provided with the AForge.NET Framework. There is a sample, which does motion detection. When detected, it blinks red border around video. You can start from there.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3451
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Play Action when motion detected

Postby dmitryzinatulin » Wed Jun 26, 2019 9:00 am

andrew.kirillov wrote:Hello,

Check sample and documentation provided with the AForge.NET Framework. There is a sample, which does motion detection. When detected, it blinks red border around video. You can start from there.

i already make detection algorithm, but it's working not correct for me
my webcam detect motion and blinks red border around motion object
what i need to do in comments

Code: Select all
        private void videoSourcePlayer_NewFrame(object sender, ref Bitmap image)
        {
                float motionLevel = detector.ProcessFrame(image);
                    if (detector != null)
                    {
                        if (motionLevel > motionAlarmLevel)
                        {
                            // If motion detected, play video then, when video stopped start detect motion from new frame, not from primary frames( HOW TO DO THIS??? HELP PLS )
                            cam1lbl.Invoke((MethodInvoker)delegate { cam1lbl.Text = "Cam 1: Motion detected"; });
                            animForm.canDetect = true;
                            animForm.PlayVideo();
                        }
                        else
                        {

                            cam1lbl.Invoke((MethodInvoker)delegate { cam1lbl.Text = "Cam 1: Motion not detected"; });


                        }
            }
        }


Code: Select all
/*ANIM FORM*/
        public void PlayVideo()
        {
            if (canDetect == true)
            {
                player.URL = Application.StartupPath + "/Crack.avi";
                player.Ctlcontrols.play();
                Thread.Sleep(5000);
                canDetect = false;
            }
           
        }
dmitryzinatulin
 
Posts: 4
Joined: Tue Jun 25, 2019 7:12 pm

Re: Play Action when motion detected

Postby andrew.kirillov » Wed Jun 26, 2019 9:36 am

When your video stopped playing, you can reset motion detector. Check documentation.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3451
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Play Action when motion detected

Postby dmitryzinatulin » Wed Jun 26, 2019 1:56 pm

andrew.kirillov wrote:When your video stopped playing, you can reset motion detector. Check documentation.


Detector.Reset not working? or what i doind wrong?

MainForm:
Code: Select all
private void videoSourcePlayer_NewFrame(object sender, ref Bitmap image)
        {
            if (detectCheckBox1.Checked)
            {
                float motionLevel = detector.ProcessFrame(image);
                if (detector != null)
                {
                    if (motionLevel > motionAlarmLevel)
                    {
                        if (CanCheck)
                        {
                            DoAction();
                            CanCheck = false;
                            CanCheckDuration();
                            ResetDetection();
   
                        }
                    }

                }
            }
        }


void CanCheckDuration()
        {
            if (CanCheck == false)
            {
                CanCheck = true;
                MessageBox.Show("CANCHECK CHANGE");
            }

        }

        public void ResetDetection()
        {
            detector.Reset();
            MessageBox.Show("RESET");
        }

        void DoAction()
        {
            cam1lbl.Invoke((MethodInvoker)delegate { cam1lbl.Text = "Cam 1: Motion detected"; });
            animForm.PlayVideo(5000);
        }


AnimForm
Code: Select all

public void PlayVideo(int duration)
        {
            player.URL = Application.StartupPath + "/Crack.avi";
            player.Ctlcontrols.play();
            Thread.Sleep(duration);
            //form.ResetDetection();
        }

Help pls
dmitryzinatulin
 
Posts: 4
Joined: Tue Jun 25, 2019 7:12 pm

Re: Play Action when motion detected

Postby andrew.kirillov » Thu Jun 27, 2019 7:07 am

I don't know what is not working for you. What do you expect to happen? What is happening instead?

The Reset() method will bring motion detector to its original state. As if you start detecting motion from the current video frame onwards. Just call that method after your other video finishes.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3451
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Play Action when motion detected

Postby dmitryzinatulin » Thu Jun 27, 2019 7:30 am

andrew.kirillov wrote:I don't know what is not working for you. What do you expect to happen? What is happening instead?


when motion detected video should be play 10 seconds, after 10 seconds detect new motion again ( it's what i need)

in videosourceplayer after 10 seconds video play, i see previous frames with red border and video play again :\, and as if Detector.Reset func not working (it' whats happening)
dmitryzinatulin
 
Posts: 4
Joined: Tue Jun 25, 2019 7:12 pm




Return to AForge.NET Framework