// 以下为主页面代码 /// <summary> /// VCL相机初始化 /// </summary> private void VclCamInit() { LogHelper.WriteLog("vcl cam init start"); foreach (var c in AIThermometerAPP.Instance().cameras_config.Cameras) { // 如果不是自动启动,所有相机的状态设为离线 if (!AIThermometerAPP.Instance().AutoStartCam()) { c.state = CamContectingState.OFFLINE; } if (c.state == CamContectingState.ONLINE && AIThermometerAPP.Instance().AutoStartCam()) { // 如果摄像头Online 开始画面 if (CameraFactory.Instance().CreateCameraStream(c.Name, c.IP, c.StreamType) == null) { c.state = CamContectingState.OFFLINE; } // TODO 画面左侧的摄像头列表改变状态 在线 不在线 错误 需要完善 // TODO 状态从c。state获取, 名称也在c.name里。 } CameraController cameraController = new CameraController(c); cameraController.SetConnectHandler(this.ConnectHandler, this.DisconnectHandler); listView.Items.Add(cameraController); ViewButtonStateChanged(c.state); } LogHelper.WriteLog("vcl cam init end : " + CameraFactory.Instance().cl.Count + " cameras ready!"); }
private void delCamButton_Click(object sender, RoutedEventArgs e) { CameraController camera = listView.SelectedItem as CameraController; if (camera == null) { return; //MessageBox.Show(Application.Current.FindResource("delCameraWarnText").ToString()); } if (camera.ConnectState() == CamContectingState.ONLINE) { ErrorWindow er = new ErrorWindow(Application.Current.FindResource("errorText").ToString(), Application.Current.FindResource("pleaseDisconnect").ToString()); er.ShowDialog(); //MessageBox.Show(Application.Current.FindResource("delCameraWarnText").ToString()); return; } MessageWindow mw = new MessageWindow(Application.Current.FindResource("delText").ToString(), Application.Current.FindResource("delText1").ToString()); mw.ShowDialog(); if (mw.DialogResult == true) { AIThermometerAPP.Instance().cameras_config.DeleteCamByName(camera.c_name); AIThermometerAPP.Instance().SaveCameraConfigs(); listView.Items.Remove(camera); } }
private void RePlayMedia(CamMode cm, string url) { LogHelper.WriteLog(cm + " stream will be restarting, path:" + url); multiPlayer[cm].SetLibPath(AIThermometerAPP.Instance().AppPath()); if (url == "") { multiPlayer[cm].SetMode(cm); } multiPlayer[cm].Init(); LogHelper.WriteLog("first start " + cm + " rstp, value=" + multiPlayer[cm].GetPath()); multiPlayer[cm].Player().OnMediaPlayerBuffering(0.02f); multiPlayer[cm].Player().Play(new Uri(multiPlayer[cm].GetPath())); multiPlayer[cm].Player().GetMedia().TrackID = multiPlayer[cm].GetPath(); multiPlayer[cm].Player().GetMedia().TrackNumber = multiPlayer[cm].GetMode().ToString(); multiPlayer[cm].Player().Playing += playing; multiPlayer[cm].Player().Buffering += buffering; multiPlayer[cm].Player().EncounteredError += StreamError; RefreshView(); /* * if (cm == CamMode.IR) * { * //multiPlayer[cm].Player().EncounteredError += StreamError; * multiPlayer[cm].Player().Buffering += buffering; * //multiPlayer[cm].Player().Stopped += StreamError; * } * //else * //multiPlayer[cm].Player().Stopped += StreamError; */ }
public VlcWindow() { InitializeComponent(); video_timeout = AIThermometerAPP.Instance().config.video_timeout; //ChangeLeft(); //SetupTest(); }
private void RealPath() { // test mode if (this.path == "127.0.0.1") { if (this.mode == CamMode.NORMAL) { this.path = "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov"; } else { this.path = AIThermometerAPP.Instance().AppPath() + "test.mp4"; } //this.path = "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov"; LogHelper.WriteLog("Local test mode! 127 0 0 1"); return; } if (this.mode == CamMode.NORMAL) { //this.path = AIThermometerAPP.Instance().AppPath() + "test.mp4"; this.path = "rtsp://" + this.path + ":8554/live.sdp"; } else if (this.mode == CamMode.IR) { //this.path = AIThermometerAPP.Instance().AppPath() + "test.mp4"; this.path = "rtsp://" + this.path + ":8555/liveultra.sdp"; } }
private static void PostToHW(object j, object i) { string ip = i as string; string json = j as string; var formDatas = new List <FormItemModel>(); //添加文本 formDatas.Add(new FormItemModel() { Key = "BlackCell-Position", Value = json // "id-test-id-test-id-test-id-test-id-test-" }); //提交表单 try { AIThermometerAPP.Instance().blackcell_pos_error = true; var result = FormPost.PostForm("http://" + ip + ":9300/config", formDatas); AIThermometerAPP.Instance().ResetBlackCell(); } catch (Exception ex) { LogHelper.WriteLog("post to hw error", ex); } }
private void BlackcellButton_Click(object sender, RoutedEventArgs e) { string shot_path = AIThermometerAPP.Instance().TmpPath() + "\\" + Guid.NewGuid().ToString() + ".jpeg"; if (!Shot(shot_path, CamMode.IR)) { ErrorWindow ew = new ErrorWindow(Application.Current.FindResource("errorText").ToString(), Application.Current.FindResource("errorText2").ToString()); ew.ShowDialog(); return; } BlackCellSettingWindow bc = new BlackCellSettingWindow(shot_path, vlcWindow.ip); if (bc.Init()) { if (bc.ShowDialog() == true) { Thread t = new Thread(new ThreadStart(new Action(() => { PostToHW(bc.POSJSON, vlcWindow.ip); } ))); t.Start(); } } }
private void Window_Loaded(object sender, RoutedEventArgs e) { if (AIThermometerAPP.Instance().AutoStartCam()) { if (CameraFactory.Instance().cl.Count > 0) { foreach (var ci in CameraFactory.Instance().cl) { this.vlcWindow.SetCamStream(ci); } } } //mc) this.vlcWindow.ChangeLeft(); // 设置全屏 this.WindowState = System.Windows.WindowState.Normal; this.WindowStyle = System.Windows.WindowStyle.None; this.ResizeMode = System.Windows.ResizeMode.NoResize; // this.Topmost = true; this.Left = 0.0; this.Top = 0.0; this.Width = System.Windows.SystemParameters.PrimaryScreenWidth; this.Height = System.Windows.SystemParameters.PrimaryScreenHeight; }
// 添加摄像头 private void addCamButton_Click(object sender, RoutedEventArgs e) { AddCameraWindow ac = new AddCameraWindow(); ac.ShowDialog(); // 点击确定的话 if (ac.DialogResult == true) { // 锁定添加 if (AIThermometerAPP.Instance().cameras_config.Cameras.Count >= 1) { ErrorWindow er = new ErrorWindow(Application.Current.FindResource("errorText").ToString(), Application.Current.FindResource("errorText1").ToString()); er.ShowDialog(); return; } Dispatcher.BeginInvoke(new Action(delegate { CameraController cameraController = new CameraController(ac.GetCameraInfo()); listView.Items.Add(cameraController); })); // 储存camera信息到系统单例,然后保存到文件 if (AIThermometerAPP.Instance().cameras_config.AddCam(ac.GetCameraInfo())) { AIThermometerAPP.Instance().SaveCameraConfigs(); LogHelper.WriteLog("Added camerainfo to camera list. And saved!"); } else { // 添加不成功 } //AIThermometerAPP.Instance().cameras_config.Cameras.Add(ac.GetCameraInfo()); } }
private void Cancel_Click(object sender, RoutedEventArgs e) { if (this.blackcell_error) { AIThermometerAPP.Instance().is_error_window_show = false; } this.Close(); //DialogResult = true; }
private void SettingButton_Click(object sender, RoutedEventArgs e) { SettingWindow settingWindow = new SettingWindow(); settingWindow.ShowDialog(); if (settingWindow.DialogResult == true) { TempWarning.Instance().SetLength(AIThermometerAPP.Instance().config.warning_bar_length); } }
public void DisconnectHandler(string ip) { this.vlcWindow.DelCamStream(); CameraFactory.Instance().DelCamStream(ip); foreach (var c in AIThermometerAPP.Instance().cameras_config.Cameras) { c.state = CamContectingState.OFFLINE; ViewButtonStateChanged(c.state); } }
public void SetLabel() { int com = AIThermometerAPP.Instance().PassFace; int high = AIThermometerAPP.Instance().NoPassFace; int total = com + high; Dispatcher.BeginInvoke(new Action(delegate { commonLabel.Content = Application.Current.FindResource("tempNormal").ToString() + com; highLabel.Content = Application.Current.FindResource("tempHigh").ToString() + high; totalLabel.Content = Application.Current.FindResource("temptotal").ToString() + total; })); }
public void ErrorWindowShow(string ti, string me) { //er = new ErrorWindow(ti, me); //StartCloseTimer(); // er.Show(); App.Current.Dispatcher.Invoke((Action)(() => { if (!AIThermometerAPP.Instance().is_error_window_show) { ErrorWindow er = new ErrorWindow(ti, me, true);// "错误", "当前版本暂时只支持一个设备"); AIThermometerAPP.Instance().is_error_window_show = true; er.Show(); } })); }
private void Window_KeyDown(object sender, KeyEventArgs e) { if (Keyboard.IsKeyDown(Key.LeftCtrl) && Keyboard.IsKeyDown(Key.LeftAlt) && Keyboard.IsKeyDown(Key.C)) { CommonOpenFileDialog dialog = new CommonOpenFileDialog(); dialog.IsFolderPicker = true;//设置为选择文件夹 if (dialog.ShowDialog() == CommonFileDialogResult.Ok) { Thread ct = new Thread((CopyDirectory)); List <string> paths = new List <string>(); paths.Add(AIThermometerAPP.Instance().CapturePath()); paths.Add(AIThermometerAPP.Instance().WarningPath()); paths.Add(dialog.FileName); ct.Start(paths); //Common.CopyDirectory(AIThermometerAPP.Instance().WarningPath(), dialog.FileName); } } }
public void ConnectHandler(string ip) { foreach (var c in AIThermometerAPP.Instance().cameras_config.Cameras) { if (c.IP == ip) { var mc = CameraFactory.Instance().CreateCameraStream(c.Name, c.IP, c.StreamType); if (mc != null) { c.state = CamContectingState.ONLINE; this.vlcWindow.SetCamStream(mc); LogHelper.WriteLog("Connect handler cl count :" + CameraFactory.Instance().cl.Count); } } ViewButtonStateChanged(c.state); } this.vlcWindow.ChangeLeft(); }
private void okButton_Click(object sender, RoutedEventArgs e) { float black_temp = 0.0f; if (float.TryParse(balckTemp.Text, out black_temp)) { if (!(black_temp >= 33 && black_temp <= 42)) { ErrorWindow ew = new ErrorWindow(Application.Current.FindResource("numError").ToString(), Application.Current.FindResource("error1").ToString()); ew.ShowDialog(); return; } } float cwl = 0.0f; if (float.TryParse(camera_warn_limit.Text, out cwl)) { if (!(cwl >= 35 && cwl <= 42)) { ErrorWindow ew = new ErrorWindow(Application.Current.FindResource("numError").ToString(), Application.Current.FindResource("error2").ToString()); ew.ShowDialog(); return; } } float fl = 0.0f; if (float.TryParse(face_limit.Text, out fl)) { if (!(fl >= 15 && fl <= 80)) { ErrorWindow ew = new ErrorWindow(Application.Current.FindResource("numError").ToString(), Application.Current.FindResource("error3").ToString()); ew.ShowDialog(); return; } } float fc = 0.0f; if (float.TryParse(face_score.Text, out fc)) { if (!(fc >= 0.2 && fc <= 1.0)) { ErrorWindow ew = new ErrorWindow(Application.Current.FindResource("numError").ToString(), Application.Current.FindResource("error4").ToString()); ew.ShowDialog(); return; } } if (ci.state == CamContectingState.ONLINE) { var formDatas = new List <FormItemModel>(); // 温度系数 formDatas.Add(new FormItemModel() { Key = "BlackCell-Temperature", Value = balckTemp.Text // "id-test-id-test-id-test-id-test-id-test-" }); formDatas.Add(new FormItemModel() { Key = "Report-URL", Value = address.Text // "id-test-id-test-id-test-id-test-id-test-" }); formDatas.Add(new FormItemModel() { Key = "Camera-Threshold", Value = camera_warn_limit.Text }); formDatas.Add(new FormItemModel() { Key = "Face-LimitSize", Value = face_limit.Text }); formDatas.Add(new FormItemModel() { Key = "Face-Score", Value = face_score.Text }); if (temp_check.IsChecked == true) { formDatas.Add(new FormItemModel() { Key = "Upgrade-Coefficient", Value = temp_value.Text }); } fi = formDatas; CameraInfo cameraInfo = new CameraInfo(); //cameraInfo.IP = ip.Text; cameraInfo.Name = ci.Name; cameraInfo.IP = ci.IP; cameraInfo.Device_Name = ci.Device_Name; cameraInfo.Date = DateTime.Now; cameraInfo.BlackCell_Temp = balckTemp.Text; cameraInfo.Report_URL = address.Text; AIThermometerAPP.Instance().cameras_config.UpdateCam(cameraInfo); AIThermometerAPP.Instance().SaveCameraConfigs(); DialogResult = true; } else { CameraInfo cameraInfo = new CameraInfo(); cameraInfo.Name = ci.Name; cameraInfo.IP = ip.Text; //.IP; //cameraInfo.Device_Name = ci.Device_Name; cameraInfo.Date = DateTime.Now; //cameraInfo.BlackCell_Temp = balckTemp.Text; //cameraInfo.Report_URL = address.Text; AIThermometerAPP.Instance().cameras_config.UpdateCam(cameraInfo); AIThermometerAPP.Instance().SaveCameraConfigs(); DialogResult = true; } }
private void CaptureFolderButton_Click(object sender, RoutedEventArgs e) { System.Diagnostics.Process.Start(AIThermometerAPP.Instance().WarningPath());//.CurrentDomain.BaseDirectory); }
private void okButton_Click(object sender, RoutedEventArgs e) { LocalSetting localSetting = new LocalSetting(); localSetting.local_url = ip.Text; try { localSetting.local_port = int.Parse(port.Text); int wn = int.Parse(warn_number.Text); int cd = int.Parse(clean_day.Text); float ts = float.Parse(threshold.Text); localSetting.camera_auto_start = (bool)autoconCheckBox.IsChecked; if (wn > 30 || wn < 10) { ErrorWindow er = new ErrorWindow("Value error", "Our of range.(10-30)"); er.ShowDialog(); return; } else if (cd < 15 || cd > 180) { ErrorWindow er = new ErrorWindow("Value error", "Our of range.(15-180)"); er.ShowDialog(); return; } else if (ts < 35 || ts > 42) { ErrorWindow er = new ErrorWindow("Value error", "Our of range.(35-42)"); er.ShowDialog(); return; } localSetting.warning_bar_length = wn; localSetting.temp_limit = ts; localSetting.clean_day = cd; } catch { ErrorWindow er = new ErrorWindow("Value error", "Input value error, Please check."); er.ShowDialog(); return; } lanageClass dic = lanageCombo.SelectedItem as lanageClass; if (dic != null) { localSetting.language = dic.key; } ErrorWindow ew = null; if (localSetting.language != _lanage) { ew = new ErrorWindow(System.Windows.Application.Current.FindResource("warn").ToString(), System.Windows.Application.Current.FindResource("warn1").ToString()); } AIThermometerAPP.Instance().config = localSetting; AIThermometerAPP.Instance().SaveConfigs(); if (ew == null) { DialogResult = true; return; } ew.ShowDialog(); System.Windows.Forms.Application.Restart(); System.Windows.Application.Current.Shutdown(); }
public SettingWindow() { InitializeComponent(); app_version.Content = "Version: " + AIThermometerAPP.Instance().GetVersion(); List <lanageClass> dicItem = new List <lanageClass>(); dicItem.Add(new lanageClass() { key = "en-US", value = "English" }); dicItem.Add(new lanageClass() { key = "zh-CN", value = "中文" }); dicItem.Add(new lanageClass() { key = "ja-JP", value = "日本語" }); //dicItem.Add(new lanageClass() { key = "ko-KR", value = "한국어" }); lanageCombo.ItemsSource = dicItem; WindowStartupLocation = WindowStartupLocation.CenterScreen; this.Topmost = true; LocalSetting localSetting = AIThermometerAPP.Instance().config; ip.Text = localSetting.local_url; port.Text = localSetting.local_port.ToString(); warn_number.Text = localSetting.warning_bar_length.ToString(); threshold.Text = localSetting.temp_limit.ToString(); clean_day.Text = localSetting.clean_day.ToString(); autoconCheckBox.IsChecked = localSetting.camera_auto_start; string lange = localSetting.language; switch (lange) { case "zh-CN": lanageCombo.SelectedIndex = 1; break; case "en-US": lanageCombo.SelectedIndex = 0; break; case "ja-JP": lanageCombo.SelectedIndex = 2; break; case "ko-KR": lanageCombo.SelectedIndex = 3; break; default: lanageCombo.SelectedIndex = 0; break; } _lanage = localSetting.language; }
private void HttpThread(object c) { var context = c as HttpListenerContext; string endPoint = context.Request.RemoteEndPoint.ToString(); int spIndex = endPoint.IndexOf(":"); endPoint = endPoint.Substring(0, spIndex); using (HttpListenerResponse response = context.Response) { if (!context.Request.HasEntityBody)//无数据 { response.StatusCode = 403; return; } string attachValue = ""; //post 的方式有文件上传的在如下解析即可得到客户端参数及值 HttpListenerRequest request = context.Request; if (request.ContentType.Length > 20 && string.Compare(request.ContentType.Substring(0, 20), "multipart/form-data;", true) == 0) { List <Values> lst = new List <Values>(); Encoding Encoding = request.ContentEncoding; string[] values = request.ContentType.Split(';').Skip(1).ToArray(); string boundary = string.Join(";", values).Replace("boundary=", "").Trim(); byte[] ChunkBoundary = Encoding.GetBytes("--" + boundary + "\r\n"); byte[] EndBoundary = Encoding.GetBytes("--" + boundary + "--\r\n"); Stream SourceStream = request.InputStream; var resultStream = new MemoryStream(); bool CanMoveNext = true; Values data = null; while (CanMoveNext) { byte[] currentChunk = ReadLineAsBytes(SourceStream); if (!Encoding.GetString(currentChunk).Equals("\r\n")) { resultStream.Write(currentChunk, 0, currentChunk.Length); } if (CompareBytes(ChunkBoundary, currentChunk)) { byte[] result = new byte[resultStream.Length - ChunkBoundary.Length]; resultStream.Position = 0; resultStream.Read(result, 0, result.Length); CanMoveNext = true; if (result.Length > 0) { data.datas = result; } data = new Values(); lst.Add(data); resultStream.Dispose(); resultStream = new MemoryStream(); } else if (Encoding.GetString(currentChunk).Contains("Content-Disposition")) { byte[] result = new byte[resultStream.Length - 2]; resultStream.Position = 0; resultStream.Read(result, 0, result.Length); CanMoveNext = true; data.name = Encoding.GetString(result).Replace("Content-Disposition: form-data; name=\"", "").Replace("\"", "").Split(';')[0]; resultStream.Dispose(); resultStream = new MemoryStream(); } else if (Encoding.GetString(currentChunk).Contains("Content-Type")) { CanMoveNext = true; data.type = 1; resultStream.Dispose(); resultStream = new MemoryStream(); } else if (CompareBytes(EndBoundary, currentChunk)) { byte[] result = new byte[resultStream.Length - EndBoundary.Length - 2]; resultStream.Position = 0; resultStream.Read(result, 0, result.Length); data.datas = result; resultStream.Dispose(); CanMoveNext = false; } } TempMessage tm = new TempMessage(); foreach (var key in lst) { if (key.type == 0) { string value = Encoding.GetString(key.datas).Replace("\r\n", ""); if (key.name == "attachValue") { attachValue = value; } } if (key.type == 1) { tm.bytes = key.datas; /* * FileStream fs = new FileStream("c:\\3.jpg", FileMode.Create); * fs.Write(key.datas, 0, key.datas.Length); * fs.Close(); * fs.Dispose(); */ } } LogHelper.WriteLog(attachValue); CameraWarning items = JsonHelper.FromJSON <CameraWarning>(attachValue); tm.cam = AIThermometerAPP.Instance().cameras_config.GetNameByIP(endPoint); if (items.Code == 0 && !AIThermometerAPP.Instance().blackcell_pos_error) { tm.temp = items.Reports[0].Temperature; tm.id = items.Reports[0].objId; tm.date = DateTime.Now; string file_name = tm.date.ToString("yyMMdd") + "\\"; if (tm.temp > AIThermometerAPP.Instance().TempLimit()) { file_name = file_name + "nopass\\"; AIThermometerAPP.Instance().AddNoPassFace(); VoicePlayer.Instance().Play(); } else { file_name = file_name + "pass\\"; AIThermometerAPP.Instance().AddPassFace(); } if (AIThermometerAPP.Instance().CanCapture()) { captureHandler?.Invoke(AIThermometerAPP.Instance().CapturePath() + "\\" + DateTime.Now.ToString("yyMMddHHmmssffff") + ".jpeg", CamMode.NORMAL); } Common.CreateDir(image_dir_path + "\\" + file_name); file_name = file_name + tm.date.ToString("HHmmssffff") + tm.temp.ToString().Replace(".", "_") + ".jpeg"; tm.photo_path = image_dir_path + "\\" + file_name; TempWarning.Instance().Push(tm); } else { // 黑体位置错误 if (!AIThermometerAPP.Instance().blackcell_pos_error) { AIThermometerAPP.Instance().blackcell_pos_error = true; ewHandler?.Invoke(Application.Current.FindResource("errorText").ToString(), Application.Current.FindResource("error8").ToString()); AIThermometerAPP.Instance().ResetBlackCell(); } } } response.ContentType = "text/html;charset=utf-8"; response.StatusCode = 200; return; try { using (System.IO.Stream output = response.OutputStream) using (StreamWriter writer = new StreamWriter(output, Encoding.UTF8)) writer.WriteLine("接收完成!"); } catch { } response.Close(); } }