Click here to Skip to main content
15,893,663 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
i'm using ANDREW KIRILLOV's algos and libraries. please help me out with a way to save images on motion detection else the camera keeps on running.



// On timer event - gather statistic
private void timer_Elapsed( object sender, System.Timers.ElapsedEventArgs e )
{
try
{
Camera camera = cameraWindow.Camera;

if (camera != null)
{
// get number of frames for the last second
statCount[statIndex] = camera.FramesReceived;
// MessageBox.Show(statCount);
// increment indexes
if (++statIndex >= statLength)
statIndex = 0;
if (statReady < statLength)
statReady++;

float fps = 0;
float b1 = 0;

// calculate average value
for (int i = 0; i < statReady; i++)
{
fps += statCount[i];

}
fps /= statReady;

statCount[statIndex] = 0;
b1 = fps;


if (b1 >= 2 && b1 <= 10)
{
Val++;
//SendSMS(Phone.ToString(), "Alert!Intruder Detected");

if (Val == 3 || Val > 3)
{

timer.Stop();

camera.Stop();
this.Hide();


//this.Dispose();
}


Bitmap bmp = new Bitmap(this.Width, this.Height);
this.DrawToBitmap(bmp, new Rectangle(0, 0, this.Width, this.Height));
pictureBox1.Image = bmp;

///////
if (Val == 3 || Val > 3)
{

timer.Stop();

// camera.Stop();
this.Hide();


//this.Dispose();
}
else
{
bmp.Save("C:\\SpyCam\\" + Val.ToString() + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

}



//bmp.Save("C:\\SpyCam\\" + System.DateTime.Now.Minute.ToString() + "" + System.DateTime.Now.Second.ToString() + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);


look for the bold part of the code that's what i entered into ANDREW's code.
i have tried this code. but it saves 2 images on camera startup. but i want to save images only on motion detection compared to an initial reference frame. and that too of the camera window only. this code saves image of the whole form.
Posted
Updated 16-Mar-13 18:23pm
v5
Comments
[no name] 16-Mar-13 11:02am    
And we are supposed to know what it is that you have tried and what the actual problem is, how?
ProCodingKing 16-Mar-13 11:21am    
i have updated the question
[no name] 16-Mar-13 12:07pm    
No... this is just a massive code dump. You should only post enough code to demonstrate your issue. and describe your problem
ProCodingKing 17-Mar-13 0:24am    
updated again. now can you please help me as i have my project submission tomorrow.
Sergey Alexandrovich Kryukov 16-Mar-13 21:17pm    
Excuse me, perhaps you are from different culture, but did you know that mentioning person's name starting with lo-case letter means deep disrespect to this person? And just ignoring capitalization/punctuation and other rules in writing is simply rude...
—SA

Put a if statment on the newframe event that check for motion level >0 then save img
I had made a similar project with same name "SpyCam" but it save image create moview and write log for only frame of motion above a certain level
 
Share this answer
 
Comments
ProCodingKing 31-Mar-13 7:46am    
can you provide me your code?
kburman6 2-Apr-13 14:40pm    
can u give ur email id so that i can mail u
ProCodingKing 10-Apr-13 12:01pm    
prateek.kumar234@gmail.com
kburman6 10-Apr-13 15:45pm    
Check your mail.
try this code:

if (detector.MotionLevel > 0.2)
{

camera.Lock();
Val++;


if (Val == 3 || Val > 3)
{

timer.Stop();

camera.Stop();
this.Hide();



}


Bitmap bmp = new Bitmap(this.Width, this.Height);
this.DrawToBitmap(bmp, new Rectangle(0, 0, this.Width, this.Height));




else
{
bmp.Save("C:\\SpyCam\\" + Val.ToString() + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
camera.Unlock();
}
 
Share this answer
 

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