Ejemplo n.º 1
0
        private void CameraListLoad()
        {
            int numCameras = _grabber.GetNumCameras();

            if (numCameras == 0)
            {
                System.Windows.MessageBox.Show("No cameras found!");
            }

            CameraList.DataSource    = Enumerable.Range(0, numCameras).Select(i => string.Format("Camera {0}", i + 1)).ToList();
            CameraList.SelectedIndex = 0;
        }
        private List <string> LoadCameraList()
        {
            var numberOfCameras = _frameGrabber.GetNumCameras();

            if (numberOfCameras == 0)
            {
                //TODO: Listen from ShellViewModel for message about "No cameras found!"
            }

            var cameras = Enumerable.Range(0, numberOfCameras).Select(i => $"Camera {i + 1}");

            return(cameras.ToList());
        }
        /// <summary> Populate CameraList in the UI, once it is loaded. </summary>
        /// <param name="sender"> Source of the event. </param>
        /// <param name="e">      Routed event information. </param>
        private void CameraList_Loaded(object sender, RoutedEventArgs e)
        {
            int numCameras = _grabber.GetNumCameras();

            if (numCameras == 0)
            {
                MessageArea.Text = "No cameras found!";
            }

            var comboBox = sender as ComboBox;
            comboBox.ItemsSource = Enumerable.Range(0, numCameras).Select(i => string.Format("Camera {0}", i + 1));
            comboBox.SelectedIndex = 0;
        }
Ejemplo n.º 4
0
        /// <summary> Populate CameraList in the UI, once it is loaded. </summary>
        /// <param name="sender"> Source of the event. </param>
        /// <param name="e">      Routed event information. </param>
        private void CameraList_Loaded(object sender, RoutedEventArgs e)
        {
            int numCameras = _grabber.GetNumCameras();

            if (numCameras == 0)
            {
                MessageArea.Text = "No cameras found!";
            }

            var comboBox = sender as ComboBox;

            comboBox.ItemsSource   = Enumerable.Range(0, numCameras).Select(i => string.Format("Camera {0}", i + 1));
            comboBox.SelectedIndex = 1;

            //Kamera otomatik çalışacak.
            this.StartButton_Click(null, e);
        }
        private List <string> LoadCameraList()
        {
            var result          = new List <string>();
            var numberOfCameras = _frameGrabber.GetNumCameras();

            if (numberOfCameras == 0)
            {
                //TODO: Listen from ShellViewModel for message about "No cameras found!"
            }
            var cameras = Enumerable.Range(0, numberOfCameras).Select(i => string.Format("Camera {0}", i + 1));

            foreach (var camera in cameras)
            {
                result.Add(camera);
            }

            return(result);
        }
Ejemplo n.º 6
0
        /// <summary> Populate CameraList in the UI, once it is loaded. </summary>
        /// <param name="sender"> Source of the event. </param>
        /// <param name="e">      Routed event information. </param>
        private void CameraList_Loaded(object sender, RoutedEventArgs e)
        {
            int numCameras = _grabber.GetNumCameras();

            if (numCameras == 0)
            {
                MessageArea.Text = "No cameras found!";
            }

            List <string> ListData = new List <string>();

            for (int i = 0; i <= numCameras; i++)
            {
                if (i > 0)
                {
                    ListData.Add($"Camera {i}");
                }
            }
            if (!string.IsNullOrWhiteSpace(camoip))
            {
                ListData.Add("ipcam");
            }
            if (!string.IsNullOrWhiteSpace(dvrip))
            {
                for (int x = 1; x <= chs; x++)
                {
                    if (chs > 0)
                    {
                        ListData.Add($"DVR Network Camera {x}");
                    }
                }
            }
            if (!string.IsNullOrWhiteSpace(web))
            {
                ListData.Add("web");
            }

            var comboBox = sender as ComboBox;

            comboBox.ItemsSource   = ListData; //Enumerable.Range(0, numCameras).Select(i => string.Format("Camera {0}", i + 1));
            comboBox.SelectedIndex = 0;
            //selectedCamera = comboBox.SelectedItem.ToString();
        }
 private bool CanStartCamera(object obj)
 {
     return(_frameGrabber.GetNumCameras() > 0 && SelectedPersonGroup != null);
 }
Ejemplo n.º 8
0
        private static void Main(string[] args)
        {
            Console.WriteLine("Initializing Congestion Camera Console App...");

            // Get Secret variables.
            var configuration = new ConfigurationBuilder()
                                .AddUserSecrets <Program>()
                                .AddJsonFile("appsettings.json")
                                .AddEnvironmentVariables()
                                .AddCommandLine(args, GetCommandLineSwitchMappings())
                                .Build();

            var appSettings = configuration.GetSection("Settings").Get <AppSettings>();

            if (appSettings == null)
            {
                Console.WriteLine("Failed App Settings initialization. Need to set variables.");
                return;
            }
            if (!appSettings.IsValid())
            {
                return;
            }

            // Create Face API Client.
            var faceClient = new FaceClient(new ApiKeyServiceClientCredentials(appSettings.Face_API_Subscription_Key))
            {
                Endpoint = appSettings.Face_API_Endpoint
            };
            IList <FaceAttributeType?> faceAttributes = new FaceAttributeType?[]
            {
                FaceAttributeType.Age,
                FaceAttributeType.Gender,
                FaceAttributeType.Smile,
                FaceAttributeType.FacialHair,
                FaceAttributeType.HeadPose,
                FaceAttributeType.Glasses,
                FaceAttributeType.Emotion,
                FaceAttributeType.Accessories
            };

            // Create CosmosDB Client.
            FaceCountDB faceCountDB = new FaceCountDB(
                appSettings.FaceCountDB_Endpoint,
                appSettings.FaceCountDB_Key,
                appSettings.DatabaseId,
                appSettings.ContainerId);

            if (!faceCountDB.IsInitialized())
            {
                Console.WriteLine("Failed CosmosDB initialization.");
                return;
            }

            // Create grabber.
            FrameGrabber <IList <DetectedFace> > grabber = new FrameGrabber <IList <DetectedFace> >();

            // Check Cameras.
            // At this time, there is a memory leak issue in Opencv 4.*
            // https://github.com/opencv/opencv/issues/13255
            // If you want to disable the warning messages, you try to set the environment variable of OPENCV_VIDEOIO_PRIORITY_MSMF to 0.
            int numCameras = grabber.GetNumCameras();

            if (numCameras == 0)
            {
                Console.WriteLine("No cameras found.");
                return;
            }

            Console.WriteLine($"Deteced {numCameras} camera(s).");
            if (appSettings.CameraIndex + 1 > numCameras)
            {
                Console.WriteLine("'CameraIndex' is invalid");
                return;
            }

            // Set up a listener for when we acquire a new frame.
            grabber.NewFrameProvided += (s, e) =>
            {
            };

            // Set up Face API call.
            grabber.AnalysisFunction = async frame =>
            {
                // Encode image and submit to Face API.

                // After the "mask' attribute is supported on the latest Face .NET SDK,
                // will replace this method with DetectWithStreamAsync.
                return(await CallFaceApiAsync(frame.Image.ToMemoryStream(".jpg"), appSettings));

                //return await faceClient.Face.DetectWithStreamAsync(frame.Image.ToMemoryStream(".jpg"), true, false, faceAttributes);
                //return await faceClient.Face.DetectWithStreamAsync(frame.Image.ToMemoryStream(".jpg"), true, false,
                // Hope this "mask" attribute will be added to Face .NET SDK soon
                //returnFaceAttributes: new List<FaceAttributeType?> { FaceAttributeType.Mask },
                // The recognition_04 model (published 2021) is the most accurate model currently available.
                //recognitionModel: "recognition_04", returnRecognitionModel: true,
                // The detection_03 model (published 2021) is the latest model that should be used with recognition_04 model.
                //detectionModel: "detection_03");
            };

            // 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.");
                }
                else if (e.Exception != null)
                {
                    Console.WriteLine("API call threw an exception.");
                }
                else
                {
                    long maskCount = GetMaskCount2021(e.Analysis);
                    faceCountDB.UpdateFaceCount(e.Analysis.Count, maskCount, appSettings.PlaceName);
                    Console.WriteLine("New result received for frame acquired at {0}. {1} faces, {2} masks detected", e.Frame.Metadata.Timestamp, e.Analysis.Count, maskCount);
                }
            };

            // Tell grabber when to call API.
            // See also TriggerAnalysisOnPredicate
            grabber.TriggerAnalysisOnInterval(TimeSpan.FromSeconds(appSettings.AnalysisIntervalInSeconds));

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

            // Wait for keypress to stop
            Console.WriteLine("Congestion Camera Console App has been successfully started.");
            Console.WriteLine("Press any key to stop...");
            Console.ReadKey();

            // Stop, blocking until done.
            grabber.StopProcessingAsync().Wait();
        }