//Выбор лучшего скрина //SELECT vid_id, max(ave), link from result GROUP BY vid_id //по этому запросу выбирается лучшее изображение по максимальному среднему private void button13_Click(object sender, EventArgs e) { int rzm = Images_Compare_Grid.Rows.Count; MySqlConnection conn = DBUtils.GetDBConnection(); MySqlCommand cmd = conn.CreateCommand(); cmd.Connection.Open(); string sql3 = "SELECT vid_id, max(ave), link from result GROUP BY vid_id"; cmd.CommandText = sql3; MySqlDataReader reader; try { reader = cmd.ExecuteReader(); while (reader.Read()) { Mini_Log.AppendText("Best screen link for video: \nID: " + reader["vid_id"] + "\nLink for screen:" + reader["link"] + "\n"); dataGridView1.Rows.Add(reader["vid_id"], GetImageFromUrl(reader["link"].ToString())); } reader.Close(); } catch (MySqlException ex) { MessageBox.Show("Error: \r\n{ 0}" + ex.ToString(), "Error", MessageBoxButtons.OK); } }
private void Load_Images_Cmp_Click(object sender, EventArgs e) { MySqlConnection conn = DBUtils.GetDBConnection(); MySqlCommand cmd = conn.CreateCommand(); string sql_count = "SELECT * FROM our_screens"; cmd.Connection = conn; cmd.CommandText = sql_count; MySqlDataReader reader; try { cmd.Connection.Open(); reader = cmd.ExecuteReader(); while (reader.Read()) { Images_Compare_Grid.Rows.Add(reader["link"], reader["vid_id"]); } reader.Close(); } catch (MySqlException ex) { MessageBox.Show("Error: \r\n{ 0}" + ex.ToString(), "Error", MessageBoxButtons.OK); } int rowsin = Images_Compare_Grid.RowCount - 1; Mini_Log.AppendText(">> Added: " + rowsin + " links \n"); Screen_Anal_Button.Visible = true; }
private async void Screen_Anal_Button_Click(object sender, EventArgs e) { int rowsin = Images_Compare_Grid.RowCount - 1; progressBar1.Maximum = rowsin; var client = new ClarifaiClient("f5d04074f20343b787952a2605d34b3a"); MySqlConnection conn = DBUtils.GetDBConnection(); MySqlCommand cmd = conn.CreateCommand(); cmd.Connection.Open(); string truncate = "TRUNCATE `an_base_our_screens`;"; cmd.CommandText = truncate; for (int n = 0; n < (rowsin); n++) { string links = Images_Compare_Grid[0, n].Value.ToString(); var res = await client.PublicModels.GeneralModel.Predict(new ClarifaiURLImage(links)).ExecuteAsync(); try { var res2 = await client.PublicModels.FocusModel.Predict(new ClarifaiURLImage(links)).ExecuteAsync(); int vid_id = Convert.ToInt32(Images_Compare_Grid[1, n].Value.ToString()); try { foreach (var concept in res.Get().Data) { Screen_Analyze_Grid.Rows.Add($"{concept.Name}", $"{concept.Value}", links, vid_id); string sql = "INSERT INTO an_base_our_screens (name,value,img_link,vid_id) VALUES (@name,@val,@link,@img_id)"; using (MySqlCommand cmd1 = new MySqlCommand(sql, conn)) { cmd1.Parameters.AddWithValue("@name", concept.Name); cmd1.Parameters.AddWithValue("@val", concept.Value); cmd1.Parameters.AddWithValue("@link", links); cmd1.Parameters.AddWithValue("@img_id", vid_id); cmd1.ExecuteNonQuery(); } } } catch (MySqlException ex) { Mini_Log.AppendText("Error: \r\n{ 0}" + ex.ToString()); } Mini_Log.AppendText(">> Analyzed: " + n + " images \n"); progressBar1.Value = n + 1; } catch (Exception exps) { } } Mini_Log.AppendText(">> Analyzing completed successfully! \n"); MessageBox.Show("Analyze Completed Successfully!", "Success!", MessageBoxButtons.OK); }