mirror of
https://github.com/kingomarnajjar/Cognitive-Samples-VideoFrameAnalysis.git
synced 2026-07-25 22:27:34 +10:00
Don't call Emotion API if OpenCv found no faces locally. (#4)
* Don't call Emotion API if OpenCv found no faces locally. See [this](http://stackoverflow.com/questions/42597067/emotion-recognition-real-time-analysis-api-calls) for context. * Move line for consistency
This commit is contained in:
parent
779049ed3a
commit
0aad9934ba
1 changed files with 11 additions and 5 deletions
|
|
@ -206,7 +206,14 @@ namespace LiveCameraSample
|
|||
|
||||
// See if we have local face detections for this image.
|
||||
var localFaces = (OpenCvSharp.Rect[])frame.UserData;
|
||||
if (localFaces != null)
|
||||
if (localFaces == null)
|
||||
{
|
||||
// If localFaces is null, we're not performing local face detection.
|
||||
// Use Cognigitve Services to do the face detection.
|
||||
Properties.Settings.Default.EmotionAPICallCount++;
|
||||
emotions = await _emotionClient.RecognizeAsync(jpg);
|
||||
}
|
||||
else if (localFaces.Count() > 0)
|
||||
{
|
||||
// If we have local face detections, we can call the API with them.
|
||||
// First, convert the OpenCvSharp rectangles.
|
||||
|
|
@ -218,16 +225,15 @@ namespace LiveCameraSample
|
|||
Width = f.Width,
|
||||
Height = f.Height
|
||||
});
|
||||
Properties.Settings.Default.EmotionAPICallCount++;
|
||||
emotions = await _emotionClient.RecognizeAsync(jpg, rects.ToArray());
|
||||
}
|
||||
else
|
||||
{
|
||||
// If not, the API will do the face detection.
|
||||
emotions = await _emotionClient.RecognizeAsync(jpg);
|
||||
// Local face detection found no faces; don't call Cognitive Services.
|
||||
emotions = new Emotion[0];
|
||||
}
|
||||
|
||||
// Count the API call.
|
||||
Properties.Settings.Default.EmotionAPICallCount++;
|
||||
// Output.
|
||||
return new LiveCameraResult
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue