示例#1
0
 protected void LogMessage(string format, params object[] args)
 {
     ConcurrentLogger.WriteLine(String.Format(format, args));
 }
示例#2
0
        public Camera(CameraMode mode)
        {
            // Create grabber.
            grabber     = new FrameGrabber <ImageTag[]>();
            currentMode = mode;

            // Create Computer Vision API Client.
            _visionClient = new ComputerVisionClient(new ApiKeyServiceClientCredentials(ApiKey))
            {
                Endpoint = Endpoint
            };

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

                if (currentMode == CameraMode.Drinking)
                {
                    bool exists = System.IO.Directory.Exists(drinkingTagFolder);
                    if (!exists)
                    {
                        System.IO.Directory.CreateDirectory(drinkingTagFolder);
                    }

                    e.Frame.Image.SaveImage($@"{drinkingTagFolder}\picture_{DateTime.Now.ToLongTimeString().Replace(':', '_')}.jpg");
                }
                else if (currentMode == CameraMode.Negative)
                {
                    bool exists = System.IO.Directory.Exists(negativePicFolder);
                    if (!exists)
                    {
                        System.IO.Directory.CreateDirectory(negativePicFolder);
                    }

                    e.Frame.Image.SaveImage($@"{negativePicFolder}\picture_{DateTime.Now.ToLongTimeString().Replace(':', '_')}.jpg");
                }
                else if (currentMode == CameraMode.Prediction)
                {
                    bool exists = System.IO.Directory.Exists(predictionFolder);
                    if (!exists)
                    {
                        System.IO.Directory.CreateDirectory(predictionFolder);
                    }
                    exists = System.IO.Directory.Exists($@"{predictionFolder}\temp");
                    if (!exists)
                    {
                        System.IO.Directory.CreateDirectory($@"{predictionFolder}\temp");
                    }

                    string tempFilePath = $@"{predictionFolder}\temp\picture_{DateTime.Now.ToLongTimeString().Replace(':', '_')}.jpg";
                    e.Frame.Image.SaveImage(tempFilePath);
                    try
                    {
                        File.Move(tempFilePath, $@"{predictionFolder}\picture_{DateTime.Now.ToLongTimeString().Replace(':', '_')}.jpg");
                    }
                    catch
                    {
                    }
                }
            };

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