diff --git a/ISCamRecorder/MainForm.Designer.cs b/ISCamRecorder/MainForm.Designer.cs index 8226813..5c63283 100644 --- a/ISCamRecorder/MainForm.Designer.cs +++ b/ISCamRecorder/MainForm.Designer.cs @@ -101,6 +101,7 @@ this.splitContainer1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); + this.splitContainer1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.splitContainer1.Location = new System.Drawing.Point(0, 60); this.splitContainer1.Name = "splitContainer1"; this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal; @@ -119,6 +120,7 @@ // // splitContainer2 // + this.splitContainer2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill; this.splitContainer2.Location = new System.Drawing.Point(0, 0); this.splitContainer2.Name = "splitContainer2"; @@ -144,7 +146,7 @@ this.TxtCvCamera.Location = new System.Drawing.Point(3, 3); this.TxtCvCamera.Name = "TxtCvCamera"; this.TxtCvCamera.ReadOnly = true; - this.TxtCvCamera.Size = new System.Drawing.Size(330, 19); + this.TxtCvCamera.Size = new System.Drawing.Size(328, 19); this.TxtCvCamera.TabIndex = 3; this.TxtCvCamera.Text = "近接カメラ"; // @@ -155,13 +157,14 @@ | System.Windows.Forms.AnchorStyles.Right))); this.PicCvCamera.Location = new System.Drawing.Point(3, 28); this.PicCvCamera.Name = "PicCvCamera"; - this.PicCvCamera.Size = new System.Drawing.Size(330, 218); + this.PicCvCamera.Size = new System.Drawing.Size(328, 216); this.PicCvCamera.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; this.PicCvCamera.TabIndex = 0; this.PicCvCamera.TabStop = false; // // splitContainer3 // + this.splitContainer3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.splitContainer3.Dock = System.Windows.Forms.DockStyle.Fill; this.splitContainer3.Location = new System.Drawing.Point(0, 0); this.splitContainer3.Name = "splitContainer3"; @@ -188,7 +191,7 @@ this.TxtTop.Location = new System.Drawing.Point(4, 3); this.TxtTop.Name = "TxtTop"; this.TxtTop.ReadOnly = true; - this.TxtTop.Size = new System.Drawing.Size(329, 19); + this.TxtTop.Size = new System.Drawing.Size(327, 19); this.TxtTop.TabIndex = 2; // // icTop @@ -203,7 +206,7 @@ this.icTop.LiveDisplayPosition = new System.Drawing.Point(0, 0); this.icTop.Location = new System.Drawing.Point(4, 28); this.icTop.Name = "icTop"; - this.icTop.Size = new System.Drawing.Size(331, 218); + this.icTop.Size = new System.Drawing.Size(329, 216); this.icTop.TabIndex = 1; // // TxtSensor @@ -214,7 +217,7 @@ this.TxtSensor.Location = new System.Drawing.Point(3, 3); this.TxtSensor.Name = "TxtSensor"; this.TxtSensor.ReadOnly = true; - this.TxtSensor.Size = new System.Drawing.Size(331, 19); + this.TxtSensor.Size = new System.Drawing.Size(329, 19); this.TxtSensor.TabIndex = 3; this.TxtSensor.Text = "逆血センサー"; // @@ -266,12 +269,13 @@ this.chart1.Series.Add(series1); this.chart1.Series.Add(series2); this.chart1.Series.Add(series3); - this.chart1.Size = new System.Drawing.Size(329, 220); + this.chart1.Size = new System.Drawing.Size(327, 218); this.chart1.TabIndex = 0; this.chart1.Text = "chart1"; // // splitContainer4 // + this.splitContainer4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.splitContainer4.Dock = System.Windows.Forms.DockStyle.Fill; this.splitContainer4.Location = new System.Drawing.Point(0, 0); this.splitContainer4.Name = "splitContainer4"; @@ -297,7 +301,7 @@ this.TxtLeft.Location = new System.Drawing.Point(3, 3); this.TxtLeft.Name = "TxtLeft"; this.TxtLeft.ReadOnly = true; - this.TxtLeft.Size = new System.Drawing.Size(328, 19); + this.TxtLeft.Size = new System.Drawing.Size(326, 19); this.TxtLeft.TabIndex = 4; // // icLeft @@ -312,11 +316,12 @@ this.icLeft.LiveDisplayPosition = new System.Drawing.Point(0, 0); this.icLeft.Location = new System.Drawing.Point(3, 28); this.icLeft.Name = "icLeft"; - this.icLeft.Size = new System.Drawing.Size(331, 213); + this.icLeft.Size = new System.Drawing.Size(329, 211); this.icLeft.TabIndex = 3; // // splitContainer5 // + this.splitContainer5.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.splitContainer5.Dock = System.Windows.Forms.DockStyle.Fill; this.splitContainer5.Location = new System.Drawing.Point(0, 0); this.splitContainer5.Name = "splitContainer5"; @@ -343,7 +348,7 @@ this.TxtFront.Location = new System.Drawing.Point(3, 3); this.TxtFront.Name = "TxtFront"; this.TxtFront.ReadOnly = true; - this.TxtFront.Size = new System.Drawing.Size(329, 19); + this.TxtFront.Size = new System.Drawing.Size(327, 19); this.TxtFront.TabIndex = 10; // // icFront @@ -358,7 +363,7 @@ this.icFront.LiveDisplayPosition = new System.Drawing.Point(0, 0); this.icFront.Location = new System.Drawing.Point(3, 28); this.icFront.Name = "icFront"; - this.icFront.Size = new System.Drawing.Size(330, 213); + this.icFront.Size = new System.Drawing.Size(328, 211); this.icFront.TabIndex = 9; // // TxtRight @@ -369,7 +374,7 @@ this.TxtRight.Location = new System.Drawing.Point(1, 3); this.TxtRight.Name = "TxtRight"; this.TxtRight.ReadOnly = true; - this.TxtRight.Size = new System.Drawing.Size(331, 19); + this.TxtRight.Size = new System.Drawing.Size(329, 19); this.TxtRight.TabIndex = 11; // // icRight @@ -384,7 +389,7 @@ this.icRight.LiveDisplayPosition = new System.Drawing.Point(0, 0); this.icRight.Location = new System.Drawing.Point(1, 28); this.icRight.Name = "icRight"; - this.icRight.Size = new System.Drawing.Size(331, 213); + this.icRight.Size = new System.Drawing.Size(329, 211); this.icRight.TabIndex = 5; // // BtnRecodeMovie diff --git a/ISCamRecorder/MainForm.cs b/ISCamRecorder/MainForm.cs index 5beaeac..9b93aaf 100644 --- a/ISCamRecorder/MainForm.cs +++ b/ISCamRecorder/MainForm.cs @@ -33,20 +33,20 @@ public partial class MainForm : Form { readonly int PLOT_LENGTH = 200; // センサー値表示サンプル数 - readonly int UI_UPDATE_INTERVAL = 2000; // UI更新時間 + readonly int UI_UPDATE_INTERVAL = 500; // UI更新時間(ms) readonly int CVCAMERA_ID = 0; // 追加カメラのID readonly int CVCAMERA_WIDTH = 1920; // 追加カメラの画像幅 readonly int CVCAMERA_HEIGHT = 1080; // 追加カメラの画像高さ - private System.Threading.Timer _UITimer; // UI更新タイマー - List _Cameras = new List (); // ISカメラオブジェクト + System.Threading.Timer _UITimer; // UI更新タイマー + List _Cameras; // ISカメラオブジェクト SensorData _Sensor; // センサーオブジェクト CvCamera _CvCamera; // Cvカメラオブジェクト Task _TriggerThread; // トリガースレッド Task _SerialThread; // シリアル通信スレッド Task _CvCameraThread; // opencvカメラスレッド Task _RecodingThread; // 録画スレッド - List _Sounds = new List (); + List _Sounds; // 音源オブジェクト public Setting Setting { get; private set; } // 設定ダイアログ public Chart SensorChart { get { return chart1; } } // 外部からのアクセス用 @@ -62,9 +62,11 @@ public MainForm() { MediaFoundationApi.Startup(); InitializeComponent(); + _Cameras = new List(); _Sensor = new SensorData(this, PLOT_LENGTH); _CvCamera = new CvCamera(this); Setting = new Setting(); + _Sounds = new List(); _Sounds.Add(new SoundPlayer(@"StartRecoding.wav")); _Sounds.Add(new SoundPlayer(@"StopRecoding.wav")); _Sounds.Add(new SoundPlayer(@"EndSaving.wav")); @@ -98,15 +100,17 @@ #if DEBUG TxtSubjectName.Text = "デバッグ"; #endif - this.UpdateStateLabel(); + this.UpdateControlState(); } /// /// ソフトウェアトリガー生成スレッド + /// UI更新も行う /// private void TriggerThread() { var swatch = new Stopwatch(); swatch.Start(); + var lastUIUpdate = DateTime.Now; while (State != STATE.Exit) { var interval = (long)(1000F / Setting.SWTriggerFPS); @@ -115,6 +119,13 @@ } swatch.Restart(); _Cameras.ForEach(c => c.SWTrigger()); + + // UI更新 + var now = DateTime.Now; + if ((now - lastUIUpdate).TotalMilliseconds > UI_UPDATE_INTERVAL) { + this.UpdateTextInfo(); + lastUIUpdate = now; + } } } @@ -140,35 +151,36 @@ /// static void UITimerCB(object obj) { if (((MainForm)obj).State == STATE.Exit) return; - ((MainForm)obj).UpdateForm(); + //((MainForm)obj).UpdateTextInfo(); } /// /// UI更新 /// - public void UpdateForm() { - if (this.InvokeRequired) { - this.Invoke((MethodInvoker)delegate { UpdateForm(); }); - return; - } - if (State != STATE.Exit) { + public void UpdateTextInfo() { + if (State == STATE.Exit) return; + this.Invoke((MethodInvoker)delegate { TxtTop.Text = $"上方カメラ {_Cameras[0].CameraInfo()}"; TxtLeft.Text = $"左方カメラ {_Cameras[1].CameraInfo()}"; TxtFront.Text = $"前方カメラ {_Cameras[2].CameraInfo()}"; TxtRight.Text = $"右方カメラ {_Cameras[3].CameraInfo()}"; TxtSensor.Text = $"逆血センサー {_Sensor.FrameRate:0.0} Hz"; TxtCvCamera.Text = $"追加カメラ {_CvCamera.CameraInfo()}"; - if (State == STATE.Init && _CvCamera.CurrentFPS>0) { + if (State == STATE.Init && _CvCamera.CurrentFPS > 0) { State = STATE.Idle; - this.UpdateStateLabel(); + this.UpdateControlState(); } - } + if (State == STATE.Recoding) { + var elapse = DateTime.Now - RecodingTime; + LblState.Text = $"録画中 {elapse.TotalSeconds:0}s"; + } + }); } /// /// 状態表示の更新 /// - private void UpdateStateLabel() { + private void UpdateControlState() { switch (State) { case STATE.Init: LblState.Text = "初期化中"; @@ -195,7 +207,7 @@ TxtCounter.ReadOnly = false; break; case STATE.Recoding: - LblState.Text = "録画中"; + LblState.Text = $"録画中"; PnlState.BackColor = Color.OrangeRed; BtnRecodeMovie.Text = $"{ButtonSymbol(Setting.ACTION.movie)}停止"; BtnRecodeMovie.Enabled = true; @@ -246,11 +258,11 @@ for (var i = 0; i < _Cameras.Count; i++) { if (Setting.RecCameras[i]) _Cameras[i].ChangeSink(true); } + RecodingTime = DateTime.Now; + Directory.CreateDirectory(OutputDir); State = STATE.Recoding; - this.UpdateStateLabel(); + this.UpdateControlState(); }); - RecodingTime = DateTime.Now; - Directory.CreateDirectory(OutputDir); // 録画 Task[] tasks = new Task[_Cameras.Count]; @@ -268,7 +280,7 @@ _Sounds[1].Play(); this.Invoke((MethodInvoker)delegate { State = STATE.Saving; - this.UpdateStateLabel(); + this.UpdateControlState(); }); // 保存 @@ -291,7 +303,7 @@ } TxtCounter.Text = (int.Parse(TxtCounter.Text) + 1).ToString(); State = STATE.Idle; - this.UpdateStateLabel(); + this.UpdateControlState(); }); _Sounds[2].Play(); Debug.WriteLine("_RecodingThread ends"); @@ -393,7 +405,7 @@ Setting.ShowDialog(); - this.UpdateStateLabel(); + this.UpdateControlState(); if (Setting.SWTrigger != lastTriggerSetting) { _Cameras.ForEach(c => c.SetTriggerMode(Setting.SWTrigger)); } diff --git a/ISCamRecorder/Setting.Designer.cs b/ISCamRecorder/Setting.Designer.cs index 1a7d85e..5adaba6 100644 --- a/ISCamRecorder/Setting.Designer.cs +++ b/ISCamRecorder/Setting.Designer.cs @@ -75,7 +75,7 @@ // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(6, 72); + this.label3.Location = new System.Drawing.Point(7, 63); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(41, 12); this.label3.TabIndex = 16; @@ -85,7 +85,7 @@ // this.TxtOutputDir.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.TxtOutputDir.Location = new System.Drawing.Point(53, 69); + this.TxtOutputDir.Location = new System.Drawing.Point(54, 60); this.TxtOutputDir.Name = "TxtOutputDir"; this.TxtOutputDir.Size = new System.Drawing.Size(274, 19); this.TxtOutputDir.TabIndex = 15; @@ -100,7 +100,7 @@ this.groupBox1.Controls.Add(this.TxtOutputDir); this.groupBox1.Location = new System.Drawing.Point(10, 12); this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(343, 145); + this.groupBox1.Size = new System.Drawing.Size(343, 122); this.groupBox1.TabIndex = 17; this.groupBox1.TabStop = false; this.groupBox1.Text = "全体設定"; @@ -149,7 +149,7 @@ // label4 // this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(163, 110); + this.label4.Location = new System.Drawing.Point(161, 95); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(21, 12); this.label4.TabIndex = 34; @@ -158,7 +158,7 @@ // TxtTriggerFPS // this.TxtTriggerFPS.Enabled = false; - this.TxtTriggerFPS.Location = new System.Drawing.Point(123, 107); + this.TxtTriggerFPS.Location = new System.Drawing.Point(121, 92); this.TxtTriggerFPS.Name = "TxtTriggerFPS"; this.TxtTriggerFPS.Size = new System.Drawing.Size(34, 19); this.TxtTriggerFPS.TabIndex = 33; @@ -168,7 +168,7 @@ // ChkTrigger // this.ChkTrigger.AutoSize = true; - this.ChkTrigger.Location = new System.Drawing.Point(8, 109); + this.ChkTrigger.Location = new System.Drawing.Point(6, 94); this.ChkTrigger.Name = "ChkTrigger"; this.ChkTrigger.Size = new System.Drawing.Size(109, 16); this.ChkTrigger.TabIndex = 32; @@ -201,7 +201,7 @@ // BtnApply // this.BtnApply.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.BtnApply.Location = new System.Drawing.Point(408, 416); + this.BtnApply.Location = new System.Drawing.Point(408, 373); this.BtnApply.Name = "BtnApply"; this.BtnApply.Size = new System.Drawing.Size(93, 31); this.BtnApply.TabIndex = 18; @@ -212,7 +212,7 @@ // BtnCancel // this.BtnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.BtnCancel.Location = new System.Drawing.Point(507, 416); + this.BtnCancel.Location = new System.Drawing.Point(507, 373); this.BtnCancel.Name = "BtnCancel"; this.BtnCancel.Size = new System.Drawing.Size(93, 31); this.BtnCancel.TabIndex = 19; @@ -238,7 +238,7 @@ this.groupBox2.Controls.Add(this.ChkRecLeft); this.groupBox2.Controls.Add(this.ChkRecTop); this.groupBox2.Controls.Add(this.label9); - this.groupBox2.Location = new System.Drawing.Point(10, 177); + this.groupBox2.Location = new System.Drawing.Point(10, 149); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(343, 156); this.groupBox2.TabIndex = 20; @@ -411,9 +411,9 @@ this.groupBox3.Controls.Add(this.ChkSnapTop); this.groupBox3.Controls.Add(this.label7); this.groupBox3.Controls.Add(this.label10); - this.groupBox3.Location = new System.Drawing.Point(10, 351); + this.groupBox3.Location = new System.Drawing.Point(10, 323); this.groupBox3.Name = "groupBox3"; - this.groupBox3.Size = new System.Drawing.Size(343, 97); + this.groupBox3.Size = new System.Drawing.Size(343, 84); this.groupBox3.TabIndex = 21; this.groupBox3.TabStop = false; this.groupBox3.Text = "静止画撮影設定"; @@ -483,7 +483,7 @@ this.groupBox4.Controls.Add(this.label12); this.groupBox4.Location = new System.Drawing.Point(369, 12); this.groupBox4.Name = "groupBox4"; - this.groupBox4.Size = new System.Drawing.Size(231, 371); + this.groupBox4.Size = new System.Drawing.Size(231, 352); this.groupBox4.TabIndex = 22; this.groupBox4.TabStop = false; this.groupBox4.Text = "被験者設定"; @@ -498,7 +498,7 @@ this.TxtSubjectList.Multiline = true; this.TxtSubjectList.Name = "TxtSubjectList"; this.TxtSubjectList.ScrollBars = System.Windows.Forms.ScrollBars.Both; - this.TxtSubjectList.Size = new System.Drawing.Size(211, 304); + this.TxtSubjectList.Size = new System.Drawing.Size(211, 285); this.TxtSubjectList.TabIndex = 2; // // label12 @@ -514,7 +514,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(612, 459); + this.ClientSize = new System.Drawing.Size(612, 416); this.ControlBox = false; this.Controls.Add(this.groupBox4); this.Controls.Add(this.groupBox3); diff --git a/ISCamRecorder/Setting.cs b/ISCamRecorder/Setting.cs index 5231bc7..6ea15b5 100644 --- a/ISCamRecorder/Setting.cs +++ b/ISCamRecorder/Setting.cs @@ -32,8 +32,8 @@ /// public Setting() { InitializeComponent(); - ImageType = "jpg"; - FrameType = "tif"; + ImageType = "tif"; + FrameType = "jpg"; SWTrigger = false; SWTriggerFPS = 40F; ButtonAction = ACTION.movie;