I want to compare two images to see if they are the same images by checking the pixel values of the images. DB has a table with a column with images saved as BLOB
type.
I upload an image into a picture box, then checks it with the DB to retrieve the value in the column named "CID" when the pixel values of the picture box image is similar to pixel values of an image from the DB.
The code is in C# using MySql and VisualStudio.
However, it gives the exception of Parameter is not valid
What am I doing wrong here? Any help would be highly appreciated.
private void search_botton_Click_1(object sender, EventArgs e)
{
if (leftRadio.Checked == true)
{
try
{
string MyConnection = "datasource=127.0.0.1;port=3306;username=root;password=;database=ahbis";
string sql = "SELECT * FROM criminal";
MySqlConnection MyConn = new MySqlConnection(MyConnection);
MySqlCommand MyCommand = new MySqlCommand(sql, MyConn);
MySqlDataReader MyReader;
MyConn.Open();
MyReader = MyCommand.ExecuteReader();
while (MyReader.Read())
{
//byte[] should be converted to Bitmap
byte[] img_Byte = (byte[])(MyReader["palmHistogram_A_L"]);
Image img1_IMAGE = (Bitmap)((new ImageConverter()).ConvertFrom(img_Byte));
//img1 = new Bitmap(img1_IMAGE);
Bitmap img1 = (Bitmap)new ImageConverter().ConvertTo(img1_IMAGE, typeof(Bitmap[]));
img2 = new Bitmap(histogram_pictureBox.Image);
string img1_ref, img2_ref;
if (img1.Width == img2.Width && img1.Height == img2.Height)
{
for (int i = 0; i < img1.Width; i++)
{
for (int j = 0; j < img1.Height; j++)
{
img1_ref = img1.GetPixel(i, j).ToString();
img2_ref = img2.GetPixel(i, j).ToString();
if (img1_ref != img2_ref)
{
count2++;
flag = false;
break;
}
count1++;
}
}
if (flag == false)
MessageBox.Show("No matches found!");
else
MessageBox.Show("Match found!");
string cid = MyReader.GetString("CID");
textBox1.Text = cid;
}
else
MessageBox.Show("Something went wrong!");
}
MyConn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
The code also has the below part at the beginning;
Bitmap img1,img2;
int count1 = 0, count2 = 0;
bool flag = true;