private void Classify_button_Click(object sender, EventArgs e) { dataGridView1.Rows.Clear(); dataGridView1.Refresh(); int l = Math.Min(Convert.ToInt32(imageLeftIndex.Text), Convert.ToInt32(imageRightIndex.Text)); int r = Math.Max(Convert.ToInt32(imageLeftIndex.Text), Convert.ToInt32(imageRightIndex.Text)); l--; r--; if (l >= 0 && r < 10000 && Convert.ToInt32(K_text.Text) <= 60000) { double accuracy = KNN.Classify(l, r, ReadingInput.testImages, ReadingInput.trainImages, Convert.ToInt32(K_text.Text)); int index = 0; for (int i = 0; i <= r - l; i++) { DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[0].Clone(); row.Cells[0].Value = KNN.testResults[index]; row.Cells[1].Value = KNN.testResults[index + 1]; row.Cells[2].Value = KNN.testResults[index + 2]; index = index + 3; dataGridView1.Rows.Add(row); } accuracy_text.Text = accuracy.ToString() + "%"; ConfusionMatrix CM = new ConfusionMatrix(); CM.Show(); } }
private void Classify_button_Click(object sender, EventArgs e) { int index = Convert.ToInt32(imageIndex.Text); index--; if (index >= 0 && index < 10000 && Convert.ToInt32(K_text.Text) <= 60000) { byte pred = KNN.Classify(ReadingInput.testImages[index], ReadingInput.trainImages, Convert.ToInt32(K_text.Text)); predicion_text.Text = pred.ToString(); } }
private void Classify_button_Click(object sender, EventArgs e) { Bitmap drawnImage = new Bitmap(pictureBox1.Image); Bitmap resized = new Bitmap(drawnImage, new Size(28, 28)); pictureBox1.Image = resized; byte[,] arr = new byte[28, 28]; for (int i = 0; i < 28; i++) { for (int j = 0; j < 28; j++) { arr[i, j] = resized.GetPixel(j, i).R; } } DigitImage DI = new DigitImage(arr, 0); byte pred = KNN.Classify(DI, ReadingInput.trainImages, Convert.ToInt32(K_text.Text)); predicion_text.Text = pred.ToString(); }