hi when you click on botton Recognize it display a error as follows: An unhandled exception of type 'System.NullReferenceException' occurred in CameraCapture.exe Additional information: Object reference not set to an instance of an object
in part: name = recognizer.Recognize (ExtFaces [faceNo]) ToString ().; stringOutput [faceNo] = name;
here is the link the code part:
private void RecognizeFaces(){
//detect faces from the gray-scale image and store into an array of type 'var',i.e 'MCvAvgComp[]'
Image
//Assign user-defined Values to parameter variables:
MinNeighbors = int.Parse(comboBoxMinNeigh.Text); // the 3rd parameter
WindowsSize = int.Parse(textBoxWinSiz.Text); // the 5th parameter
//ScaleIncreaseRate = Double.Parse(comboBoxScIncRte.Text); //the 2nd parameter
//for (int i = 0; i < NumNameLabels; i++)
//{
//NamePersons[i]=NameLabless[i]+"&"+IDLabless[i];
//}
var faces = grayframe.DetectHaarCascade(haar, ScaleIncreaseRate, MinNeighbors,
HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
new Size(WindowsSize, WindowsSize))[0];
if (faces.Length > 0)
{
Bitmap ExtractedFace; //empty
ExtFaces = new Image
faceNo = 0;
foreach (var face in faces)
{
// ImageFrame.Draw(face.rect, new Bgr(Color.Green), 3);
t = t + 1;
//set the size of the empty box(ExtractedFace) which will later contain the detected face
ExtractedFace = new Bitmap(face.rect.Width, face.rect.Height);
ExtFaces[faceNo] = new Image
ExtFaces[faceNo] = ExtFaces[faceNo].Resize(100, 100, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
//TermCriteria for face recognition with numbers of trained images like maxIteration
MCvTermCriteria termCrit = new MCvTermCriteria(ContTrain, 0.001);
if (trainingImages.ToArray().Length != 0)
{
//Eigen face recognizer
EigenObjectRecognizer recognizer = new EigenObjectRecognizer(
trainingImages.ToArray(),
NameLabless.ToArray(),
3000,
ref termCrit);
name = recognizer.Recognize(ExtFaces[faceNo]).ToString();
stringOutput[faceNo] = name;
}
faceNo++;
}
pbExtractedFaces.Image = ExtFaces[0].ToBitmap(); //draw the face detected in the 0th (gray) channel with blue color
t = 0;
if (stringOutput[0] == null)
{
label1.Text = "Unknown";
label9.Text = "";
}
//Draw the label for each face detected and recognized
else
{
//string[] label = stringOutput[faceNo].Split(',');
label1.Text = "Known";
// for (int i = 0; i < 2; i++)
//{
label9.Text = stringOutput[0];
//label7.Text = label[1];
//}
}
}
if (faceNo == 0)
{
MessageBox.Show("No face detected");
}
else
{
btnNextRec.Enabled = true;
btnPreviousRec.Enabled = true;
}
}
Hemant SrivastavaPosted Jun 5, 2013, 9:15 AM
khaledd khaleddPosted Jun 4, 2013, 10:05 PM
if there is no problem
Hemant SrivastavaPosted Jun 4, 2013, 5:43 PM
Also keep all your funtinality within try-catch block.
Sunny SharmaPosted Jun 4, 2013, 1:05 AM
Since I'm not aware of the API you're using nor explained by you, I can't guess the fragment what is causing the Exception. Well, apart of this I don't see any try...catch block inside your code which I suggest you to surround your codes with to track it down where actually this null value is being assigned and why?
Hope it helps :)
Thanks.