Esempio n. 1
0
        private void SetCameraControlSourceAndResolution(string camName, string res)
        {
            LogDebug(String.Format("Setting camera to {0} at res {1}", camName, res));
            CameraChoice chooser = new CameraChoice();

            chooser.UpdateDeviceList();
            DsDevice       chosenCam   = chooser.GetCameraByName(camName);
            ResolutionList resolutions = Camera.GetResolutionList(chosenCam.Mon);

            Camera_NET.Resolution chosenRes = resolutions.Find(x => x.ToString() == res);
            camControl.SetCamera(chosenCam.Mon, chosenRes);
        }
Esempio n. 2
0
        public IHardwareProxy LoadFromHardwareId(string hardwareId)
        {
            if (string.IsNullOrEmpty(hardwareId))
            {
                return(null);
            }
            string[] parts = hardwareId.Split("|".ToCharArray());
            if (parts.Length < 2)
            {
                return(null);
            }

            Guid   id     = new Guid(parts[0]);
            string resstr = parts[1];

            CameraChoice cams    = new CameraChoice();
            IMoniker     moniker = null;

            foreach (var camera_device in cams.Devices)
            {
                if (camera_device.Mon != null)
                {
                    Guid camid;
                    camera_device.Mon.GetClassID(out camid);
                    if (camid == id)
                    {
                        moniker = camera_device.Mon;
                        break;
                    }
                }
            }
            if (moniker == null)
            {
                return(null);
            }
            ResolutionList resolutions = Camera.GetResolutionList(moniker);

            if (resolutions == null)
            {
                return(null);
            }

            for (int index = 0; index < resolutions.Count; index++)
            {
                if (resstr == resolutions[index].ToString())
                {
                    CameraProxy proxy = new CameraProxy();
                    proxy.SetCamera(moniker, resolutions[index]);
                    return(proxy);
                }
            }
            return(null);
        }
Esempio n. 3
0
        private void frm_camera_Load(object sender, EventArgs e)
        {
            CameraChoice _CameraChoice = new CameraChoice();

            // Get List of devices (cameras)
            _CameraChoice.UpdateDeviceList();

            // To get an example of camera and resolution change look at other code samples
            if (_CameraChoice.Devices.Count > 0)
            {
                // Device moniker. It's like device id or handle.
                // Run first camera if we have one
                var camera_moniker = _CameraChoice.Devices[0].Mon;

                // Set selected camera to camera control with default resolution
                imgVideo.SetCamera(camera_moniker, null);
            }
        }
Esempio n. 4
0
        public MainWindow()
        {
            settings_Path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\PC Camera" + slash;
            string[] names  = { "Time_Interval", "Images_Save_Location" };
            string[] values = { time_interval.ToString(), img_path };

            InitializeComponent();
            //  location + dir + @"PC Images\" + time + " PC.jpg"
            CameraChoice  _CameraChoice = new CameraChoice();
            CameraControl cam           = new CameraControl();

            _CameraChoice.UpdateDeviceList();
            var            moniker     = _CameraChoice.Devices[0].Mon;
            ResolutionList resolutions = Camera.GetResolutionList(moniker);

            DirCheck();
            //settings folder maker
            if (!Directory.Exists(settings_Path))
            {
                Directory.CreateDirectory(settings_Path);
            }

            //logger = new Logger(location + current_dir + "log file.txt", current_time);
            //if setting file exists
            if (!File.Exists(settings_Path + settings_file_name))
            {
                // Create a file to write to.
                JSONMaker maker = new JSONMaker(names.Length, names, values, settings_Path + settings_file_name);
            }
            //using (StreamReader sr = File.OpenText(settings_Path + settings_file_name))
            {
                read = new Reader.Reader(settings_Path + settings_file_name);
                //string s = "";
                //s = sr.ReadLine();
                time_interval  = Convert.ToInt32(read.ReturnValueOf("Time_Interval"));
                img_path       = read.ReturnValueOf("Images_Save_Location");
                time_out.Text += Convert.ToString(time_interval) + "\n";
                time_out.Text += Convert.ToString(img_path) + "\n";
                LogCheck();
            }

            Res.Text += "Resolutions " + "\n";
            logger.Information("Resolutions", current_time);
            foreach (Resolution r in resolutions)
            {
                Res.Text += Convert.ToString(r + "\n");
                logger.Information(Convert.ToString(r), current_time);
            }

            cam.SetCamera(moniker, resolutions[0]);
            Res.Text += "Starting Camera" + "\n";
            logger.Information("Starting Camera", current_time);
            var timer = new System.Timers.Timer
            {
                Interval = (1000 * 60) * time_interval
            };

            //this will run the ontimed function when time is elapsed
            timer.Elapsed += ontimed;
            temp           = "current mins are set to: ";
            Res.Text      += temp + Convert.ToString(time_interval) + "\n";
            logger.Information(temp + time_interval, current_time);
            //this starts the timer
            timer.Start();

            void ontimed(object sender, System.Timers.ElapsedEventArgs e)
            {   //the time at which the image got taken
                current_time = DateTime.Now.ToString("dddd dd MMMM yyyy hh.mm tt");
                //the location at which the mage will be stored along with the generic location
                //it is used to store images according to each day
                current_dir = DateTime.Now.ToString("dddd dd MMMM yyyy") + "\\";


                this.Dispatcher.Invoke(() =>
                {
                    try
                    {
                        DirCheck();
                        LogCheck();
                        user_image(current_time, current_dir);
                        pc_img(current_time, current_dir);
                        Log_info("Image captured at time ", current_time);
                        if (check == true)
                        {
                            Log_mins("minutes updated to ", current_time, time_interval);
                            temp      = "current mins are set to: ";
                            Res.Text += temp + Convert.ToString(time_interval) + "\n";
                            logger.Information(temp + time_interval, current_time);
                            check = false;
                        }
                        timer.Interval = (1000 * 60) * time_interval;
                    }
                    catch (Exception ex)
                    {
                        time_out.Text += ex.ToString() + "\n";
                        logger.Error(ex, current_time);
                    }
                });
            }

            void pc_img(string time, string dir)
            {
                var image = ScreenCapture.CaptureDesktop();

                image.Save(img_path + dir + @"PC Images\" + time + " PC.jpg", ImageFormat.Jpeg);

                {
                    /*
                     * System.Drawing.Rectangle bounds = Screen.GetBounds(System.Drawing.Point.Empty);
                     * using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
                     * {
                     *  using (Graphics g = Graphics.FromImage(bitmap))
                     *  {
                     *      g.CopyFromScreen(System.Drawing.Point.Empty, System.Drawing.Point.Empty, bounds.Size);
                     *  }
                     *  bitmap.Save("D:\\test.jpg", ImageFormat.Jpeg);
                     * }
                     */
                }
            }

            void user_image(string time, string dir)
            {
                this.Dispatcher.Invoke(() =>
                {
                    try
                    {
                        image_taker(time, dir);
                    }
                    catch (Exception ex)
                    {
                        time_out.Text = ex.ToString();
                    }
                });
            }

            void image_taker(string time, string dir)
            {
                try
                {
                    //image taker
                    // cam.SetCamera(moniker, resolutions[0]);
                    cam.SnapshotSourceImage().Save(img_path + dir + @"User Images\" + time + " User.png");
                    // cam.Dispose();
                }
                catch (Exception ex)
                {
                    time_out.Text += ex.ToString() + "\n";
                    logger.Error(ex, current_time);
                }
            }

            void Log_info(string info, string time)
            {
                time_out.Text += info + time + "\n";
                logger.Information(info, time);
            }

            void Log_mins(string info, string time, int mins)
            {
                time_out.Text += info + mins + "\n";
                logger.Information(info + mins, time);
            }

            void DirCheck()
            {
                //checks for directories
                if (!Directory.Exists(img_path + current_dir + @"PC Images\"))
                {
                    Directory.CreateDirectory(img_path + current_dir + @"PC Images\");
                }
                if (!Directory.Exists(img_path + current_dir + @"User Images\"))
                {
                    Directory.CreateDirectory(img_path + current_dir + @"User Images\");
                }
            }

            void LogCheck()
            {
                //checks for the log file
                if (logger == null || !logger.Exists())
                {
                    logger = new Logger(img_path + current_dir + "log file.txt", current_time);
                }
            }
        }