public string toString() { string s = getLabel() + "\n " + type.ToString(); string a = (area >= 10000) ? (int)(area / 1000) + "k" : area + ""; s += " @(img" + imIndex + "; " + x + "; " + y + ")\n" + " color: " + color.ToString() + "\n" + " area: " + a + "\n" + " circularity: " + circularity + "\n"; return(s); }
private void imageBox1_Click(object sender, EventArgs e) { if (im1.Image == null) { return; } //--Get Mouseposition in Pixelcoordinates-------- var mouseEventArgs = e as MouseEventArgs; int imWidth, imHeight, boxWidth, boxHeight; imWidth = im1.Image.Size.Width; imHeight = im1.Image.Size.Height; boxWidth = im1.Size.Width; boxHeight = im1.Size.Height; Point mouse = TranslateZoomMousePosition(mouseEventArgs.X, mouseEventArgs.Y, imWidth, imHeight, boxWidth, boxHeight); int x = mouse.X; //(int)(mouseEventArgs.X / im1.ZoomScale); int y = mouse.Y; //(int)(mouseEventArgs.Y / im1.ZoomScale); Emgu.CV.Image <Hsv, byte> original = LoadedImages[listBox1.SelectedItem.ToString()]; Hsv pcolor = original[y, x]; if (mouseEventArgs != null) { label1.Text = "@(" + x + "; " + y + "): " + pcolor.ToString(); } Emgu.CV.Image <Gray, byte> threshedimage; threshedimage = thresholdHSVtoGray(original, pcolor); imageBox2.Image = threshedimage; shapes.Clear(); Emgu.CV.Image <Hsv, byte> refImg = (Emgu.CV.Image <Hsv, byte>)im1.Image; Emgu.CV.Image <Gray, byte> inImg = (Emgu.CV.Image <Gray, byte>)im2.Image; Emgu.CV.Image <Hsv, byte> outImg = inImg.Convert <Hsv, byte>(); shapes.AddRange(findShapesinGrayImg(inImg, refImg, listBox1.SelectedIndex)); //--Find closest shape--------- ShapeColorObject temp = null; int dist = 0; foreach (ShapeColorObject shp in shapes) { int d = (shp.pos.X - mouse.X) * (shp.pos.X - mouse.X) + (shp.pos.Y - mouse.Y) * (shp.pos.Y - mouse.Y); if (ShapeColorObject.compareHues(shp.getColor().Hue, pcolor.Hue, dHue)) { if (temp == null || d < dist) { temp = shp; temp.imIndex = listBox1.SelectedIndex; dist = d; } } } if (temp != null && !chosenshapes.Contains(temp)) { temp.objIndex = chosenshapes.Count; chosenshapes.Add(temp); //trackedshapes.Add(temp); } foreach (ShapeColorObject shp in chosenshapes) { shp.drawOnImg(ref outImg); im2.Image = outImg; im2.Update(); } label2.Text = ""; foreach (ShapeColorObject shape in chosenshapes) { label2.Text += shape.toString() + "\n"; } }