private void BtnApply_Click(object sender, EventArgs e) { renderedSelectedBox.SetLabel(labelTxt.Text); datasetService.Save(t.DlibObject); EditorImage dImg = (EditorImage)treeView1.SelectedNode.Tag; pBox.Image = renderedSelectedBox.ChangeState(dImg); }
private void OnImageClick(object sender, MouseEventArgs e) { if (sender == null) { return; } if (pBox.Image == null) { return; } EditorImage t = (EditorImage)treeView1.SelectedNode.Tag; if (t == null) { return; } if (e.Button == MouseButtons.Left) { /* Box su cui si è cliccato null altrimenti */ EditorBox clickedBox = t.GetBox(e.X, e.Y); /* Se la zona su cui si è cliccato non ha una box */ if (clickedBox == EditorBox.None) { t.Boxes.FindAll(b => b.IsSelected).ForEach(b => b.ChangeState(t)); return; } if (renderedSelectedBox != clickedBox) { if (renderedSelectedBox != EditorBox.None) { renderedSelectedBox?.ChangeState(t); } } renderedSelectedBox = clickedBox; Image rendered = renderedSelectedBox?.ChangeState(t); //365ms if (rendered == null) { return; } /* Se è stata selezionata una box imposta l'editor dati */ SetEditorData(rendered); // 1270ms pBox.Image.Dispose(); pBox.Image = rendered; boxEditor.Enabled = true; return; } if (e.Button == MouseButtons.Right) { FilterOptions fOpts = new FilterOptions(); Bitmap bmpMask = new Bitmap(t.File); EditorImage dImg = (EditorImage)treeView1.SelectedNode.Tag; bmpMask = new Bitmap(t.File); FillRegionDetector det = new FillRegionDetector(e.Location); bmpMask = new ContrastFilter(0.8f).Apply(bmpMask); det.Apply(bmpMask); Rectangle area = det.Detected; if (area.Width <= 0 || area.Height <= 0) { MessageBox.Show(@"No valid box detected!", @"No box detected", MessageBoxButtons.OK, MessageBoxIcon.Information); bmpMask.Dispose(); return; } dImg.AddBox(new EditorBox(new DataBox { Top = area.Top, Left = area.Left, Height = area.Height, Width = area.Width, Label = "new box" })); bmpMask.Dispose(); pBox.Image.Dispose(); pBox.Image = dImg.Render(); return; } }