private void Btn_change_Click(object sender, EventArgs e) { Timer_tracking.Stop(); sendmessage("Q"); pictureBox1.Enabled = true; label_tracking.Visible = true; }
private void Rb_detection_Click(object sender, EventArgs e) { if (Timer_tracking.Enabled == true) { Timer_tracking.Stop(); sendmessage("Q"); } Timer_face.Start(); Btn_change.Visible = false; Picturebox_colore.BackColor = Color.Transparent; label_tracking.Visible = false; }
private void pictureBox1_Click(object sender, EventArgs e) { var mouseEventArgs = e as MouseEventArgs; if (mouseEventArgs != null) { int min_h = default(int); int min_s = default(int); int min_v = default(int); int max_h = default(int); int max_s = default(int); int max_v = default(int); int px = mouseEventArgs.X; int py = mouseEventArgs.Y; var bmp = pictureBox1.Image as Bitmap; Color target = bmp.GetPixel(px, py); Picturebox_colore.BackColor = target; //converte dalla scala di c# con h 0-360 s 0-1 e v 0-1 //alla scala di python con h 0-180 s 0-255 e v 0-255 int h = (int)(target.GetHue() / 2); int s = (int)(target.GetSaturation() * 255); int v = (int)(target.GetBrightness() * 255); if (h >= 10) { min_h = h - 10; } else { min_h = 0; } if (s >= 40) { min_s = s - 40; } else { min_s = 0; } if (v >= 30) { min_v = v - 30; } else { min_v = 0; } if (h <= 169) { max_h = h + 10; } else { max_h = 179; } if (s <= 215) { max_s = s + 40; } else { max_s = 255; } if (v <= 205) { max_v = v + 50; } else { max_v = 255; } string HSV = $"{min_h} {min_s} {min_v} {max_h} {max_s} {max_v}"; sendmessage("T"); sendmessage(HSV); Timer_tracking.Start(); pictureBox1.Enabled = false; Btn_change.Visible = true; label_tracking.Visible = false; } }