/// <summary> 
                 /// Connects to the camera on the NAO robot 
                 /// </summary> 
                 /// <param name="ip"> the ip address of the robot </param> 
                 /// <param name="format"> the video format desired </param> 
                 /// <param name="ColorSpace"> the video color space </param> 
                 /// <param name="FPS"> the FPS of the video </param> 
                public void connect(string ip,  NaoCamImageFormat format,  int ColorSpace,  
                                    int FPS)  
                
        {
             
                        try 
                         {
                 
                                if (naoCamera  !=  null)  
                                
                {
                     
                                        Disconnect();  
                                        
                }

                 
                 
                                        naoCamera  =  new VideoDeviceProxy(ip,  9559);
                 
                                // Attempt to unsubscribe incase program was not shut down properly 
                                try 
                                 {
                     
                                        naoCamera.unsubscribe("NAO Camera");  

                                        
                }  
                                catch (Exception)  
                                
                {
                     
                                        
                }

                 
                 
                                // subscribe to NAO Camera for easier access to camera memory 
                                naoCamera.subscribe("NAO Camera",  format.id,  ColorSpace,  FPS);

                // naoCamera.subscribe("NAO Camera", format.id, ColorSpace, FPS);
                            
            }  
                        catch (Exception e)  
                        
            {
                 
                                 // display error message and write exceptions to a file 
                                 // MessageBox.Show("Exception occurred, error log in C:\\NAOcam\\exception.txt"); 
                                    naoCamera  =  null;  

                                System.IO.File.WriteAllText(@"C:\\NAOcam\\exception.txt",  
                                                            e.ToString());  
                                
            }

                     
        }
Пример #2
0
                 /// <summary> 
                 /// Class constructor 
                 /// </summary> 
                 /// <param name="ip"> ip address of the robot </param> 
                 /// <param name="format"> image format to use </param> 
                 /// <param name="colorSpace"> color space to use </param> 
                 /// <param name="FPS"> FPS to use </param> 
                 /// <param name="currentCamera"> instance of the camera class to use 
                 ///</param> 
                 /// <param name="currentStorage"> instance of the DataStorage class to use 
                 ///</param> 
                public GetFrame(string ip,  NaoCamImageFormat format,  int colorSpace,  int 
                                FPS,  Camera currentCamera,  DataStorage currentStorage)  
                
        {
             
                            naoCam  =  currentCamera;  

                            storage  =  currentStorage;  
             
                        naoCam.connect(ip,  format,  colorSpace,  FPS);  

                        
        }
                // class constructor 
                public Camera()  
                
        {
             
                        // set up image formats 
                            NaoCamImageFormat format120  =  new NaoCamImageFormat();  

                            NaoCamImageFormat format240  =  new NaoCamImageFormat();  
                            NaoCamImageFormat format480  =  new NaoCamImageFormat();  
                            NaoCamImageFormat format960  =  new NaoCamImageFormat();  
             
                        format120.name  =   "160 * 120";  

                        format120.id      =  0;  
                        format120.width   =  160;  
                        format120.height  =  120;  
             
                        format240.name  =   "320 * 240";  

                        format240.id      =  1;  
                        format240.width   =  320;  
                        format240.height  =  240;  
                         format480.name   = "640 * 480";
                        format480.id     = 2;
                        format480.width  =  640;  
                        format480.height  =  480;  
             
                        format960.name  =   "1280 * 960";  

                        format960.id      =  3;  
                        format960.width   =  1280;  
                        format960.height  =  960;  
             
                        // add them to the formats list 
                        NaoCamImageFormats.Add(format120);  

                        NaoCamImageFormats.Add(format240);  
                        NaoCamImageFormats.Add(format480);  
                        NaoCamImageFormats.Add(format960);  
                        
        }
        private void initializeNaoComponents()
        {
            naoCam        = new Camera();
            currentFormat = naoCam.NaoCamImageFormats[2];
            HDFormat      = naoCam.NaoCamImageFormats[3];


            naoMotion        = new Motion();
            naoFaceDetection = new FaceDetection(IP);

            initialPosition = new System.Drawing.Point(this.Width / 2, this.Height / 2);
            pen             = new System.Drawing.Pen(System.Drawing.Brushes.Green);
            faceP1          = new System.Drawing.Point(-1, -1);
            faceP2          = new System.Drawing.Point(-1, -1);

            try
            {
                naoMotion.connect(IP);

                naoFaceDetection.initializeProxies();

                newFrames   = new GetFrame(IP, currentFormat, COLOR_SPACE, FPS, naoCam, storage);
                frameThread = new Thread(new ThreadStart(newFrames.grabFrame));
                frameThread.Start();

                faceThread = new Thread(new ThreadStart(naoFaceDetection.startDetecting));
                faceThread.Start();

                isCamInitialized = true;
                textBox1.Enabled = false;
            }
            catch (Exception ex)
            {
                isCamInitialized = false;
                System.IO.File.WriteAllText(@"C:\\NAOcam\\exception.txt", ex.ToString());
            }
            timer1.Start();
        }