Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I add motion detection???? #49

Open
roast247 opened this issue Jan 11, 2022 · 2 comments
Open

How do I add motion detection???? #49

roast247 opened this issue Jan 11, 2022 · 2 comments

Comments

@roast247
Copy link

I wanted to add motion detection, so I had to add the reference "ref Bitmap image" but after adding that I get the error No overload for 'video_NewFrame' matches delegate 'NewFrameEventHandler'

        MotionDetector Detector;
        float viewmotion;
        private void mjpegStreamForm_Load(object sender, EventArgs e)
        {
            Detector = new MotionDetector(new TwoFramesDifferenceDetector(), new BlobCountingObjectsProcessing());
            viewmotion = 0;
        }
public void video_NewFrame(object sender, NewFrameEventArgs eventArgs, ref Bitmap image)     //<---------This is where I added it
       {
           viewmotion = Detector.ProcessFrame(image);

           time.Start();
           Bitmap img = (Bitmap)eventArgs.Frame.Clone();
           if (flag_rotate!=0)
           { 
           if (flag_rotate == 1) { img.RotateFlip(RotateFlipType.Rotate90FlipNone); }
           else if (flag_rotate == 2) { img.RotateFlip(RotateFlipType.Rotate180FlipNone); }
           else { img.RotateFlip(RotateFlipType.Rotate270FlipNone); }
           }
           if (flag_smooth == 1) { img = grayscale.Apply(img); }
           if (trackBar1.Value != 0) { img = br.Apply(img); }
           if (flag_flipX == 1) {img.RotateFlip(RotateFlipType.RotateNoneFlipX);}
           if (flag_flipY == 1) { img.RotateFlip(RotateFlipType.RotateNoneFlipY); }
           if (flag_sharpen == 1) { sharpen.ApplyInPlace(img);}
           if (flag_treshold == 1) {marker.ApplyInPlace(img); }
           if (flag_edge == 1) { rubovi.ApplyInPlace(img); }
           if (flag_dither == 1) {poster_filter.ApplyInPlace(img); }
           if (flag_invert == 1) { invert_filter.ApplyInPlace(img); }
           pbx_image.Image = img;
           time.Stop();
           lbl_time.Text = "Frame times: " + time.ElapsedMilliseconds+" ms";
           time.Reset();
       }

but on a button press I have the argument

        private void btn_playPause_Click(object sender, EventArgs e)
        {
            i++;
            if (i % 2 == 0)
            {
                this.btn_playPause.Image = ((System.Drawing.Image)(IPCams.Properties.Resources.icons8_circled_play_64));
                
                btn_capImage.Enabled = false;
                videoSource.SignalToStop();
                videoSource.WaitForStop();
                videoSource.Stop();
            }
            else
            {
                new Thread(() =>{
                Thread.CurrentThread.IsBackground = true;
                btn_capImage.Enabled = true;
                videoSource.Login = camUsername;
                videoSource.Password = camPassword;
                this.btn_playPause.Image = ((System.Drawing.Image)(IPCams.Properties.Resources.icons8_pause_button_64));
                videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);        //<---------This is where I have the problem
                videoSource.Start();
                }).Start();
            }
        }

Is there any way to get rid of this error? I just want motion detection to work!

@Micke3rd
Copy link

Micke3rd commented Jan 11, 2022

if you write
new NewFrameEventHandler(video_NewFrame);
then
video_NewFrame(object sender, NewFrameEventArgs eventArgs, ref Bitmap image)
and
NewFrameEventHandler(object sender,NewFrameEventArgs eventArgs);
have to have the same arguments, but they are now different with Bitmap image.

@roast247
Copy link
Author

if you write new NewFrameEventHandler(video_NewFrame); then video_NewFrame(object sender, NewFrameEventArgs eventArgs, ref Bitmap image) and NewFrameEventHandler(object sender,NewFrameEventArgs eventArgs); have to have the same arguments, but they are now different with Bitmap image.

How would I fix this? I won't be able to use motion detection unless Bitmap image is added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants