diff --git a/TIASshot/Form1.Designer.cs b/TIASshot/Form1.Designer.cs index 9a7a4ad..50db299 100644 --- a/TIASshot/Form1.Designer.cs +++ b/TIASshot/Form1.Designer.cs @@ -45,8 +45,10 @@ this.label8 = new System.Windows.Forms.Label(); this.btnOpenDataFolder = new System.Windows.Forms.Button(); this.btnLightSW = new System.Windows.Forms.Button(); + this.icImagingControl1 = new TIS.Imaging.ICImagingControl(); ((System.ComponentModel.ISupportInitialize)(this.picPreview)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.picDisplay)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.icImagingControl1)).BeginInit(); this.SuspendLayout(); // // btnShotOne @@ -66,15 +68,15 @@ this.label1.Font = new System.Drawing.Font("MS UI Gothic", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(128))); this.label1.Location = new System.Drawing.Point(12, 9); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(60, 16); + this.label1.Size = new System.Drawing.Size(40, 16); this.label1.TabIndex = 1; - this.label1.Text = "Camera"; + this.label1.Text = "カメラ"; // // label2 // this.label2.AutoSize = true; this.label2.Font = new System.Drawing.Font("MS UI Gothic", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(128))); - this.label2.Location = new System.Drawing.Point(153, 9); + this.label2.Location = new System.Drawing.Point(157, 9); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(35, 16); this.label2.TabIndex = 1; @@ -83,10 +85,10 @@ // txtDeviceName // this.txtDeviceName.Font = new System.Drawing.Font("MS UI Gothic", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(128))); - this.txtDeviceName.Location = new System.Drawing.Point(78, 6); + this.txtDeviceName.Location = new System.Drawing.Point(51, 6); this.txtDeviceName.Name = "txtDeviceName"; this.txtDeviceName.ReadOnly = true; - this.txtDeviceName.Size = new System.Drawing.Size(60, 23); + this.txtDeviceName.Size = new System.Drawing.Size(106, 23); this.txtDeviceName.TabIndex = 2; // // txtSerialNo @@ -274,11 +276,25 @@ this.btnLightSW.UseVisualStyleBackColor = true; this.btnLightSW.Click += new System.EventHandler(this.btnLightSW_Click); // + // icImagingControl1 + // + this.icImagingControl1.BackColor = System.Drawing.Color.White; + this.icImagingControl1.DeviceListChangedExecutionMode = TIS.Imaging.EventExecutionMode.Invoke; + this.icImagingControl1.DeviceLostExecutionMode = TIS.Imaging.EventExecutionMode.AsyncInvoke; + this.icImagingControl1.ImageAvailableExecutionMode = TIS.Imaging.EventExecutionMode.MultiThreaded; + this.icImagingControl1.LiveDisplayPosition = new System.Drawing.Point(0, 0); + this.icImagingControl1.Location = new System.Drawing.Point(12, 505); + this.icImagingControl1.Name = "icImagingControl1"; + this.icImagingControl1.Size = new System.Drawing.Size(79, 54); + this.icImagingControl1.TabIndex = 22; + this.icImagingControl1.Visible = false; + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(753, 634); + this.Controls.Add(this.icImagingControl1); this.Controls.Add(this.btnLightSW); this.Controls.Add(this.btnOpenDataFolder); this.Controls.Add(this.label8); @@ -307,6 +323,7 @@ this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.picPreview)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.picDisplay)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.icImagingControl1)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -336,6 +353,7 @@ private System.Windows.Forms.Label label8; private System.Windows.Forms.Button btnOpenDataFolder; private System.Windows.Forms.Button btnLightSW; + private TIS.Imaging.ICImagingControl icImagingControl1; } } diff --git a/TIASshot/Form1.cs b/TIASshot/Form1.cs index 1f46ba2..061e4e2 100644 --- a/TIASshot/Form1.cs +++ b/TIASshot/Form1.cs @@ -12,14 +12,17 @@ using System.Windows.Interop; using System.Windows.Media.Media3D; using System.Xml.Serialization; +using TIS.Imaging; namespace TIASshot { public partial class Form1 : Form { public static string APP_NAME = "TIAS Shot"; - private Lucam _lucam; + //private Lucam _lucam; + private IScam _iscam; private LightSource _light = new LightSource(); private bool _isLightOn = true; + //public ICImagingControl IcCam { get { return icImagingControl1; } } /// /// コンストラクタ @@ -27,7 +30,8 @@ public Form1() { InitializeComponent(); - _lucam = new Lucam(this, picPreview, picDisplay); + //_lucam = new Lucam(this, picPreview, picDisplay); + _iscam = new IScam(this, icImagingControl1); var version = Assembly.GetExecutingAssembly().GetName().Version; Text = $"{APP_NAME} ver.{version.Major}.{version.Minor}"; @@ -42,19 +46,27 @@ /// /// private void Form1_Load(object sender, EventArgs e) { - if (!_lucam.Connect()) { - MessageBox.Show(_lucam.ErrorMsg, APP_NAME, + //if (!_lucam.Connect()) { + // MessageBox.Show(_lucam.ErrorMsg, APP_NAME, + // MessageBoxButtons.OK, MessageBoxIcon.Warning); + // Close(); + // return; + //} + if (!_iscam.Connect()) { + MessageBox.Show("IScamの接続に失敗しました。", APP_NAME, MessageBoxButtons.OK, MessageBoxIcon.Warning); Close(); return; } - - txtDeviceName.Text = _lucam.DeviceName; - txtSerialNo.Text = _lucam.SerialNumber; + + txtDeviceName.Text = icImagingControl1.DeviceCurrent.Name; + txtSerialNo.Text = icImagingControl1.DeviceCurrent.GetSerialNumber(); + //txtDeviceName.Text = _lucam.DeviceName; + //txtSerialNo.Text = _lucam.SerialNumber; txtSaveFolder.Text = Config.GetString("SaveFolder"); EnableShots(false); - _lucam.StartStopPreview(); + //_lucam.StartStopPreview(); if (_light.Open()) { _light.SetLight(); @@ -67,7 +79,8 @@ /// /// private void Form1_FormClosing(object sender, FormClosingEventArgs e) { - _lucam.Disconnect(); + //_lucam.Disconnect(); + _iscam.Disconnect(); } /// @@ -76,7 +89,7 @@ /// /// private void btnShot1_Click(object sender, EventArgs e) { - _lucam.ShotOne(); + //_lucam.ShotOne(); } /// @@ -85,7 +98,7 @@ /// /// private void btnShotMulti_Click(object sender, EventArgs e) { - _lucam.ShotMulti(); + //_lucam.ShotMulti(); } /// @@ -94,7 +107,7 @@ /// /// private void btnCalib_Click(object sender, EventArgs e) { - _lucam.Calibration(); + //_lucam.Calibration(); } /// diff --git a/TIASshot/IScam.cs b/TIASshot/IScam.cs new file mode 100644 index 0000000..26b5dc1 --- /dev/null +++ b/TIASshot/IScam.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using TIS.Imaging; +using OpenCvSharp; +using OpenCvSharp.Extensions; +using System.Diagnostics; +using System.Drawing; + +namespace TIASshot { + internal class IScam { + ICImagingControl _ic; + Form1 _form; + Bitmap[] _bmps = new Bitmap[2]; + int _bmpIndex = 0; + + public IScam(Form1 form, ICImagingControl ic) { + _form = form; + _ic = ic; + + Config.Load(); + + } + + public bool Connect() { + if (!_ic.LoadShowSaveDeviceState("lastSelectedDeviceState.xml")) { + return false; + } + _ic.Sink = new TIS.Imaging.FrameQueueSink(Retrieve, MediaSubtypes.RGB24, 5); + _ic.LiveStart(); + + return true; + } + + public void Disconnect() { + _ic.LiveStop(); + } + + private FrameQueuedResult Retrieve(IFrameQueueBuffer buffer) { + //var image = buffer.CreateBitmapWrap(); + var frameType = buffer.FrameType; + + using (Mat img = Mat.FromPixelData(frameType.Height, frameType.Width, MatType.CV_8UC3, buffer.GetIntPtr())) { + using (Mat imgt = img.T()) { + _bmps[_bmpIndex] = imgt.ToBitmap(); + + //if (_calibrating > 0) { + // var whitePatch = Cv2.Mean(imgt, _chartMasks[12]); + // Debug.WriteLine($"White patch R {whitePatch.Val2:.00} G {whitePatch.Val1:.00} B {whitePatch.Val0:.00}"); + // if (_calibrating % Config.GetInt("CalibrationUpdateInterval") == 0) { + // _snap.GainBlue *= GetRatio((float)whitePatch.Val0, Config.GetFloat("ReferenceB")); + // _snap.GainGrn1 *= GetRatio((float)whitePatch.Val1, Config.GetFloat("ReferenceG")); + // _snap.GainGrn2 = _snap.GainGrn1; + // _snap.GainRed *= GetRatio((float)whitePatch.Val2, Config.GetFloat("ReferenceR")); + // SetCameraParam(); + // } + // _calibrating--; + // if (_calibrating == 0) { + // CalcTcc(imgt); + // } + //} + + //if (!_calibrated && _calibrating == 0) { + // DetectChart(imgt); + //} + } + } + _form.ShowImage(_bmps[_bmpIndex]); + _bmpIndex = (_bmpIndex + 1) % 2; + if (_bmps[_bmpIndex] != null) _bmps[_bmpIndex].Dispose(); + + //_form.ShowImage(image); + return FrameQueuedResult.ReQueue; + } + } +} diff --git a/TIASshot/TIASshot.csproj b/TIASshot/TIASshot.csproj index 3c1dc17..e5d1592 100644 --- a/TIASshot/TIASshot.csproj +++ b/TIASshot/TIASshot.csproj @@ -104,6 +104,10 @@ + + False + C:\Program Files (x86)\The Imaging Source Europe GmbH\IC Imaging Control 3.5 .NET Library\bin\x64\TIS.Imaging.ICImagingControl35.dll + @@ -114,6 +118,7 @@ Form1.cs +