锐英源软件
第一信赖

精通

英语

开源

擅长

开发

培训

胸怀四海 

第一信赖

当前位置:锐英源 / 开源技术 / C#开源英语 / Cam Alarm 2.0 - 基于网络摄像头的报警系统
服务方向
人工智能数据处理
人工智能培训
kaldi数据准备
小语种语音识别
语音识别标注
语音识别系统
语音识别转文字
kaldi开发技术服务
软件开发
运动控制卡上位机
机械加工软件
软件开发培训
Java 安卓移动开发
VC++
C#软件
汇编和破解
驱动开发
联系方式
固话:0371-63888850
手机:138-0381-0136
Q Q:396806883
微信:ryysoft

锐英源精品开源心得,转载请注明:“锐英源www.wisestudy.cn,孙老师作品,电话13803810136。”需要全文内容也请联系孙老师。

Cam Alarm 2.0 - 基于网络摄像头的报警系统

报警系统

Just a quickie..简短前言....

I wrote the original version of this in VB6 about 4 years ago, and published it as freeware (might even be floating around the wild somewhere still..), and decided it was a good starter app for learning C#, when I began migrating my skills almost two years ago. So, the uncompleted version of this has been sitting in a folder on my dev box for some time, just waiting for a few tweaks - which I got around to the other day. I thought this would be a good target freeware, because unfortunately, many of us have had the misfortune of being robbed at some point in our lives, and students, young working people, or someone in an apartment may not be able to afford or install a proper alarm system.

我在大约4年前写这个基于VB6的原始版本,并发表为免费版本(甚至可能在网络上四处流窜.),并决定这是一个很好的学习c#起步的应用程序,当我几乎是两年前开始移植这些特性。 所以,未完成的版本一直坐在一个文件夹,保存在我的目录下一段时间,只是等待调整——我来了。 我认为这将是一个好免费软件,,因为不幸的是,我们许多人在我们的生活中都不幸被剥夺了,和学生,工作的年轻人,或者有人在公寓里可能无法负担或安装一个合适的报警系统。

I use a Creative 5.1 speaker rig, and with the amp cranked, the siren this sounds is at least as loud as a conventional alarm system, and would probably cause an intruder to bolt rather than attempt to find the source and disarm.

我使用一个Creative 5.1扬声器,带弯曲的放大器,,警笛这听起来至少是一样响亮的传统的报警系统,并可能导致入侵者不前,而不是试图找到源和解除。

The original used the avicap32.dll library, which seemed to work fine on my older Logitech camera, but will not work on newer devices (this was tested with both an Acer notebook camera, and an MS Lifecam). At this point, I realized I had to go to the DirectShow library to capture video from a wider range of input devices. A search on CodeProject turned up the Motion Detection project by Andrew Kirillov. I removed dependencies on the AForge library, and reworked the AVI reader/writer classes, but the DirectShow wrappers and detection algorithms are his work (thanks Andrew).

原来的使用 avicap32.dll 库,它似乎对我的老罗技摄像头很好使,但不会工作在新设备上(这是一个测试与宏碁笔记本摄像头,和一个女士Lifecam)。 在这一点上,我意识到我不得不去DirectShow库来从一个广泛的输入设备捕获视频。 在CodeProject上搜索了 运动检测 项目,来自安德鲁Kirillov。 我删除了依赖的AForge库,修改了AVI阅读器/写入器类,但DirectShow的包装和检测算法(感谢安德鲁)是他的工作。

The highlights 亮点

When the application loads, it tests for the WMV AVI recording codec by enumerating the installed codecs; if it isn't found, a dialog is launched, asking the user to install it. The installation executable is an embedded resource, which is pulled from the resource assembly and recreated as a file in the temp directory, then launched with the ShellExecute API.

当应用程序加载时,这对WMV AVI测试记录编解码器通过列举编解码器安装;如果没有找到,启动一个对话框,要求用户安装它。 安装可执行文件是嵌入式资源,从资源组装和重新创建临时目录中的一个文件,然后推出ShellExecute API.

private void codecTest()
      { 
      FilterCollection filters = new FilterCollection(FilterCategory.VideoCompressorCategory);
      bool found = false;
      foreach (Filter filter in filters)
      {
      found = filter.Name.Contains("Media Video 9");
      if (found)
      break;
      }
      if (!found)
      {
      if (MessageBox.Show("The video capture feature requires the Microsoft " + 
  "WMV9 codec. Do you want to install this now?", 
  "Codec Installation Required",
      MessageBoxButtons.OKCancel, 
      MessageBoxIcon.Question) == DialogResult.OK)
      {
      executeCodec();
      }
      else
      {
      _bCanRecord = false;
      }
      }
      }
      private bool executeCodec()
      {
      try
      {
      Assembly assembly = Assembly.GetExecutingAssembly();
      using (Stream stream = assembly.GetManifestResourceStream(
  "CamAlarm.Resources.wmv9VCMsetup.exe"))
      {
      if (stream != null)
      {
      BinaryReader br = new BinaryReader(stream);
      using (FileStream fs = new FileStream(
      Environment.GetEnvironmentVariable("TEMP") +   "\\wmv9VCMsetup.exe", FileMode.Create))
      {
      BinaryWriter bw = new BinaryWriter(fs);
      byte[] bt = new byte[stream.Length];
      stream.Read(bt, 0, bt.Length);
      bw.Write(bt);
      br.Close();
      bw.Close();
      fs.Close();      }
      executeProgram(Environment.GetEnvironmentVariable("TEMP") + 
  "\\wmv9VCMsetup.exe");
      }
      }
      return true;
      }
      catch { return false; }
      }

A timer is run that waits for the camera to focus in, then the control panels are activated. Settings like the keycode and option control states are stored in the application's default properties. When first run, or if the keycode property is cleared, the Arm/Disarm button acts as the keycode set button. The sounds used in the application are instances of the System.Media.SoundPlayer class, instanced and loaded with a sound file when the app initializes:

运行一个计时器等相机对焦,对焦,然后控制面板被激活。 设置键码和选项控制状态存储在应用程序的默认属性。 第一次运行时,或者清除键码属性,手臂/解除按钮充当键码设置按钮。 声音中使用的应用程序实例 System.Media.SoundPlayer 类,实例化和加载应用程序初始化时声音文件:

private void loadWarning()
{
if (_cWarningSound != null)
_cWarningSound.Dispose();
_cWarningSound = new SoundPlayer(CamAlarm.Resource1.beep);
_cWarningSound.Load();
}

The camera's motion trigger-state is polled periodically using a custom timer class; if motion has occurred, an alarm timer is fired, which will loop until the alarm is deactivated, or the max alarm timeout occurs:

相机的运动触发状态定期调查使用自定义定时器类;如果运动发生,警报触发计时器,将循环,直到报警时,马克斯报警或者超时:

private void _cAlarmTimer_Tick(object sender)
      {
      // timer starts 5 states: standby, armed, arming, triggered, sounding
      //1) if arming warning period elapses, optional beeps
      //2) if not arming, warning sounds and counts to min elapse
      //3) if min elapse and _activetick over threshhold, loops again
      //4) if standby -stop timer
      if (_eAlarmState == AlarmState.Arming)
      {
      _iTimerTick++;
      if (_iTimerTick > stringToInt(txtArmingDelay.Text))
      armAlarm();
      else
      updateStatus();
      }
      else if (_eAlarmState == AlarmState.Armed)
      {
      if (_iActiveTick > 5)>
      triggerAlarm();
      }
      else if (_eAlarmState == AlarmState.Sounding)
      {
      _iTimerTick++;
      if (_iTimerTick > stringToInt(txtDuration.Text))
      {
      if (_iActiveTick < 5)
      disarmAlarm();
      els
      //loop again
      soundAlarm();
      }
      else
      {
      soundAlarm();
      }
      }
      else if (_eAlarmState == AlarmState.Standby)
      {
      stopAlarm();
      }
      else if (_eAlarmState == AlarmState.Triggered)
      {
      _iTimerTick++;
      if (_iTimerTick > stringToInt(txtAlarmDelay.Text))
      {
      soundAlarm();
      }
      else
      {
      if (!chkSilent.Checked)
      playWarning();
      }
      }
      }

When the alarm is in Armed mode, all but the keypad and disarm switch are disabled. This is done by disabling the GroupBox that houses the controls. The main form close button also needs to be deactivated. This is done both by cancelling the form's exit in the FormClosing event, and by disabling the Close button using the GetSystemMenu/EnableMenuItem API:

当报警 武装 模式,但键盘和解除开关都是禁用的。 这是通过禁用 GroupBox ,控制。 关闭按钮的主要形式也需要释放。 这样做是通过取消表单的退出 FormClosing 事件,并通过禁用关闭按钮使用 GetSystemMenu / EnableMenuItem API:

private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
      {
      if (_bCloseDisabled)
      {
      e.Cancel = true;
      }
      else
      {
      closeCamera();
      closeFile();
      saveSettings();
      if (_cAlarmTimer != null/
      _cAlarmTimer.Dispose();
      }
      }
    private void enableClose(bool enable)
      {
      if (enable)
      EnableMenuItem(GetSystemMenu(this.Handle, false), SC_CLOSE, MF_ENABLED);
      else
      EnableMenuItem(GetSystemMenu(this.Handle, false), SC_CLOSE, MF_GRAYED);
 
      _bCloseDisabled = !enable;
      }

All in all, fairly simple approach; though I wasn't all that generous with comments in code, it is fairly straightforward.. 总之,相当简单的方法,虽然我并不那么慷慨的注释代码,这是相当简单的。

Using the application.. 使用应用程序。

Keep the camera view up where pets won't trigger it, and away from windows. Crank the volume on your speakers, and adjust application volumes through the mixer; CamAlarm has an option to push to the maximum volume when the alarm is activated, but this won't mean much if the master volume is down low.

保持相机远离宠物干扰,,并远离窗户。 扬声器的音量调到最大,通过混合器调整应用程序音量;CamAlarm有一个选项来推动最大音量时,报警被激活,但这并不意味着如果主音量下降低得多。

友情链接
版权所有 Copyright(c)2004-2021 锐英源软件
公司注册号:410105000449586 豫ICP备08007559号 最佳分辨率 1024*768
地址:郑州大学北校区院(文化路97号院)内