diff --git a/TIASshot/CameraBase.cs b/TIASshot/CameraBase.cs index fc004cf..3883ccd 100644 --- a/TIASshot/CameraBase.cs +++ b/TIASshot/CameraBase.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Security.Cryptography; using System.Text; +using System.Threading; using System.Threading.Tasks; using System.Windows.Controls; using System.Windows.Forms; @@ -35,6 +36,8 @@ protected List _chartMasks = new List(); protected Mat _convRGB2SRGB; protected string _saveFolder = ""; + protected List _shots = new List(); + // プライベートメンバ readonly Dictionary ARDict = CvAruco.GetPredefinedDictionary(PredefinedDictionaryName.Dict4X4_50); @@ -90,7 +93,7 @@ public void ShotOne() { SetSaveFolder(_form.GetDataName()); Shot(); - _form.ShowMessage("1枚撮影 保存しました"); + _form.ShowMessage("撮影終了"); } /// @@ -99,7 +102,7 @@ public void ShotMulti() { SetSaveFolder(_form.GetDataName()); Shot(_form.GetNumMultiShots(), _form.GetMultiShotsInterval()); - _form.ShowMessage("連続撮影 保存しました"); + _form.ShowMessage("撮影終了"); } /// @@ -122,6 +125,24 @@ } /// + /// 画像保存スレッド処理 + /// + /// + protected void SaveThread(int numImages) { + int saveCount = 0; + while (saveCount < numImages) { + while(_shots.Count <= saveCount) { + Thread.Sleep(1); + } + SaveImages(_shots[saveCount], saveCount); + saveCount++; + _form.ShowMessage($"画像{saveCount}/{numImages}枚目保存"); + } + _form.ShowMessage("全ての画像保存完了"); + _form.EnableShots(true); + } + + /// /// チャートの検出 /// /// diff --git a/TIASshot/Form1.cs b/TIASshot/Form1.cs index c041be9..b806c9a 100644 --- a/TIASshot/Form1.cs +++ b/TIASshot/Form1.cs @@ -90,6 +90,7 @@ /// /// private void btnShot1_Click(object sender, EventArgs e) { + EnableShots(false); _camera.ShotOne(); } @@ -99,6 +100,7 @@ /// /// private void btnShotMulti_Click(object sender, EventArgs e) { + EnableShots(false); _camera.ShotMulti(); } diff --git a/TIASshot/IScam.cs b/TIASshot/IScam.cs index 14429ae..5a23fbc 100644 --- a/TIASshot/IScam.cs +++ b/TIASshot/IScam.cs @@ -141,9 +141,12 @@ _ic.LiveStop(); _ic.Sink = _snapSink; _ic.LiveStart(); - var snapSink = _ic.Sink as FrameSnapSink; + _shots.Clear(); + var thread = new Thread(() => SaveThread(numImages)); + thread.Start(); + var filename = Config.GetString("ShotTimeFile"); using (var csv = new StreamWriter(Path.Combine(_saveFolder, filename))) { csv.WriteLine("Shot,Time(ms)"); @@ -152,14 +155,13 @@ for (int i = 0; i < numImages; i++) { var shotTime = watch.ElapsedMilliseconds; csv.WriteLine($"{i+1},{shotTime}"); + _form.ShowMessage($"撮影 {i + 1} / {numImages} 枚目"); var buffer = snapSink.SnapSingle(TimeSpan.FromSeconds(5)); - - //using (Mat img = Mat.FromPixelData(buffer.FrameType.Height, buffer.FrameType.Width, MatType.CV_8UC3, buffer.GetIntPtr())) { - // using (Mat imgt = img.T()) { - // SaveImages(imgt, i); - // } - //} - while(watch.ElapsedMilliseconds < interval * (i+1) && i < numImages - 1) { + + using (Mat img = Mat.FromPixelData(buffer.FrameType.Height, buffer.FrameType.Width, MatType.CV_8UC3, buffer.GetIntPtr())) { + _shots.Add(img.T()); + } + while (watch.ElapsedMilliseconds < interval * (i+1) && i < numImages - 1) { Thread.Sleep(1); } } diff --git a/TIASshot/Lucam.cs b/TIASshot/Lucam.cs index 2de5dc8..ba679ac 100644 --- a/TIASshot/Lucam.cs +++ b/TIASshot/Lucam.cs @@ -199,25 +199,38 @@ protected override void Shot(int numImages=1, int interval=0) { SetSnapParam(); + _shots.Clear(); + var thread = new Thread(() => SaveThread(numImages)); + thread.Start(); + dll.LucamEnableFastFrames(_hCam, ref _snap); var imageSize = _snap.Format.Width * _snap.Format.Height; var rawImage = new byte[imageSize]; var rgbImage = new byte[imageSize * 3]; - for (var i = 0; i < numImages; i++) { - _form.ShowMessage($"連続撮影 {i+1} / {numImages} 枚目"); - var ret = dll.LucamTakeFastFrame(_hCam, rawImage); - //Debug.WriteLine(ret); - dll.LucamConvertFrameToRgb24(_hCam, rgbImage, rawImage, - _snap.Format.Width, _snap.Format.Height, dll.LucamPixelFormat.PF_8, ref _convert); - using (Mat img = Mat.FromPixelData(_snap.Format.Height, _snap.Format.Width, MatType.CV_8UC3, rgbImage)) { - using (Mat imgt = img.T()) { - SaveImages(imgt, i); + var filename = Config.GetString("ShotTimeFile"); + using (var csv = new StreamWriter(Path.Combine(_saveFolder, filename))) { + csv.WriteLine("Shot,Time(ms)"); + + var watch = Stopwatch.StartNew(); + for (var i = 0; i < numImages; i++) { + var shotTime = watch.ElapsedMilliseconds; + csv.WriteLine($"{i + 1},{shotTime}"); + _form.ShowMessage($"撮影 {i + 1} / {numImages} 枚目"); + var ret = dll.LucamTakeFastFrame(_hCam, rawImage); + //Debug.WriteLine(ret); + + dll.LucamConvertFrameToRgb24(_hCam, rgbImage, rawImage, + _snap.Format.Width, _snap.Format.Height, dll.LucamPixelFormat.PF_8, ref _convert); + using (Mat img = Mat.FromPixelData(_snap.Format.Height, _snap.Format.Width, MatType.CV_8UC3, rgbImage)) { + _shots.Add(img.T()); + } + while (watch.ElapsedMilliseconds < interval * (i + 1) && i < numImages - 1) { + Thread.Sleep(1); } } - - if (i < numImages - 1) Thread.Sleep(interval); } + rgbImage = null; rawImage = null; diff --git a/TIASshot/config.xml b/TIASshot/config.xml index 2d4f10a..6be47f0 100644 --- a/TIASshot/config.xml +++ b/TIASshot/config.xml @@ -29,7 +29,7 @@ tcc.png tcc_rois.jpg Shot0000.bmp - Srgb0000.bmp + Srgb0000.jpg ShotTime.csv conv_rgb_srgb.csv conv_rgb_xyz.csv