比较 "if" 构造中的值时出错
Error comparing values in "if" construct
我正在做一个人脸识别项目,我想将x.label
返回值与保存到数据库中的ID
进行比较。
我总是在 if
条件下将 ID 与 x.label
进行比较时出错
public int Predict(Image<Gray, Byte> testImage)
{
Emgu.CV.FaceRecognizer.PredictionResult x;
if (testImage != null)
{
x= fr.Predict(testImage);
pictureBox1.Image = testImage.ToBitmap();
//MessageBox.Show(x.Label.ToString()+" "+x.Distance.ToString());
OleDbCommand D1 = new OleDbCommand("Select [ID] FROM [connect]", DBConnection);
OleDbDataReader reader = D1.ExecuteReader();
while (reader.Read())
{
if (Convert.ToInt32(reader["ID"]) == x.Label)
{
OleDbCommand insert1 = new OleDbCommand("UPDATE OutputReport SET [Attendance]='yes' WHERE [StudentID]='109';", DBConnection);
insert1.ExecuteNonQuery();
MessageBox.Show(" its working");
}
}
RefreshDBConnection();
if (x.Distance < 69)
return x.Label;
else
MessageBox.Show("Error!!, The detected Face is neither recognised nor enrolled");
return -1;
}
else
{
return -1;
}
}
如果我的理解是正确的,您需要检查 x.Label 值与 MS-Access 数据库中的 ID 列值。为此,您需要执行 reader 并分配值。
public int Predict(Image<Gray, Byte> testImage)
{
Emgu.CV.FaceRecognizer.PredictionResult x;
if (testImage != null)
{
x= fr.Predict(testImage);
pictureBox1.Image = testImage.ToBitmap();
//MessageBox.Show(x.Label.ToString()+" "+x.Distance.ToString());
OleDbCommand D1 = new OleDbCommand("Select [ID] FROM [connect]", DBConnection);
OleDbDataReader reader = D1.ExecuteReader();
while (reader.Read())
{
if (Convert.ToInt32(reader["ID"]) == x.Label)
{
OleDbCommand insert1 = new OleDbCommand("UPDATE OutputReport SET [Attendance]='yes' WHERE [StudentID]='109';", DBConnection);
int i= insert1.ExecuteNonQuery();
MessageBox.Show(i.ToString());
}
}
RefreshDBConnection();
if (x.Distance < 69)
return x.Label;
else
MessageBox.Show("Error!!, The detected Face is neither recognised nor enrolled");
return -1;
}
else
{
return -1;
}
}
我正在做一个人脸识别项目,我想将x.label
返回值与保存到数据库中的ID
进行比较。
我总是在 if
条件下将 ID 与 x.label
public int Predict(Image<Gray, Byte> testImage)
{
Emgu.CV.FaceRecognizer.PredictionResult x;
if (testImage != null)
{
x= fr.Predict(testImage);
pictureBox1.Image = testImage.ToBitmap();
//MessageBox.Show(x.Label.ToString()+" "+x.Distance.ToString());
OleDbCommand D1 = new OleDbCommand("Select [ID] FROM [connect]", DBConnection);
OleDbDataReader reader = D1.ExecuteReader();
while (reader.Read())
{
if (Convert.ToInt32(reader["ID"]) == x.Label)
{
OleDbCommand insert1 = new OleDbCommand("UPDATE OutputReport SET [Attendance]='yes' WHERE [StudentID]='109';", DBConnection);
insert1.ExecuteNonQuery();
MessageBox.Show(" its working");
}
}
RefreshDBConnection();
if (x.Distance < 69)
return x.Label;
else
MessageBox.Show("Error!!, The detected Face is neither recognised nor enrolled");
return -1;
}
else
{
return -1;
}
}
如果我的理解是正确的,您需要检查 x.Label 值与 MS-Access 数据库中的 ID 列值。为此,您需要执行 reader 并分配值。
public int Predict(Image<Gray, Byte> testImage)
{
Emgu.CV.FaceRecognizer.PredictionResult x;
if (testImage != null)
{
x= fr.Predict(testImage);
pictureBox1.Image = testImage.ToBitmap();
//MessageBox.Show(x.Label.ToString()+" "+x.Distance.ToString());
OleDbCommand D1 = new OleDbCommand("Select [ID] FROM [connect]", DBConnection);
OleDbDataReader reader = D1.ExecuteReader();
while (reader.Read())
{
if (Convert.ToInt32(reader["ID"]) == x.Label)
{
OleDbCommand insert1 = new OleDbCommand("UPDATE OutputReport SET [Attendance]='yes' WHERE [StudentID]='109';", DBConnection);
int i= insert1.ExecuteNonQuery();
MessageBox.Show(i.ToString());
}
}
RefreshDBConnection();
if (x.Distance < 69)
return x.Label;
else
MessageBox.Show("Error!!, The detected Face is neither recognised nor enrolled");
return -1;
}
else
{
return -1;
}
}