
Don Zalmrol
Belgium
Asked
— Edited
Hello all,
I have a question concerning the camera usage in visual studio 10, C#.
Is it possible to use this with a thread?
The problem is that my program is starting to run very very slowly when the camera is activated for facial detections
This is my code
if (!ezb.Camera.IsActive)
{
return;
}
ObjectLocation objectLocation = ezb.CameraFaceDetection.GetFaceDetection();
if (!objectLocation.isFound)
{
turnAway = true;
timer2.Start();
timer4.Stop();
timer4.Dispose();
}
if (objectLocation.isFound)
{
interactie();
textBox1.AppendText(Environment.NewLine);
textBox1.AppendText("Face found");
textBox1.AppendText(Environment.NewLine);
}
When the program sees a face it goes to the method "interact();" or in English "interaction();"
But then the program seems to halt and running slowly
Thanks in advance for the help.
Cheers,
Laurens
That is how you would do it, yes. The speed of your program depends on the entire program, not just that sniplet. It matters how you are executing that bit of code. Is that being executed in a timer? Is it in a loop? How many times a second are you calling it? Is any throttling mechanism in place to prevent it from eating up all available cpu cycles within the loop?
If you paste more code, i can help you
Hi DJ, Thx for helping me.
The code for the cam is being executed by a timer. The cam must be active whenever it comes across an object. Then it will scan if it is a human. When I run it the program "works" but when the cam is active the cam stops working, but the program continuous to work.
But the cam won't activate anymore
This is my whole code:
There are a lot of thread timers. timers that are unused. primarily because they all share the same thread anyway. Have you looked at Omnibot's code example? I think that is more of what you are trying to do. You only need one timer to do everything.
Allright, thx.
We will look into that.
A small side-question: Is it possible to use more then one class? Like the form only as the representation level and other classes for face detection, voice interaction, movement?
What do you mean use more than one class?
Like you have your Form1.cs and Program.cs classes. Now we only need to improve the performance of our code
The program now is using 1 timer and running smoother then before! Thx for the reference!
The code is working much better now, but we still have a small problem with the voice recognition.
When the robot ping sensor sees an object (<= 4 inches) it stops and checks with the camera is the object is a human. If the object is not a human, the robot turn left or right and goes on.
This works, but when the robot detects a human face. The program "jumps" to the interaction method for voice detection/synthesis.
The robot does this, but is stuck in a loop and repeats the same command over & over again (i.e. you say "sing" the robot sings, but when the robot says your face again, it start to sing all over again)
To make it easier to follow the program here is my new code: