diff --git a/ISCamRecorder/ISCamRecorder.csproj b/ISCamRecorder/ISCamRecorder.csproj index 2df358e..45d984e 100644 --- a/ISCamRecorder/ISCamRecorder.csproj +++ b/ISCamRecorder/ISCamRecorder.csproj @@ -53,6 +53,7 @@ true + diff --git a/ISCamRecorder/ISCamera.cs b/ISCamRecorder/ISCamera.cs index 73ece90..72ba49d 100644 --- a/ISCamRecorder/ISCamera.cs +++ b/ISCamRecorder/ISCamera.cs @@ -152,5 +152,17 @@ public string CameraInfo() { return $"({_SerialNumber}) {_Fps.FrameRate:0.0}fps"; } + + /// + /// 1秒録画に要するメモリ量 + /// + /// + public float MemoryFor1SecRecoding() { + if (!_Cam.DeviceValid) return 0; + var vf = _Cam.VideoFormatCurrent; + int frameSize = vf.BitsPerPixel / 8 * vf.Width * vf.Height; + int bcs = 1024 * 1024; + return _Fps.FrameRate * frameSize / bcs; + } } } diff --git a/ISCamRecorder/MainForm.Designer.cs b/ISCamRecorder/MainForm.Designer.cs index f02d6b1..decd744 100644 --- a/ISCamRecorder/MainForm.Designer.cs +++ b/ISCamRecorder/MainForm.Designer.cs @@ -38,6 +38,14 @@ this.icFront = new TIS.Imaging.ICImagingControl(); this.TxtRight = new System.Windows.Forms.TextBox(); this.icRight = new TIS.Imaging.ICImagingControl(); + this.TxtRecodingDulation = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.LblAvailableMemory = new System.Windows.Forms.Label(); + this.LblRecodingMemory = new System.Windows.Forms.Label(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.BtnRecodeMovie = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); @@ -66,16 +74,16 @@ // this.button2.Location = new System.Drawing.Point(12, 12); this.button2.Name = "button2"; - this.button2.Size = new System.Drawing.Size(102, 42); + this.button2.Size = new System.Drawing.Size(75, 34); this.button2.TabIndex = 5; - this.button2.Text = "Property"; + this.button2.Text = "プロパティ"; this.button2.UseVisualStyleBackColor = true; this.button2.Click += new System.EventHandler(this.SetProperty_Click); // // ChkTrigger // this.ChkTrigger.AutoSize = true; - this.ChkTrigger.Location = new System.Drawing.Point(120, 26); + this.ChkTrigger.Location = new System.Drawing.Point(93, 22); this.ChkTrigger.Name = "ChkTrigger"; this.ChkTrigger.Size = new System.Drawing.Size(83, 16); this.ChkTrigger.TabIndex = 6; @@ -264,19 +272,99 @@ 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(291, 213); + this.icRight.Size = new System.Drawing.Size(288, 213); this.icRight.TabIndex = 5; // + // TxtRecodingDulation + // + this.TxtRecodingDulation.Location = new System.Drawing.Point(187, 27); + this.TxtRecodingDulation.Name = "TxtRecodingDulation"; + this.TxtRecodingDulation.Size = new System.Drawing.Size(34, 19); + this.TxtRecodingDulation.TabIndex = 8; + this.TxtRecodingDulation.Text = "15"; + this.TxtRecodingDulation.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + this.TxtRecodingDulation.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TxtRecodingDulation_KeyPress); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(185, 12); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(53, 12); + this.label1.TabIndex = 9; + this.label1.Text = "記録時間"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(221, 30); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(17, 12); + this.label2.TabIndex = 10; + this.label2.Text = "秒"; + // + // LblAvailableMemory + // + this.LblAvailableMemory.AutoSize = true; + this.LblAvailableMemory.Location = new System.Drawing.Point(258, 12); + this.LblAvailableMemory.Name = "LblAvailableMemory"; + this.LblAvailableMemory.Size = new System.Drawing.Size(101, 12); + this.LblAvailableMemory.TabIndex = 11; + this.LblAvailableMemory.Text = "利用可能物理メモリ"; + // + // LblRecodingMemory + // + this.LblRecodingMemory.AutoSize = true; + this.LblRecodingMemory.Location = new System.Drawing.Point(258, 30); + this.LblRecodingMemory.Name = "LblRecodingMemory"; + this.LblRecodingMemory.Size = new System.Drawing.Size(96, 12); + this.LblRecodingMemory.TabIndex = 12; + this.LblRecodingMemory.Text = "消費する物理メモリ"; + // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(523, 27); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(235, 19); + this.textBox1.TabIndex = 13; + this.textBox1.Text = "D:\\usr\\DL"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(521, 12); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(41, 12); + this.label3.TabIndex = 14; + this.label3.Text = "保存先"; + // + // BtnRecodeMovie + // + this.BtnRecodeMovie.Location = new System.Drawing.Point(443, 12); + this.BtnRecodeMovie.Name = "BtnRecodeMovie"; + this.BtnRecodeMovie.Size = new System.Drawing.Size(74, 34); + this.BtnRecodeMovie.TabIndex = 15; + this.BtnRecodeMovie.Text = "動画撮影"; + this.BtnRecodeMovie.UseVisualStyleBackColor = true; + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(892, 555); + this.Controls.Add(this.BtnRecodeMovie); + this.Controls.Add(this.label3); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.LblRecodingMemory); + this.Controls.Add(this.LblAvailableMemory); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.TxtRecodingDulation); this.Controls.Add(this.splitContainer1); this.Controls.Add(this.ChkTrigger); this.Controls.Add(this.button2); this.Name = "MainForm"; - this.Text = "マルチカメラ撮影ソフトウェア by フロンティア医工学センター"; + this.Text = "マルチカメラ撮影ソフトウェア by 千葉大学フロンティア医工学センター"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing); this.Load += new System.EventHandler(this.MainForm_Load); this.SizeChanged += new System.EventHandler(this.MainForm_SizeChanged); @@ -327,6 +415,14 @@ private System.Windows.Forms.TextBox TxtLeft; private System.Windows.Forms.TextBox TxtFront; private System.Windows.Forms.TextBox TxtRight; + private System.Windows.Forms.TextBox TxtRecodingDulation; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label LblAvailableMemory; + private System.Windows.Forms.Label LblRecodingMemory; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Button BtnRecodeMovie; } } diff --git a/ISCamRecorder/MainForm.cs b/ISCamRecorder/MainForm.cs index ea29953..8f6bbb5 100644 --- a/ISCamRecorder/MainForm.cs +++ b/ISCamRecorder/MainForm.cs @@ -15,6 +15,7 @@ private System.Threading.Timer _UITimer; List _Cameras = new List (); // カメラオブジェクト //private Stopwatch _Swatch = new Stopwatch(); // 高精度時間計測 + private ulong _availablePhysicalMemory; //合計物理メモリ /// /// コンストラクタ @@ -38,30 +39,32 @@ //_Swatch.Start(); _Cameras.ForEach(c => c.Connect()); - _UITimer = new System.Threading.Timer(TimerCB, this, 0, 2000); + _UITimer = new System.Threading.Timer(UITimerCB, this, 0, 2000); } /// /// タイマーイベント /// /// - static void TimerCB(object obj) { - ((MainForm)obj).SoftwareTrigger(); + static void UITimerCB(object obj) { + ((MainForm)obj).UpdateForm(); } /// /// トリガー発生 /// - public void SoftwareTrigger() { + public void UpdateForm() { if (this.InvokeRequired) { - this.Invoke((MethodInvoker)delegate { SoftwareTrigger(); }); + this.Invoke((MethodInvoker)delegate { UpdateForm(); }); return; } //_Cam.ForEach(c => c.SWTrigger()); - TxtTop.Text = $"Top {_Cameras[0].CameraInfo()}"; - TxtLeft.Text = $"Left {_Cameras[1].CameraInfo()}"; - TxtFront.Text = $"Front {_Cameras[2].CameraInfo()}"; - TxtRight.Text = $"Right {_Cameras[3].CameraInfo()}"; + TxtTop.Text = $"上方カメラ {_Cameras[0].CameraInfo()}"; + TxtLeft.Text = $"左方カメラ {_Cameras[1].CameraInfo()}"; + TxtFront.Text = $"前方カメラ {_Cameras[2].CameraInfo()}"; + TxtRight.Text = $"右方カメラ {_Cameras[3].CameraInfo()}"; + TotalPhysicalMemory(); + MemoryToUse(); } /// @@ -113,5 +116,45 @@ private void MainForm_SizeChanged(object sender, EventArgs e) { _Cameras.ForEach(c => c.SetDisplaySize()); } + + /// + /// 利用可能なメモリ量をラベルに表示 + /// + private void TotalPhysicalMemory() { + + Microsoft.VisualBasic.Devices.ComputerInfo info = + new Microsoft.VisualBasic.Devices.ComputerInfo(); + ulong bcs = 1024 * 1024; + _availablePhysicalMemory = info.AvailablePhysicalMemory / bcs; //利用可能な物理メモリ + LblAvailableMemory.Text = "利用可能メモリ:" + _availablePhysicalMemory.ToString("#,0") + "MB"; + } + + /// + /// 消費メモリ量をラベルに表示 + /// + private void MemoryToUse() { + var memoryConsumption = _Cameras.Select(c => c.MemoryFor1SecRecoding()).Sum() + * float.Parse(TxtRecodingDulation.Text); + LblRecodingMemory.Text = "消費するメモリ:" + memoryConsumption.ToString("#,0") + "MB"; + if (memoryConsumption > _availablePhysicalMemory && _availablePhysicalMemory != 0) LblRecodingMemory.ForeColor = Color.Red; + else LblRecodingMemory.ForeColor = Color.Black; + } + + /// + /// 録画時間テキストボックスでキー押下時 + /// + /// + /// + private void TxtRecodingDulation_KeyPress(object sender, KeyPressEventArgs e) { + //バックスペースが押された時は有効(Deleteキーも有効) + if (e.KeyChar == '\b') { + return; + } + + //数値0~9以外が押された時はイベントをキャンセルする + if ((e.KeyChar < '0' || '9' < e.KeyChar)) { + e.Handled = true; + } + } } }