diff --git a/TIASshot/CameraBase.cs b/TIASshot/CameraBase.cs index c392cf7..3bb12d5 100644 --- a/TIASshot/CameraBase.cs +++ b/TIASshot/CameraBase.cs @@ -41,6 +41,7 @@ protected string _saveFolder = ""; protected List _shots = new List(); protected Dictionary _ShotInfo = new Dictionary(); // 設定値保存用 + protected Rect _roi; // プライベートメンバ readonly Dictionary ARDict = CvAruco.GetPredefinedDictionary(PredefinedDictionaryName.Dict4X4_50); diff --git a/TIASshot/IScam.cs b/TIASshot/IScam.cs index e70e7f0..142fc1a 100644 --- a/TIASshot/IScam.cs +++ b/TIASshot/IScam.cs @@ -55,6 +55,11 @@ //if (!_ic.LoadShowSaveDeviceState(configFile)) { // return false; //} + _roi = new Rect( + Config.GetInt($"{DeviceName}/ROI/X"), + Config.GetInt($"{DeviceName}/ROI/Y"), + Config.GetInt($"{DeviceName}/ROI/W"), + Config.GetInt($"{DeviceName}/ROI/H")); _queueSink = new FrameQueueSink(Retrieve, MediaSubtypes.RGB24, 5); _snapSink = new FrameSnapSink(MediaSubtypes.RGB24); @@ -98,40 +103,42 @@ 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(); + using (Mat imgt_full = img.T()) { + using (var imgt = new Mat(imgt_full, _roi)) { + _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("Calib/UpdateInterval") == 0) { - _whiteBalanceBlue.Value = (int)(0.5 + _whiteBalanceBlue.Value * GetRatio((float)whitePatch.Val0, Config.GetFloat("Calib/Reference/B"))); - _whiteBalanceGreen.Value = (int)(0.5 + _whiteBalanceGreen.Value * GetRatio((float)whitePatch.Val1, Config.GetFloat("Calib/Reference/G"))); - _whiteBalanceRed.Value = (int)(0.5 + _whiteBalanceRed.Value * GetRatio((float)whitePatch.Val2, Config.GetFloat("Calib/Reference/R"))); + 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("Calib/UpdateInterval") == 0) { + _whiteBalanceBlue.Value = (int)(0.5 + _whiteBalanceBlue.Value * GetRatio((float)whitePatch.Val0, Config.GetFloat("Calib/Reference/B"))); + _whiteBalanceGreen.Value = (int)(0.5 + _whiteBalanceGreen.Value * GetRatio((float)whitePatch.Val1, Config.GetFloat("Calib/Reference/G"))); + _whiteBalanceRed.Value = (int)(0.5 + _whiteBalanceRed.Value * GetRatio((float)whitePatch.Val2, Config.GetFloat("Calib/Reference/R"))); + } + _calibrating--; + if (_calibrating == 0) { + Debug.WriteLine($"White Balance Blue range: {_whiteBalanceBlue.RangeMin} to {_whiteBalanceBlue.RangeMax} value={_whiteBalanceBlue.Value}"); + Debug.WriteLine($"White Balance Green range: {_whiteBalanceGreen.RangeMin} to {_whiteBalanceGreen.RangeMax} value={_whiteBalanceGreen.Value}"); + Debug.WriteLine($"White Balance Red range: {_whiteBalanceRed.RangeMin} to {_whiteBalanceRed.RangeMax} value={_whiteBalanceRed.Value}"); + + CalcTcc(imgt); + + SetInfo("Exposure(ms)", $"{(float)_exposure.Value / 10}"); + SetInfo("Brightness", $"{_brightness.Value}"); + SetInfo("Gamma", $"{_gamma.Value}"); + SetInfo("Gain", $"{_gain.Value}"); + SetInfo("Gain B", $"{_whiteBalanceBlue.Value}"); + SetInfo("Gain G", $"{_whiteBalanceGreen.Value}"); + SetInfo("Gain R", $"{_whiteBalanceRed.Value}"); + SetInfo("画像幅", $"{imgt.Width}"); + SetInfo("画像高さ", $"{imgt.Height}"); + } } - _calibrating--; - if (_calibrating == 0) { - Debug.WriteLine($"White Balance Blue range: {_whiteBalanceBlue.RangeMin} to {_whiteBalanceBlue.RangeMax} value={_whiteBalanceBlue.Value}"); - Debug.WriteLine($"White Balance Green range: {_whiteBalanceGreen.RangeMin} to {_whiteBalanceGreen.RangeMax} value={_whiteBalanceGreen.Value}"); - Debug.WriteLine($"White Balance Red range: {_whiteBalanceRed.RangeMin} to {_whiteBalanceRed.RangeMax} value={_whiteBalanceRed.Value}"); - CalcTcc(imgt); - - SetInfo("Exposure(ms)", $"{(float)_exposure.Value/10}"); - SetInfo("Brightness", $"{_brightness.Value}"); - SetInfo("Gamma", $"{_gamma.Value}"); - SetInfo("Gain", $"{_gain.Value}"); - SetInfo("Gain B", $"{_whiteBalanceBlue.Value}"); - SetInfo("Gain G", $"{_whiteBalanceGreen.Value}"); - SetInfo("Gain R", $"{_whiteBalanceRed.Value}"); - SetInfo("画像幅", $"{imgt.Width}"); - SetInfo("画像高さ", $"{imgt.Height}"); + if (!_calibrated && _calibrating == 0) { + DetectChart(imgt); } } - - if (!_calibrated && _calibrating == 0) { - DetectChart(imgt); - } } } _form.ShowImage(_bmps[_bmpIndex]); @@ -171,7 +178,9 @@ var buffer = snapSink.SnapSingle(TimeSpan.FromSeconds(5)); using (Mat img = Mat.FromPixelData(buffer.FrameType.Height, buffer.FrameType.Width, MatType.CV_8UC3, buffer.GetIntPtr())) { - _shots.Add(img.T()); + using (Mat imgt_full = img.T()) { + _shots.Add(new Mat(imgt_full, _roi)); + } } while (watch.ElapsedMilliseconds < interval * (i+1) && i < numImages - 1) { Thread.Sleep(1); diff --git a/TIASshot/config.xml b/TIASshot/config.xml index b8db020..c6c1c29 100644 --- a/TIASshot/config.xml +++ b/TIASshot/config.xml @@ -7,6 +7,22 @@ 1.72 1.70 + + + 0 + 330 + 1840 + 2440 + + + + + 0 + 180 + 1136 + 1528 + + 4.0 30