private async void btTest_Click(object sender, EventArgs e) { this.UpdateURL(); AITOOL.UpdateAIURLs(); string pth = Global.GetRegSetting("TestImage", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestImage.jpg")); OpenFileDialog ofd = new OpenFileDialog { InitialDirectory = Path.GetDirectoryName(pth), FileName = Path.GetFileName(pth), Title = "Select test image", CheckFileExists = true, CheckPathExists = true, DefaultExt = "jpg", Filter = "jpg files (*.jpg)|*.jpg", FilterIndex = 2, RestoreDirectory = true, ShowReadOnly = true }; if (ofd.ShowDialog() == DialogResult.OK) { pth = ofd.FileName; Global.SaveRegSetting("TestImage", pth); if (File.Exists(pth)) { //must create a temp unique file every time because database key is the filename Camera cam = AITOOL.GetCamera("default", true); if (cam == null) { cam = new Camera("TEST_CAM"); } string ext = Path.GetExtension(pth); string tpth = Path.Combine(Path.GetTempPath(), $"{cam.Name}.URLTEST.{DateTime.Now:yyyy-MM-dd_HH-mm-ss-fff}{ext}"); File.Copy(pth, tpth, true); btTest.Enabled = false; bt_Save.Enabled = false; btTest.Text = "Working..."; this.UpdateURL(); ClsImageQueueItem CurImg = new ClsImageQueueItem(tpth, 0); List <ClsURLItem> linked = new List <ClsURLItem> { this.CurURL }; if (this.CurURL.LinkServerResults && !string.IsNullOrEmpty(this.CurURL.LinkedResultsServerList)) { linked.AddRange(await AITOOL.WaitForNextURL(cam, false, null, this.CurURL.LinkedResultsServerList)); } if (linked.Count > 1) { AITOOL.Log($"Debug: ---- Found '{linked.Count}' linked AI URL's."); } AITOOL.DetectObjectsResult result = await AITOOL.DetectObjects(CurImg, linked, cam); //make sure not stuck in use for the test: foreach (var url in result.OutURLs) { url.InUse.WriteFullFence(false); } btTest.Enabled = true; bt_Save.Enabled = true; btTest.Text = "Test"; if (result.Success) { Frm_ObjectDetail frm = new Frm_ObjectDetail(); frm.PredictionObjectDetails = result.OutPredictions; frm.ImageFileName = tpth; frm.Show(); MessageBox.Show($"Success! {this.CurURL.LastResultMessage}", "Success"); } else { MessageBox.Show($"Error! {this.CurURL.LastResultMessage}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.CurURL.ErrCount.WriteUnfenced(0); this.CurURL.CurErrCount.WriteUnfenced(0); } else { MessageBox.Show($"Test file does not exist:\r\n{pth}"); } } }
private async void btTest_Click(object sender, EventArgs e) { AITOOL.UpdateAIURLs(); string pth = Global.GetSetting("TestImage", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestImage.jpg")); OpenFileDialog ofd = new OpenFileDialog { InitialDirectory = Path.GetDirectoryName(pth), FileName = Path.GetFileName(pth), Title = "Select test image", CheckFileExists = true, CheckPathExists = true, DefaultExt = "jpg", Filter = "jpg files (*.jpg)|*.jpg", FilterIndex = 2, RestoreDirectory = true, ShowReadOnly = true }; if (ofd.ShowDialog() == DialogResult.OK) { pth = ofd.FileName; Global.SaveSetting("TestImage", pth); if (File.Exists(pth)) { //must create a temp unique file every time because database key is the filename string tpth = Path.Combine(Path.GetTempPath(), $"TEST_CAM.{DateTime.Now:yyyy-MM-dd_HH-mm-ss-fff}"); File.Copy(pth, tpth, true); btTest.Enabled = false; bt_Save.Enabled = false; btTest.Text = "Working..."; this.Update(); ClsImageQueueItem CurImg = new ClsImageQueueItem(tpth, 0); Camera cam = new Camera("TEST_CAM"); bool ret = await AITOOL.DetectObjects(CurImg, this.CurURL, cam); btTest.Enabled = true; bt_Save.Enabled = true; btTest.Text = "Test"; if (ret) { this.CurURL.ErrCount.WriteUnfenced(0); this.CurURL.CurErrCount.WriteUnfenced(0); MessageBox.Show($"Success! {this.CurURL.LastResultMessage}", "Success"); } else { MessageBox.Show($"Error! {this.CurURL.LastResultMessage}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show($"Test file does not exist:\r\n{pth}"); } } }