c#链接摄像头 ,照相录像存储
2021-05-20 02:29
标签:NPU created buffer 录制 dispatch mod patch tick inpu c#链接摄像头 ,照相录像存储 标签:NPU created buffer 录制 dispatch mod patch tick inpu 原文地址:https://www.cnblogs.com/yufei66/p/11323011.html
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
{
///
/// MainWindow.xaml 的交互逻辑
///
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
chushihua();
}
CameraPTZ ptz = new CameraPTZ();
VideoFileWriter video = new VideoFileWriter();
DispatcherTimer timer = new DispatcherTimer();
private void chushihua()
{
camera.OnFrameChanged += Camera_OnFrameChanged;//接收摄像头图像帧,打开摄像头,会触发接收每一帧字节数据。
ptz.Host = "172.16.11.12";
ptz.UserName = "admin";
ptz.Password = "admin";
ptz.Args = "/web/cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=[PTZ]";
}
private byte [] source = null;
private void Camera_OnFrameChanged(object sender, byte[] buffer)
{
if(buffer!=null&&buffer.Length>0)
{
Application.Current.Dispatcher.Invoke(()=>
{
if(video.IsOpened)
{
video.Write(buffer);
}
img.Source = tobitmap(buffer);
});
}
}
{
BitmapImage bmp = null;
try
{
bmp = new BitmapImage();
bmp.BeginInit();
bmp.CacheOption = BitmapCacheOption.OnLoad;
bmp.StreamSource = new MemoryStream(data);
bmp.EndInit();
bmp.Freeze();
}catch
{
return null;
}
return bmp;
}
{
camera.Open("rtsp://admin:admin@172.16.11.12/11");
}
{
string file = AppDomain.CurrentDomain.BaseDirectory + "imga";
if(!Directory.Exists(file))
{
Directory.CreateDirectory(file);
}
string name = file + "//" + time.Minute + "分" + time.Second + "秒" + ".jpg";
FileStream fs = new FileStream(name,FileMode.Create);
fs.Write(source,0,source.Length);
fs.Close();
}
{
ptz.TurnRight();
}
private void button3_Click(object sender, RoutedEventArgs e)
{
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += Timer_Tick;
timer.Start();
string file = AppDomain.CurrentDomain.BaseDirectory + "video";
if(!Directory.Exists(file))
{
Directory.CreateDirectory(file);
}
DateTime time = DateTime.Now;
string name = file + "//" + time.Minute + "分" + ".avi";
video.Open(name,640,480,15,VideoCodes.MPEG4);
}
int count = 0;
private void Timer_Tick(object sender, EventArgs e)
{
if(count>5)
{
video.Close();
MessageBox.Show("录制结束");
}
else
{
count++;
}
}
{
video.Close();
}
}
}
上一篇:qtmaind.lib(qtmain_win.obj) : error LNK2019: 无法解析的外部符号 __imp_CommandLineToArgvW,该符号在函数 WinMain 中被引用