日期:2014-05-17 浏览次数:20889 次
先上图片,看看效果
首先是wp有自带的mjpeg解码功能
能输出WriteableBitmap格式,方便接下来进行图像分析
速度还行,最大也只是100多MS的延迟
接收图像方法
public void recVideo()
{
string sourceURL = "图片流地址";
while (true)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(new Uri(sourceURL));
req.BeginGetResponse(new AsyncCallback(resResult), req);
//Thread.Sleep(10);
}
}
异步调用方法
private void resResult(IAsyncResult ir)
{
try
{
HttpWebRequest req = ir.AsyncState as HttpWebRequest;
WebResponse resp = req.EndGetResponse(ir);
Stream stream = resp.GetResponseStream();
Dispatcher.BeginInvoke(() =>
{
WriteableBitmap myBitmap = PictureDecoder.DecodeJpeg(stream); 这里就是自带的解码方法,一句话就行了,如果只要实现视频输出,下面图像识别就可以删掉了
image1.Source = myBitmap;
#region 图像识别
var w = myBitmap.PixelWidth;
var h = myBitmap.PixelHeight;
if (_pixelDataGray == null || _pixelDataGray.Length != h * w)
{
//定义了几个数组
_pixelDataGray = new byte[w / _downsampleFactor * h / _downsampleFactor];
_pixelDataDownsampled =
new byte[w / _downsampleFactor * h / _downsampleFactor];
_pixelDataGrayInt = new int[w / _downsampleFactor * h / _