コード例 #1
0
        public static void Main()
        {
            var handle       = GetConsoleWindow();
            var defaultStyle = Corale.Colore.Core.Headset.Instance.CurrentEffectId;

            // Uncomment to hide consile window
            //ShowWindow(handle, SW_HIDE);

            currentColor = ColorEmotion.Neutral;
            targetColor  = currentColor;

            colorTimer           = new System.Timers.Timer();
            colorTimer.Interval  = 100;
            colorTimer.Elapsed  += OnTimedEventLerp;
            colorTimer.AutoReset = true;
            colorTimer.Enabled   = true;


            // Create a timer and set a two second interval.
            cameraTimer          = new System.Timers.Timer();
            cameraTimer.Interval = 3500;

            // Hook up the Elapsed event for the timer.
            cameraTimer.Elapsed += OnTimedEvent;

            // Have the timer fire repeated events (true is the default)
            cameraTimer.AutoReset = true;

            // Start the timer
            cameraTimer.Enabled = true;


            // enumerate video devices
            videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            // create video source
            videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString);
            // set NewFrame event handler
            videoSource.NewFrame += new NewFrameEventHandler(Video_NewFrame);
            videoSource.Start();



            Console.WriteLine("Press the Enter key to exit the program at any time... ");
            Console.ReadLine();

            cameraTimer.Dispose();
            colorTimer.Dispose();

            videoSource.Stop();
        }
コード例 #2
0
        static async void MakeRequest(string imageFilePath)
        {
            var client = new HttpClient();

            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "<inset your own key here>"); //
            string uri = "https://westus.api.cognitive.microsoft.com/emotion/v1.0/recognize?";
            HttpResponseMessage response;
            string responseContent;

            byte[] byteData = GetImageAsByteArray(imageFilePath);

            using (var content = new ByteArrayContent(byteData))
            {
                content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                response = await client.PostAsync(uri, content);

                responseContent = response.Content.ReadAsStringAsync().Result;
            }

            Console.WriteLine(responseContent);
            try
            {
                JToken rootToken          = JArray.Parse(responseContent).First;
                JToken faceRectangleToken = rootToken.First;

                JToken scoresToken = rootToken.Last;

                JEnumerable <JToken> scoreList = scoresToken.First.Children();

                string angerString     = scoreList.ToArray()[0].ToString().Split(':')[1];
                string contemptString  = scoreList.ToArray()[1].ToString().Split(':')[1];
                string disgustString   = scoreList.ToArray()[2].ToString().Split(':')[1];
                string fearString      = scoreList.ToArray()[3].ToString().Split(':')[1];
                string happinessString = scoreList.ToArray()[4].ToString().Split(':')[1];
                string neutralString   = scoreList.ToArray()[5].ToString().Split(':')[1];
                string sadnessString   = scoreList.ToArray()[6].ToString().Split(':')[1];
                string surpriseString  = scoreList.ToArray()[7].ToString().Split(':')[1];

                double anger     = Double.Parse(angerString);
                double contempt  = Double.Parse(contemptString);
                double disgust   = Double.Parse(disgustString);
                double fear      = Double.Parse(fearString);
                double happiness = Double.Parse(happinessString);
                double neutral   = Double.Parse(neutralString);
                double sadness   = Double.Parse(sadnessString);
                double surprise  = Double.Parse(surpriseString);

                sadness = sadness * 0.8;

                Console.WriteLine($"anger : {anger}");
                Console.WriteLine($"contempt : {contempt}");
                Console.WriteLine($"disgust: {disgust}");
                Console.WriteLine($"fear : {fear}");
                Console.WriteLine($"happiness : {happiness}");
                Console.WriteLine($"neutral : {neutral}");
                Console.WriteLine($"sadness : {sadness}");
                Console.WriteLine($"surprise : {surprise}");

                if (anger > Math.Max(contempt, disgust) && anger > Math.Max(fear, happiness) && anger > Math.Max(sadness, surprise))
                {
                    targetColor = ColorEmotion.Anger;
                }

                if (contempt > Math.Max(anger, disgust) && contempt > Math.Max(fear, happiness) && contempt > Math.Max(sadness, surprise))
                {
                    targetColor = ColorEmotion.Contempt;
                }

                if (disgust > Math.Max(contempt, anger) && disgust > Math.Max(fear, happiness) && disgust > Math.Max(sadness, surprise))
                {
                    targetColor = ColorEmotion.Disgust;
                }

                if (fear > Math.Max(contempt, disgust) && fear > Math.Max(anger, happiness) && fear > Math.Max(sadness, surprise))
                {
                    targetColor = ColorEmotion.Fear;
                }

                if (happiness > Math.Max(contempt, disgust) && happiness > Math.Max(fear, anger) && happiness > Math.Max(sadness, surprise))
                {
                    targetColor = ColorEmotion.Happiness;
                }

                if (sadness > Math.Max(contempt, disgust) && sadness > Math.Max(fear, happiness) && sadness > Math.Max(anger, surprise))
                {
                    targetColor = ColorEmotion.Sadness;
                }

                if (surprise > Math.Max(contempt, disgust) && surprise > Math.Max(fear, happiness) && surprise > Math.Max(sadness, anger))
                {
                    targetColor = ColorEmotion.Surprise;
                }
            }
            catch { }
        }
コード例 #3
0
        public static uint colorToUint(ColorCore _color)
        {
            uint result = (_color.r * 0x010000) + (_color.g * 0x000100) + (_color.b * 0x000001);

            return(result);
        }