Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
Dear friends,

I am sitting here with the c# windows application.

I have set a picture box to capture image.

I want to detect motion from web camera.

I don't know how to set a path for capturing images continuously in to a folder.

Please explain me in codes.

In code project there are some project's motion_src.

I can't catch where they will call and close the program.

I am waiting for your valuable answers.

I've tried this till now:

using System;
using System.Linq;
using System.Text;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;



namespace WinFormCharpWebCam
{
    //Design by Pongsakorn Poosankam
    public partial class mainWinForm : Form
    {
        public mainWinForm()
        {
            InitializeComponent();
        }
        WebCam webcam;
        private void mainWinForm_Load(object sender, EventArgs e)
        {
            webcam = new WebCam();
            webcam.InitializeWebCam(ref imgVideo);
        }

        private void bntStart_Click(object sender, EventArgs e)
        {
            webcam.Start();
            detector = new MotionDetector3();
            detectorType = 3;
            SetMotionDetector();
        }
        private void SetMotionDetector()
        {
            Camera camera = cameraWindow.Camera;

            // enable/disable motion alarm
            if (detector != null)
            {
                detector.MotionLevelCalculation = motionAlarmItem.Checked;
            }

            // set motion detector to camera
            if (camera != null)
            {
                camera.Lock();
                camera.MotionDetector = detector;

                // reset statistics
                statIndex = statReady = 0;
                camera.Unlock();
            }
        }

        private void bntStop_Click(object sender, EventArgs e)
        {
            webcam.Stop();
        }

        private void bntContinue_Click(object sender, EventArgs e)
        {
            webcam.Continue();
        }

        private void bntCapture_Click(object sender, EventArgs e)
        {
            imgCapture.Image = imgVideo.Image;
        }

        private void bntSave_Click(object sender, EventArgs e)
        {
            Helper.SaveImageCapture(imgCapture.Image);
         
        }

        private void bntVideoFormat_Click(object sender, EventArgs e)
        {
            webcam.ResolutionSetting();
        }

        private void bntVideoSource_Click(object sender, EventArgs e)
        {
            webcam.AdvanceSetting();
        }

        
    }
}


Till now I've been able to capture the image when I press a button but I would like to be able to capture the images automatically.

I don't know how to proceed, could you help?

Thank you in advance.
Posted
Updated 25-Jul-12 5:41am
v2
Comments
[no name] 25-Jul-12 9:05am    
It is highly unlikely that you will get an answer to this unless you go through this a clearly state what it is that you are doing. Looks like you are talking about 5 different things without a clear idea of what it is that you are doing.
Dhinesh kumar.V 25-Jul-12 9:18am    
actually i want to capture image continuosly from a webcam. and it will stored automatically in to a folder.
[no name] 25-Jul-12 9:22am    
So what exactly is it that you are doing? Where is the code the demonstrates your problem? We are not mind readers.
Dhinesh kumar.V 25-Jul-12 9:39am    
using System;
using System.Linq;
using System.Text;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;



namespace WinFormCharpWebCam
{
//Design by Pongsakorn Poosankam
public partial class mainWinForm : Form
{
public mainWinForm()
{
InitializeComponent();
}
WebCam webcam;
private void mainWinForm_Load(object sender, EventArgs e)
{
webcam = new WebCam();
webcam.InitializeWebCam(ref imgVideo);
}

private void bntStart_Click(object sender, EventArgs e)
{
webcam.Start();
detector = new MotionDetector3();
detectorType = 3;
SetMotionDetector();
}
private void SetMotionDetector()
{
Camera camera = cameraWindow.Camera;

// enable/disable motion alarm
if (detector != null)
{
detector.MotionLevelCalculation = motionAlarmItem.Checked;
}

// set motion detector to camera
if (camera != null)
{
camera.Lock();
camera.MotionDetector = detector;

// reset statistics
statIndex = statReady = 0;
camera.Unlock();
}
}

private void bntStop_Click(object sender, EventArgs e)
{
webcam.Stop();
}

private void bntContinue_Click(object sender, EventArgs e)
{
webcam.Continue();
}

private void bntCapture_Click(object sender, EventArgs e)
{
imgCapture.Image = imgVideo.Image;
}

private void bntSave_Click(object sender, EventArgs e)
{
Helper.SaveImageCapture(imgCapture.Image);

}

private void bntVideoFormat_Click(object sender, EventArgs e)
{
webcam.ResolutionSetting();
}

private void bntVideoSource_Click(object sender, EventArgs e)
{
webcam.AdvanceSetting();
}


}
}
this is my code please help me.if i wanna click a button automatic capture the images in to a folder continuously.
[no name] 25-Jul-12 9:49am    
And so? This code won't even compile. Did you get all of the code from Pongsakorn Poosankam or did you just take bits and pieces?

1 solution

Dhinesh,

Your code is ok.

All you need is component Timer. You need to go in menu View -> Toolbox and add the component in your application. Then you click twice in the Timer to see the code for your project and call your function again.

The timer execute in miliseconds. If you wish a image at 1 minute, set the Timer Interval in 60000 (equal a 1 minute).

Do you understand?
 
Share this answer
 
Comments
Dhinesh kumar.V 26-Jul-12 7:04am    
dear sir, first i want motion detect to capture images.after i will call the timer.please tell me in code to motion detect by webcamera and i will use the timer. i really don't know the code for motion detection.please help me..

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