Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            // Create grabber.
            FrameGrabber <DetectedFace[]> grabber = new FrameGrabber <DetectedFace[]>();

            // Create Face API Client.
            FaceClient faceClient = new FaceClient(new ApiKeyServiceClientCredentials(ApiKey))
            {
                Endpoint = Endpoint
            };

            // Set up a listener for when we acquire a new frame.
            grabber.NewFrameProvided += (s, e) =>
            {
                Console.WriteLine($"New frame acquired at {e.Frame.Metadata.Timestamp}");
            };

            // Set up Face API call.
            grabber.AnalysisFunction = async frame =>
            {
                Consolw.WriteLine("Submirring Frame");
                //Console.WriteLine($"Submitting frame acquired at {frame.Metadata.Timestamp}");
                // Encode image and submit to Face API.
                return((await faceClient.Face.DetectWithStreamAsync(frame.Image.ToMemoryStream(".jpg"))).ToArray());
            };

            // Set up a listener for when we receive a new result from an API call.
            grabber.NewResultAvailable += (s, e) =>
            {
                if (e.TimedOut)
                {
                    Console.WriteLine("API call timed out.");
                }
                //Error in making API calls
                else if (e.Exception != null)
                {
                    //Non-timed out exceptions
                    Console.WriteLine("API call threw an exception.");
                }
                else
                {
                    Console.WriteLine($"New result received for frame acquired at {e.Frame.Metadata.Timestamp}. {e.Analysis.Length} faces detected");
                }
            };

            // Tell grabber when to call API.
            // See also TriggerAnalysisOnPredicate
            grabber.TriggerAnalysisOnInterval(TimeSpan.FromMilliseconds(3000));

            // Start running in the background.
            grabber.StartProcessingCameraAsync().Wait();

            // Wait for keypress to stop
            Console.WriteLine("Press any key to stop...");
            Console.ReadKey();

            // Stop, blocking until done.
            grabber.StopProcessingAsync().Wait();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
#if (FOO)
            Console.WriteLine("FOO is defined");
#else
            Consolw.WriteLine("FOO is not defined");
#endif
#if (BAR)
            Console.WriteLine("BAR is defined");
#else
            Console.WriteLine("BAR is not defined");
#endif
#if (DEBUG && !VC_V10)
            Console.WriteLine("DEBUG is defined");
#elif (!DEBUG && VC_V10)
            Console.WriteLine("VC_V10 is defined");
#elif (DEBUG && VC_V10)
            Console.WriteLine("DEBUG && VC_V10 are both defined");
#endif
        }