diff --git a/ISCamRecorder/Form1.Designer.cs b/ISCamRecorder/Form1.Designer.cs index da35692..e3f1abd 100644 --- a/ISCamRecorder/Form1.Designer.cs +++ b/ISCamRecorder/Form1.Designer.cs @@ -24,7 +24,7 @@ /// private void InitializeComponent() { this.icTop = new TIS.Imaging.ICImagingControl(); - this.button1 = new System.Windows.Forms.Button(); + this.BtnStartPreview = new System.Windows.Forms.Button(); this.icLeft = new TIS.Imaging.ICImagingControl(); this.icFront = new TIS.Imaging.ICImagingControl(); this.icRight = new TIS.Imaging.ICImagingControl(); @@ -42,20 +42,22 @@ this.icTop.DeviceLostExecutionMode = TIS.Imaging.EventExecutionMode.AsyncInvoke; this.icTop.ImageAvailableExecutionMode = TIS.Imaging.EventExecutionMode.MultiThreaded; this.icTop.LiveDisplayPosition = new System.Drawing.Point(0, 0); - this.icTop.Location = new System.Drawing.Point(293, 12); + this.icTop.Location = new System.Drawing.Point(391, 15); + this.icTop.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.icTop.Name = "icTop"; - this.icTop.Size = new System.Drawing.Size(262, 250); + this.icTop.Size = new System.Drawing.Size(349, 312); this.icTop.TabIndex = 0; // - // button1 + // BtnStartPreview // - this.button1.Location = new System.Drawing.Point(12, 12); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(102, 42); - this.button1.TabIndex = 1; - this.button1.Text = "Start Preview"; - this.button1.UseVisualStyleBackColor = true; - this.button1.Click += new System.EventHandler(this.button1_Click); + this.BtnStartPreview.Location = new System.Drawing.Point(16, 15); + this.BtnStartPreview.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.BtnStartPreview.Name = "BtnStartPreview"; + this.BtnStartPreview.Size = new System.Drawing.Size(136, 52); + this.BtnStartPreview.TabIndex = 1; + this.BtnStartPreview.Text = "Start Preview"; + this.BtnStartPreview.UseVisualStyleBackColor = true; + this.BtnStartPreview.Click += new System.EventHandler(this.BtnStartPreview_Click); // // icLeft // @@ -64,9 +66,10 @@ this.icLeft.DeviceLostExecutionMode = TIS.Imaging.EventExecutionMode.AsyncInvoke; this.icLeft.ImageAvailableExecutionMode = TIS.Imaging.EventExecutionMode.MultiThreaded; this.icLeft.LiveDisplayPosition = new System.Drawing.Point(0, 0); - this.icLeft.Location = new System.Drawing.Point(12, 268); + this.icLeft.Location = new System.Drawing.Point(16, 335); + this.icLeft.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.icLeft.Name = "icLeft"; - this.icLeft.Size = new System.Drawing.Size(262, 250); + this.icLeft.Size = new System.Drawing.Size(349, 312); this.icLeft.TabIndex = 2; // // icFront @@ -76,9 +79,10 @@ this.icFront.DeviceLostExecutionMode = TIS.Imaging.EventExecutionMode.AsyncInvoke; this.icFront.ImageAvailableExecutionMode = TIS.Imaging.EventExecutionMode.MultiThreaded; this.icFront.LiveDisplayPosition = new System.Drawing.Point(0, 0); - this.icFront.Location = new System.Drawing.Point(293, 268); + this.icFront.Location = new System.Drawing.Point(391, 335); + this.icFront.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.icFront.Name = "icFront"; - this.icFront.Size = new System.Drawing.Size(262, 250); + this.icFront.Size = new System.Drawing.Size(349, 312); this.icFront.TabIndex = 3; // // icRight @@ -88,32 +92,35 @@ this.icRight.DeviceLostExecutionMode = TIS.Imaging.EventExecutionMode.AsyncInvoke; this.icRight.ImageAvailableExecutionMode = TIS.Imaging.EventExecutionMode.MultiThreaded; this.icRight.LiveDisplayPosition = new System.Drawing.Point(0, 0); - this.icRight.Location = new System.Drawing.Point(573, 268); + this.icRight.Location = new System.Drawing.Point(764, 335); + this.icRight.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.icRight.Name = "icRight"; - this.icRight.Size = new System.Drawing.Size(262, 250); + this.icRight.Size = new System.Drawing.Size(349, 312); this.icRight.TabIndex = 4; // // button2 // - this.button2.Location = new System.Drawing.Point(131, 12); + this.button2.Location = new System.Drawing.Point(175, 15); + this.button2.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.button2.Name = "button2"; - this.button2.Size = new System.Drawing.Size(102, 42); + this.button2.Size = new System.Drawing.Size(136, 52); this.button2.TabIndex = 5; this.button2.Text = "Property"; this.button2.UseVisualStyleBackColor = true; - this.button2.Click += new System.EventHandler(this.button2_Click); + this.button2.Click += new System.EventHandler(this.SetProperty_Click); // // Form1 // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(849, 531); + this.ClientSize = new System.Drawing.Size(1132, 664); this.Controls.Add(this.button2); this.Controls.Add(this.icRight); this.Controls.Add(this.icFront); this.Controls.Add(this.icLeft); - this.Controls.Add(this.button1); + this.Controls.Add(this.BtnStartPreview); this.Controls.Add(this.icTop); + this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.Name = "Form1"; this.Text = "Form1"; ((System.ComponentModel.ISupportInitialize)(this.icTop)).EndInit(); @@ -127,7 +134,7 @@ #endregion private TIS.Imaging.ICImagingControl icTop; - private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button BtnStartPreview; private TIS.Imaging.ICImagingControl icLeft; private TIS.Imaging.ICImagingControl icFront; private TIS.Imaging.ICImagingControl icRight; diff --git a/ISCamRecorder/Form1.cs b/ISCamRecorder/Form1.cs index 3716e84..373424b 100644 --- a/ISCamRecorder/Form1.cs +++ b/ISCamRecorder/Form1.cs @@ -8,56 +8,58 @@ using System.Threading.Tasks; using System.Windows.Forms; using System.Diagnostics; +using TIS.Imaging; + namespace ISCamRecorder { public partial class Form1 : Form { - //readonly int NUM_CAMS = 4; - //readonly string[] SERIALNO = new string[] { "9220016", "9220018", "9220021", "9220025" }; - readonly string CAMERA_FORMAT = "RGB24 (640x480)"; - readonly float FRAME_RATE = 30F; - List _iccs; + private List _iccs; + private int _count = 0; + private Stopwatch _sw = new Stopwatch(); + private System.Threading.Timer _timer; + public VCDButtonProperty SoftwareTrigger; + /// + /// フォームロード時 + /// public Form1() { InitializeComponent(); icTop.Tag = "9220016"; + icTop.Sink = new FrameQueueSink(CaptureFrame, MediaSubtypes.RGB32, 5); icLeft.Tag = "9220018"; icFront.Tag = "9220021"; icRight.Tag = "9220025"; - _iccs = new List { - icTop, icLeft, icFront, icRight + _iccs = new List { + icTop, icLeft, icFront, icRight }; } - private void button1_Click(object sender, EventArgs e) { + static void TimerCB(object obj) { + + ((Form1)obj).SoftwareTrigger.Push(); + } + + private FrameQueuedResult CaptureFrame(IFrameQueueBuffer buffer) { + if (++_count >= 10) { + var elapsed = _sw.ElapsedMilliseconds; + _sw.Reset(); + _sw.Start(); + Debug.WriteLine($"{_count * 1000 / elapsed} fps"); + _count = 0; + } + return FrameQueuedResult.ReQueue; + } + + /// + /// プレビュー開始 + /// + /// + /// + private void BtnStartPreview_Click(object sender, EventArgs e) { try { var devs = _iccs[0].Devices; - //for (int id = 0; id < _iccs.Count; id++) { - // if (!_iccs[id].DeviceValid) { - // // カメラ接続 - // _iccs[id].Device = devs.FirstOrDefault( - // c => c.GetSerialNumber().Equals(_iccs[id].Tag)); - // } - - // if (_iccs[id].DeviceValid) { - // if (_iccs[id].LiveVideoRunning) _iccs[id].LiveStop(); - - // // 撮影条件設定 - // _iccs[id].DeviceFrameRate = _iccs[id].DeviceFrameRates.FirstOrDefault( - // c => (c > FRAME_RATE - 0.1F && c < FRAME_RATE + 0.1F)); - // _iccs[id].VideoFormat = _iccs[id].VideoFormats.FirstOrDefault( - // c => c.Name.Equals(CAMERA_FORMAT)); - // // カメラ設定読み込み - // _iccs[id].LoadDeviceStateFromFile($"config.xml", false); - - // // プレビュー設定 - // _iccs[id].LiveDisplayDefault = false; - // _iccs[id].LiveDisplayHeight = icTop.Height; - // _iccs[id].LiveDisplayWidth = icTop.Width; - // _iccs[id].LiveStart(); - // } - //} _iccs.ForEach(ic => { if (!ic.DeviceValid) { // カメラ接続 @@ -69,6 +71,8 @@ if (ic.LiveVideoRunning) ic.LiveStop(); // 撮影条件設定 + //readonly string CAMERA_FORMAT = "RGB24 (640x480)"; + //readonly float FRAME_RATE = 30F; //ic.VideoFormat = ic.VideoFormats.FirstOrDefault( // c => c.Name.Equals(CAMERA_FORMAT)); //ic.DeviceFrameRate = ic.DeviceFrameRates.FirstOrDefault( @@ -82,21 +86,33 @@ ic.LiveDisplayHeight = icTop.Height; ic.LiveDisplayWidth = icTop.Width; ic.LiveStart(); + _sw.Reset(); + _sw.Start(); } }); - } catch (TIS.Imaging.ICException iex) { + SoftwareTrigger = icTop.VCDPropertyItems.Find(VCDGUIDs.VCDID_TriggerMode, + VCDGUIDs.VCDElement_SoftwareTrigger);//宣言 + _timer = new System.Threading.Timer(TimerCB, this, 0, 30); + + } catch (ICException iex) { MessageBox.Show("Import of ICCF file failed:\n" + iex.Message, "Import IC Capture File", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } - private void button2_Click(object sender, EventArgs e) { + /// + /// カメラプロパティの設定 + /// + /// + /// + private void SetProperty_Click(object sender, EventArgs e) { _iccs.ForEach(ic => ic.LiveStop()); - _iccs[0].ShowPropertyDialog(); - var setting = _iccs[0].SaveDeviceState(); - _iccs.Skip(1).ToList().ForEach(ic => { - ic.LoadDeviceState(setting, false); - }); + _iccs.ForEach(ic => ic.DeviceTrigger = true); + //_iccs[0].ShowPropertyDialog(); + //var setting = _iccs[0].SaveDeviceState(); + //_iccs.Skip(1).ToList().ForEach(ic => { + // ic.LoadDeviceState(setting, false); + //}); _iccs.ForEach(ic => ic.LiveStart()); } }