void Canvas_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.PageUp)
            {
                ImageScale += ScaleIncrement;
            }
            if (e.KeyCode == Keys.PageDown)
            {
                ImageScale -= ScaleIncrement;
            }
            if (e.Control && e.KeyCode == Keys.Z)
            {
                commandExecutor.Undo();
            }
            if (e.Control && e.KeyCode == Keys.Y)
            {
                commandExecutor.Redo();
            }
            if (e.Control && e.KeyCode == Keys.V)
            {
                var roiText = (string)Clipboard.GetData(DataFormats.Text);
                try
                {
                    var mousePosition = PointToClient(MousePosition);
                    var offset        = NormalizedLocation(mousePosition.X, mousePosition.Y);
                    var roiData       = (float[])ArrayConvert.ToArray(roiText, 1, typeof(float));
                    var center        = new Point2f(offset.X, offset.Y);
                    var size          = new Size2f(roiData[0], roiData[1]);
                    var roi           = new RotatedRect(center, size, 0);

                    var selection = selectedRoi;
                    commandExecutor.Execute(
                        () => AddRegion(roi),
                        () => { regions.Remove(roi); SelectedRegion = selection; });
                }
                catch (ArgumentException) { }
                catch (InvalidCastException) { }
                catch (FormatException) { }
            }

            if (selectedRoi.HasValue)
            {
                if (e.Control && e.KeyCode == Keys.C)
                {
                    var roi     = regions[selectedRoi.Value];
                    var roiData = new[] { roi.Size.Width, roi.Size.Height };
                    Clipboard.SetData(DataFormats.Text, ArrayConvert.ToString(roiData));
                }

                if (e.KeyCode == Keys.Delete)
                {
                    var selection = selectedRoi.Value;
                    var region    = regions[selection];
                    commandExecutor.Execute(
                        () => { regions.RemoveAt(selection); SelectedRegion = null; },
                        () => { regions.Insert(selection, region); SelectedRegion = selection; });
                }
            }
        }
Example #2
0
        protected override string GetDisplayText(object value)
        {
            var group   = (GroupedRegions)value;
            var name    = string.IsNullOrEmpty(group.Name) ? "Group" : group.Name;
            var regions = group.Regions;

            if (regions == null || regions.Length == 0)
            {
                return(name);
            }
            else
            {
                return(string.Format("{0} ({1})", name, ArrayConvert.ToString(group.Regions)));
            }
        }
Example #3
0
        /// <summary>
        /// Converts the given value object to the specified type, using the specified
        /// context and culture information.
        /// </summary>
        /// <param name="context">
        /// An <see cref="ITypeDescriptorContext"/> that provides a format context.
        /// </param>
        /// <param name="culture">
        /// A <see cref="CultureInfo"/>. If <b>null</b> is passed, the current culture
        /// is assumed.
        /// </param>
        /// <param name="value">The <see cref="Object"/> to convert.</param>
        /// <param name="destinationType">The <see cref="Type"/> to convert the value parameter to.</param>
        /// <returns>An <see cref="Object"/> that represents the converted value.</returns>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (value != null && destinationType == typeof(string))
            {
                var mat   = (Mat)value;
                var array = new float[mat.Rows, mat.Cols];
                using (var arrayHeader = Mat.CreateMatHeader(array))
                {
                    CV.Convert(mat, arrayHeader);
                }

                return(ArrayConvert.ToString(array, culture));
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
Example #4
0
        void Canvas_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.PageUp)
            {
                ImageScale += ScaleIncrement;
            }
            if (e.KeyCode == Keys.PageDown)
            {
                ImageScale -= ScaleIncrement;
            }
            if (e.Control && e.KeyCode == Keys.Z)
            {
                commandExecutor.Undo();
            }
            if (e.Control && e.KeyCode == Keys.Y)
            {
                commandExecutor.Redo();
            }
            if (e.Control && e.KeyCode == Keys.V)
            {
                var roiText = (string)Clipboard.GetData(DataFormats.Text);
                try
                {
                    var mousePosition = PointToClient(MousePosition);
                    var offset        = NormalizedLocation(mousePosition.X, mousePosition.Y);
                    var roiData       = (int[])ArrayConvert.ToArray(roiText, 1, typeof(int));
                    var roi           = new Point[roiData.Length / 2];
                    for (int i = 0, k = 0; i < roi.Length && k < roiData.Length; i++, k += 2)
                    {
                        roi[i].X = roiData[k + 0] - roiData[0] + offset.X;
                        roi[i].Y = roiData[k + 1] - roiData[1] + offset.Y;
                    }

                    var selection = selectedRoi;
                    commandExecutor.Execute(
                        () => AddRegion(roi),
                        () => { regions.Remove(roi); SelectedRegion = selection; });
                }
                catch (ArgumentException) { }
                catch (InvalidCastException) { }
                catch (FormatException) { }
            }

            if (selectedRoi.HasValue)
            {
                if (e.Control && e.KeyCode == Keys.C)
                {
                    var roi     = regions[selectedRoi.Value];
                    var roiData = new int[roi.Length * 2];
                    for (int i = 0, k = 0; i < roi.Length && k < roiData.Length; i++, k += 2)
                    {
                        roiData[k + 0] = roi[i].X;
                        roiData[k + 1] = roi[i].Y;
                    }
                    Clipboard.SetData(DataFormats.Text, ArrayConvert.ToString(roiData));
                }

                if (e.KeyCode == Keys.Delete)
                {
                    var selection = selectedRoi.Value;
                    var region    = regions[selection];
                    commandExecutor.Execute(
                        () => { regions.RemoveAt(selection); SelectedRegion = null; },
                        () => { regions.Insert(selection, region); SelectedRegion = selection; });
                }
            }
        }