如何设计一个视频监控系统(用C#实现)急!
你好:我一个同学要做关于室内视频监控的系统,请我帮忙,可是我也是不会.
大概的需求是:用一台电脑,当系统运行时摄像头抓拍一张室内原图,然后每过一定时间再次抓图,然后对比两张图,如果不一样,系统就自动在本机报警(方式自选),然后把报警情况通过网络传送到其他电脑上.
我大致想了一下,觉得第一是解决如何把系统连接摄像头并抓图,第二抓图以后保存,
第三,如何对比前后两张图的差别,这里好象是把图象转化为灰度图然后对比.
第四,如何远程报警.
我现在仅仅找到了一个关于设像头视频采集的方法:
但是我自己没有设像头无法实验,另外下面的代码也是不完整的我补了一部分已经标注了,希望你帮我看看如何完成以下C#代码程序:
//本文是借助avicap32.dll库来驱动摄像头。做到了抓图功能。
using System;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;
namespace using System;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;
namespace PickHead
{
/// <summary>
/// 一个控制摄像头的类
/// </summary>
public class Pick
{
private const int WM_USER = 0x400;
private const int WS_CHILD = 0x40000000;
private const int WS_VISIBLE = 0x10000000;
private const int WM_CAP_START = WM_USER;
private const int WM_CAP_STOP = WM_CAP_START + 68;
private const int WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10;
private const int WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11;
private const int WM_CAP_SAVEDIB = WM_CAP_START + 25;
private const int WM_CAP_GRAB_FRAME = WM_CAP_START + 60;
private const int WM_CAP_SEQUENCE = WM_CAP_START + 62;
private const int WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START + 20;
private const int WM_CAP_SEQUENCE_NOFILE =WM_CAP_START+ 63;
private const int WM_CAP_SET_OVERLAY =WM_CAP_START+ 51;
private const int WM_CAP_SET_PREVIEW =WM_CAP_START+ 50;
private const int WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START +6;
private const int WM_CAP_SET_CALLBACK_ERROR=WM_CAP_START +2;
private const int WM_CAP_SET_CALLBACK_STATUSA= WM_CAP_START +3;
private const int WM_CAP_SET_CALLBACK_FRAME= WM_CAP_START +5;
private const int WM_CAP_SET_SCALE=WM_CAP_START+ 53;
private const int WM_CAP_SET_PREVIEWRATE=WM_CAP_START+ 52;
private IntPtr hWndC;
private bool bStat = false;
private IntPtr mControlPtr;
private int mWidth;
private int mHeight;
private int mLeft;
private int mTop;
/// <summary>
/// 初始化摄像头
/// </summary>
/// <param name="handle">控件的句柄</param>
/// <param name="left">开始显示的左边距</param>
/// <param name="top">开始显示的上边距</param>
/// <param name="width">要显示的宽度</param>
/// <param name="height">要显示的长度</param>
public Pick(IntPtr handle, int left, int top, int width,int height)
{
mControlPtr = handle;
mWidth = width;
mHeight = height;
mLeft = left;
mTop = top;
}
[DllImport("avicap32.dll")]
private static extern IntPtr capCreateCaptureWindowA(byte[] lpszWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, int nID);
[DllImport("avicap32.dll")]
private static extern int capGetVideoFormat(IntPtr hWnd, IntPtr psVideoFormat, int wSize );
[DllImport("User32.dll")]
private static extern bool SendMessage(IntPtr hWnd, int wMsg, int wParam, long lParam);
/// 开始显示图像
public void Start()
{
if (bStat)
return;
bStat = true;
byte[] lpszName = new byte[100];
hWndC = capCreateCaptureWindowA(lpszName,WS_CHILD|WS_VISIBLE ,mLeft,mTop,mWidth,mHeight,mControlPtr,0);
if (hWndC.ToInt32() != 0)
{
SendMessage(hWndC, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0);
SendMessage(hWndC, WM_CAP_SET_CALLBACK_ERROR, 0, 0);
SendMessage(hWndC, WM_CAP_SET_CALLBACK_STATUSA, 0, 0);
SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0);
SendMessage(hWndC, WM_CAP_SET_SCALE, 1, 0);
SendMessage(hWndC, WM_CAP_SET_PREVIEWRATE, 66, 0);
SendMessage(hWndC, WM_CAP_SET_OVERLAY, 1, 0);
SendMessage(hWndC, WM_CAP_SET_PREVIEW, 1, 0);
}
return;
}
/// 停止显示
public void Stop()
{
SendMessage(hWndC, WM_CAP_DRIVER_DISCONNECT, 0, 0);
bStat = false;
}
/// 抓图
/// <param name="path">要保存bmp文件的路径</param>
public void GrabImage(string path)
{
IntPtr hBmp = Marshal.StringToHGlobalAnsi(path);
SendMessage(hWndC,WM_CAP_SAVEDIB,0,hBmp.ToInt64());
}
}
}
public class Working //这个类是我自己加的
{ static void Main()
{Pick a=new Pick();//需要参数可我不知道IntPtr handle该怎么写?
a.Start();
a. GrabImage("C:\");
}
}
另外你是否能对这个系统的设计提出一些意见或建议,还有你能帮我介绍一些有关方面经验的高手吗?
谢谢!
--------------------编程问答-------------------- 建议你以fms来实现图像处理,而以c#来实现图像的识别和报警。 --------------------编程问答-------------------- 只能帮顶了 --------------------编程问答-------------------- 呵呵,调用OpenCV吧,蛮快的 --------------------编程问答-------------------- up --------------------编程问答-------------------- UPUP --------------------编程问答-------------------- 现成的:
http://www.codeproject.com/csharp/motion_detection.asp --------------------编程问答-------------------- 这涉及到移动监测的事情 不过不是太难 我开发过海康卡的程序 那里有现成的 sdk --------------------编程问答-------------------- 感觉不如装个移动探头更有效 --------------------编程问答-------------------- up --------------------编程问答-------------------- 友情帮顶
补充:.NET技术 , C#