谁能为我提供一种在运动检测中保存图像的方法 [英] can anyone provide me with a way to save image on motion detection

查看:83
本文介绍了谁能为我提供一种在运动检测中保存图像的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ANDREW KIRILLOV的算法和图书馆。请帮我解决一下在运动检测中保存图像的方法,否则相机会继续运行。







//关于计时器事件 - 收集统计数据

private void timer_Elapsed(object sender,System.Timers.ElapsedEventArgs e)

{

try

{

相机相机= cameraWindow.Camera;



if(相机!= null)

{

//获取最后一秒的帧数

statCount [statIndex] = camera.FramesReceived;

/ / MessageBox.Show(statCount);

//增量索引

if(++ statIndex> = statLength)

statIndex = 0;

if(statReady< statLength)

statReady ++;



float fps = 0;

float b1 = 0;



//计算平均值

for(int i = 0; i< statReady; i ++)

{

fps + = statCount [i];



}

fps / = statRe ady;



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();

}





位图bmp =新位图(this.Width,this.Height);

this.DrawToBitmap(bmp,new Rectangle(0,0,this。宽度,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);





寻找代码的大胆部分,这是我输入ANDREW的代码。

i已经尝试过这段代码。但它可以在相机启动时保存2张图像。但我想仅在运动检测时保存图像与初始参考帧相比。而且只有相机窗口。此代码保存整个表单的图像。

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.

推荐答案

在检查运动级别> 0的newframe事件上放置if语句然后保存img

我创建了一个名为SpyCam的类似项目,但它保存图像创建moview并仅为某个级别以上的运动帧写日志
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


尝试此代码:



if(detector.MotionLevel> 0.2)

{



相机。 Lock();

Val ++;





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

{



timer.Stop();



相机。停止();

this.Hide();







}





位图bmp =新位图(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();

}
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();
}


这篇关于谁能为我提供一种在运动检测中保存图像的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆