コード例 #1
0
ファイル: Form1.cs プロジェクト: janzendi/photobooth
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     try
     {
         IsInit = false;
         MainCamera?.Dispose();
         APIHandler?.Dispose();
     }
     catch (Exception ex)
     {
         //    ReportError(ex.Message, false);
     }
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: Vaakh/AMeteostation
 public bool Initialize()
 {
     try
     {
         APIHandler = new CanonAPI();
         List <Camera> cameras = APIHandler.GetCameraList();
         if (!OpenSession())
         {
             Console.WriteLine("No camera found. Please plug in camera");
             APIHandler.CameraAdded += APIHandler_CameraAdded;
             WaitEvent.WaitOne();
             WaitEvent.Reset();
             return(false);
         }
         else
         {
             MainCamera.CloseSession(); Console.WriteLine("Session closed"); return(true);
         }
     }
     catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return(false); }
     finally
     {
         MainCamera?.Dispose();
         APIHandler.Dispose();
     }
 }
コード例 #3
0
 private void Window_Closing(object sender, CancelEventArgs e)
 {
     try
     {
         MainCamera?.Dispose();
         APIHandler?.Dispose();
     }
     catch (Exception ex) { Report.Error(ex.Message, false); }
 }
コード例 #4
0
ファイル: Program.cs プロジェクト: Vaakh/AMeteostation
        public bool TakePhoto(string[] camSettings)  //where cS[0] is ISO(sensitivity), cS[1] is Tv(exposition), cS[2] is Tv in bulb mode and cS[3] is Av(apperture)
        {
            try
            {
                APIHandler = new CanonAPI();
                if (OpenSession())
                {
                    if (!Error)
                    {
                        ImageSaveDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "RemotePhoto");
                        MainCamera.SetSetting(PropertyID.SaveTo, (int)SaveTo.Host);
                        MainCamera.SetSetting(PropertyID.ISO, ISOValues.GetValue(camSettings[0]).IntValue);
                        MainCamera.SetSetting(PropertyID.Av, AvValues.GetValue(camSettings[3]).IntValue);
                        MainCamera.SetCapacity(4096, int.MaxValue);
                        Console.WriteLine($"Set image output path to: {ImageSaveDirectory}");

                        Console.WriteLine("Taking photo with special settings...");
                        CameraValue tv = TvValues.GetValue(MainCamera.GetInt32Setting(PropertyID.Tv));
                        if (tv == TvValues.Bulb)
                        {
                            MainCamera.TakePhotoBulb(int.Parse(camSettings[2]));
                        }
                        else
                        {
                            MainCamera.SetSetting(PropertyID.Tv, TvValues.GetValue(camSettings[1]).IntValue);
                            MainCamera.TakePhoto();
                        }
                        WaitEvent.WaitOne();

                        if (!Error)
                        {
                            Console.WriteLine("Photo taken and saved"); return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return(false); }
            finally
            {
                MainCamera?.Dispose();
                APIHandler.Dispose();
            }
        }
コード例 #5
0
 private void Window_Closing(object sender, CancelEventArgs e)
 {
     IsUIInit = false;
     if (MainCamera != null)
     {
         MainCamera.Dispose();
     }
     if (Api != null)
     {
         Api.Dispose();
     }
 }
コード例 #6
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     IsUIInit = false;
     if (MainCamera != null)
     {
         MainCamera.Dispose();
     }
     if (Api != null)
     {
         Api.Dispose();
     }
 }
コード例 #7
0
 private void Window_Closing(object sender, CancelEventArgs e)
 {
     try
     {
         if (MainCamera != null)
         {
             MainCamera.Dispose();
         }
         if (Api != null)
         {
             Api.Dispose();
         }
     }
     catch (Exception ex) { ShowError(ex); }
 }
コード例 #8
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     try
     {
         if (MainCamera != null)
         {
             MainCamera.Dispose();
         }
         if (Api != null)
         {
             Api.Dispose();
         }
     }
     catch (Exception ex) { ShowError(ex); }
 }
コード例 #9
0
ファイル: Program.cs プロジェクト: iPumpurs/bakalaura_darbs
        static void Main(string[] args)
        {
            try
            {
                APIHandler = new CanonAPI();
                List <Camera> cameras = APIHandler.GetCameraList();
                if (!OpenSession())
                {
                    Console.WriteLine("No camera found. Please plug in camera");
                    APIHandler.CameraAdded += APIHandler_CameraAdded;
                    WaitEvent.WaitOne();
                    WaitEvent.Reset();
                }

                if (!Error)
                {
                    ImageSaveDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "RemotePhoto");
                    MainCamera.SetSetting(PropertyID.SaveTo, (int)SaveTo.Host);
                    MainCamera.SetCapacity(4096, int.MaxValue);
                    Console.WriteLine($"Set image output path to: {ImageSaveDirectory}");

                    Console.WriteLine("Taking photo with current settings...");
                    CameraValue tv = TvValues.GetValue(MainCamera.GetInt32Setting(PropertyID.Tv));
                    if (tv == TvValues.Bulb)
                    {
                        MainCamera.TakePhotoBulb(2);
                    }
                    else
                    {
                        MainCamera.TakePhoto();
                    }
                    WaitEvent.WaitOne();

                    if (!Error)
                    {
                        Console.WriteLine("Photo taken and saved");
                    }
                }
            }
            catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); }
            finally
            {
                MainCamera?.Dispose();
                APIHandler.Dispose();
                Console.WriteLine("Good bye! (press any key to close)");
                Console.ReadKey();
            }
        }
コード例 #10
0
        public async Task <object> EndSession(dynamic input)
        {
            LogMessage("Ending session");

            MainCamera?.Dispose();
            MainCamera = null;
            Api.Dispose();
            Api = null;

            var result = new NodeResult();

            result.message = "Camera session ended.";
            result.success = true;

            return(result);
        }
コード例 #11
0
ファイル: CameraManager.cs プロジェクト: cxren/EDSDKLib-1.1.2
 private void Window_Closing(object sender, CancelEventArgs e)
 {
     try
     {
         IsInit = false;
         MainCamera?.Dispose();
         APIHandler?.Dispose();
     }
     catch (Exception ex) {
         ReportError(ex.Message, false);
         if (sendToUnity != null)
         {
             sendToUnity.Invoke("{\"error\":" + ex.Message + "}");
         }
     }
 }
コード例 #12
0
        void PhotoViewerForm_Closing(object sender, CancelEventArgs e)
        {
            if (ReferenceEquals(_canonApi, null))
            {
                _isInitCanonApi = false;
                return;
            }

            try
            {
                if (!ReferenceEquals(_currentCamera, null))
                {
                    _currentCamera.Dispose();
                }
                _canonApi.Dispose();
                _isInitCanonApi = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #13
0
        private void StopCamera()
        {
            IsInit = false;

            CloseSession();
            try
            {
                MainCamera?.Dispose();
                MainCamera = null;

                APIHandler?.Dispose();
                APIHandler.CameraAdded -= APIHandler_CameraAdded;
                APIHandler              = null;

                ErrorHandler.SevereErrorHappened    -= ErrorHandler_SevereErrorHappened;
                ErrorHandler.NonSevereErrorHappened -= ErrorHandler_NonSevereErrorHappened;
            }
            catch (Exception ex)
            {
                ReportError("Error stopping camera: " + ex.Message, false);
            }
        }
コード例 #14
0
 private void CloseCamera()
 {
     CloseSession();
     _mainCamera?.Dispose();
     APIHandler?.Dispose();
 }
コード例 #15
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     api.Dispose();
 }
コード例 #16
0
        static void Main(string[] args)
        {
            try
            {
                APIHandler = new CanonAPI();
                List <Camera> cameras = APIHandler.GetCameraList();
                if (!OpenSession())
                {
                    Console.WriteLine("No camera found. Please plug in camera");
                    APIHandler.CameraAdded += APIHandler_CameraAdded;
                    WaitEvent.WaitOne();
                    WaitEvent.Reset();
                }

                if (!Error)
                {
                    //ImageSaveDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "RemotePhoto");
                    ImageSaveDirectory = "G:\\CSE260\\dataset\\3";
                    MainCamera.SetSetting(PropertyID.SaveTo, (int)SaveTo.Host);
                    MainCamera.SetCapacity(4096, int.MaxValue);
                    Console.WriteLine($"Set image output path to: {ImageSaveDirectory}");

                    int SHUTTER_ID = 30;

                    // Get aperture and shutter speed tables
                    CameraValue[] AvList = MainCamera.GetSettingsList(PropertyID.Av);
                    CameraValue[] TvList = MainCamera.GetSettingsList(PropertyID.Tv);


                    // Loop over all aperture
                    for (int i_av = 0; i_av < AvList.Length; ++i_av)
                    {
                        // Validate shutter speed
                        if (SHUTTER_ID - i_av >= TvList.Length)
                        {
                            Console.WriteLine("shutter speed out of bounds");
                            break;
                        }


                        // Set Aperture and Shutter Speed
                        MainCamera.SetSetting(PropertyID.Av, AvValues.GetValue((string)AvList[i_av]).IntValue);
                        MainCamera.SetSetting(PropertyID.Tv, TvValues.GetValue((string)TvList[SHUTTER_ID - i_av]).IntValue);

                        Console.WriteLine("set av to " + (string)AvList[i_av]);
                        Console.WriteLine("set tv to " + (string)TvList[SHUTTER_ID - i_av]);

                        System.Threading.Thread.Sleep(500);

                        int now_av = MainCamera.GetInt32Setting(PropertyID.Av);
                        int now_tv = MainCamera.GetInt32Setting(PropertyID.Tv);

                        if ((int)AvList[i_av] != now_av)
                        {
                            Console.WriteLine("av comfirmation failed");
                        }
                        if ((int)TvList[SHUTTER_ID - i_av] != now_tv)
                        {
                            Console.WriteLine("tv comfirmation failed");
                        }


                        double shutterTime = TvList[SHUTTER_ID - i_av].DoubleValue;
                        int    waitTime    = (int)(shutterTime * 1000 + 2000);
                        Console.WriteLine("Wait Time is " + waitTime);

                        // 22 +3 Steps
                        for (int f = 0; f < 22; ++f)
                        {
                            int actualf = f;
                            if (!atFar)
                            {
                                actualf = 21 - f;
                            }

                            ImageFileName = now_av + "_" + actualf + ".CR3";

                            MainCamera.TakePhoto();

                            System.Threading.Thread.Sleep(waitTime);

                            // Flip the step direction each time to save time
                            if (atFar)
                            {
                                MainCamera.SendCommand(CameraCommand.DriveLensEvf, (int)DriveLens.Near3);
                            }
                            else
                            {
                                MainCamera.SendCommand(CameraCommand.DriveLensEvf, (int)DriveLens.Far3);
                            }

                            System.Threading.Thread.Sleep(500);
                        }

                        // Flip far->near and far<-near
                        atFar = !atFar;
                    }

                    /*
                     * try { MainCamera.SendCommand(CameraCommand.DriveLensEvf, (int)DriveLens.Far3); }
                     * catch (Exception ex)
                     * { Console.WriteLine(ex); }*/

                    /*
                     * Console.WriteLine("Taking photo with current settings...");
                     * CameraValue tv = TvValues.GetValue(MainCamera.GetInt32Setting(PropertyID.Tv));
                     * if (tv == TvValues.Bulb) MainCamera.TakePhotoBulb(2);
                     * else MainCamera.TakePhoto();
                     * WaitEvent.WaitOne();
                     */

                    if (!Error)
                    {
                        Console.WriteLine("Photo taken and saved");
                    }
                }
            }
            catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); }
            finally
            {
                Console.WriteLine("finally");
                MainCamera?.Dispose();
                APIHandler.Dispose();
                Console.WriteLine("Good bye! (press any key to close)");
                Console.ReadKey();
            }
        }
コード例 #17
0
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("Starting up...");
                Waiter = new AutoResetEvent(false);
                Api    = new CanonAPI();

                var camList = Api.GetCameraList();
                if (camList.Count == 0)
                {
                    Api.CameraAdded += Api_CameraAdded;
                    Console.WriteLine("Please connect a camera...");
                    Waiter.WaitOne();
                }
                else
                {
                    MainCamera = camList[0];
                }

                Console.WriteLine("Open session with " + MainCamera.DeviceName + "...");
                MainCamera.OpenSession();
                MainCamera.DownloadReady  += MainCamera_DownloadReady;
                MainCamera.FileDownloaded += MainCamera_FileDownloaded;
                MainCamera.SaveTo          = SaveTo.Host;
                MainCamera.SetCapacity(4096, 999999999);

                Console.WriteLine("Press any key to take a photo...");
                Console.ReadKey();
                if (MainCamera.IsShutterButtonAvailable)
                {
                    MainCamera.SC_PressShutterButton(ShutterButton.Completely);
                    MainCamera.SC_PressShutterButton(ShutterButton.OFF);
                }
                else
                {
                    MainCamera.SC_TakePicture();
                }

                Console.WriteLine("Waiting for download...");
                Waiter.WaitOne();

                Console.WriteLine("Closing session...");
                MainCamera.DownloadReady  -= MainCamera_DownloadReady;
                MainCamera.FileDownloaded -= MainCamera_FileDownloaded;
                MainCamera.CloseSession();
            }
            catch (DllNotFoundException) { Console.WriteLine("Canon DLLs not found. They should lie beside the executable."); }
            catch (SDKException SDKex)
            {
                if (SDKex.Error == ErrorCode.TAKE_PICTURE_AF_NG)
                {
                    Console.WriteLine("Couldn't focus");
                }
                else
                {
                    throw;
                }
            }
            catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); }
            finally
            {
                Console.WriteLine("Disposing resources...");
                if (MainCamera != null)
                {
                    MainCamera.Dispose();
                }
                if (Api != null)
                {
                    Api.Dispose();
                }
                Console.WriteLine("Press any key to close...");
                Console.ReadKey();
            }
        }
コード例 #18
0
        public async Task <object> TakePhoto(dynamic input)
        {
            NodeResult result = new NodeResult();

            try
            {
                Console.WriteLine("Called C# method from node.");
                APIHandler = new CanonAPI();

                Console.WriteLine("APIHandler initialised");
                List <Camera> cameras = APIHandler.GetCameraList();
                foreach (var camera in cameras)
                {
                    Console.WriteLine("APIHandler GetCameraList:" + camera);
                }

                if (cameras.Count > 0)
                {
                    MainCamera = cameras[0];
                    MainCamera.DownloadReady += MainCamera_DownloadReady;
                    MainCamera.OpenSession();
                    Console.WriteLine($"Opened session with camera: {MainCamera.DeviceName}");
                }
                else
                {
                    Console.WriteLine("No camera found. Please plug in camera");
                    APIHandler.CameraAdded += APIHandler_CameraAdded;
                    WaitEvent.WaitOne();
                    WaitEvent.Reset();
                }
                Console.WriteLine("OpenSession");
                if (!Error)
                {
                    if (ImageSaveDirectory == null)
                    {
                        ImageSaveDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "RemotePhoto");
                    }
                    MainCamera.SetSetting(PropertyID.SaveTo, (int)SaveTo.Host);
                    MainCamera.SetCapacity(4096, int.MaxValue);
                    Console.WriteLine($"Set image output path to: {ImageSaveDirectory}");

                    Console.WriteLine("Taking photo with current settings...");
                    CameraValue tv = TvValues.GetValue(MainCamera.GetInt32Setting(PropertyID.Tv));
                    if (tv == TvValues.Bulb)
                    {
                        MainCamera.TakePhotoBulb(2);
                    }
                    else
                    {
                        MainCamera.TakePhoto();
                    }
                    WaitEvent.WaitOne();

                    if (!Error)
                    {
                        Console.WriteLine("Photo taken and saved");
                    }
                    result.message = "Photo taken and saved";
                    result.success = true;
                }
            }
            catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); }
            finally
            {
                MainCamera?.Dispose();
                APIHandler.Dispose();
                Console.WriteLine("Program exited.");
            }

            return(result);
        }