/// <summary>
        /// Khoi tao camera IP
        /// </summary>
        /// <param name="pIP"></param>
        /// <returns>1. OK, 0. Error</returns>
        public int InitCamera(string pIP)
        {
            try
            {
                // Init new object
                //mFxCamera = new fxCamera();

                mFxCamera.IsValid();

                // Connect to the camera
                mFxCamera.SetProperty("connect/devname", pIP);
                mFxCamera.Connect();

                // Stop capture
                mFxCamera.StopCapture();

                // Turn on automatic synchronization (synchronize the DSP time to PC time)
                // Don't use this if you have NTP synchronization in the camera
                mFxCamera.SetProperty("time/sync", 1);

                // Query camera information
                int img_width  = mFxCamera.GetPropertyInt("info/capture/xsize");
                int img_height = mFxCamera.GetPropertyInt("info/capture/ysize");

                if ((img_width == 0) || (img_height == 0))
                {
                    WriteLogFile(this.GetType() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name,
                                 string.Format("Unknown camera type: {0}", mFxCamera.GetPropertyInt("info/camera_type")));
                    return(0);
                }

                // Setup camera
                if (IS_CONFIG_CAMERA)
                {
                    mFxCamera.MPStartTransaction();

                    mFxCamera.SetProperty("capture/lights", 0);
                    mFxCamera.SetProperty("capture/again", 100);
                    mFxCamera.SetProperty("capture/dgain", 100);
                    mFxCamera.SetProperty("capture/shutter", 5000);
                    mFxCamera.SetProperty("capture/fps", mFxCamera.GetPropertyInt("info/capture/fps"));
                    mFxCamera.SetProperty("capture/gamma", 1);          // 0: linear, 1: gamma

                    mFxCamera.SetProperty("camera/led_infra", 1);       // 1 = turn on all LEDs (0=off)
                    mFxCamera.SetProperty("camera/led_power", 1);       // normal: 16V
                    mFxCamera.SetProperty("camera/led_timeus", 100);    // 100us

                    mFxCamera.SetProperty("imgproc/shutter/max", 10000);
                    mFxCamera.SetProperty("imgproc/again/max", 200);
                    mFxCamera.SetProperty("capture/color", 0);

                    mFxCamera.MPCommit();
                }

                // Switch to automatic mode
                mFxCamera.SwitchMode((int)FXCAM_MODES.FXCAM_MODE_AUTOMATIC);

                // Unlock all locked frames if there is any
                mFxCamera.UnlockFrames((ushort)FXCAM_UNLOCK_FLAGS.FXCAM_UNLOCK_RELEASE_ALL, 0, 0);

                return(1);
            }
            catch (Exception ex)
            {
                WriteLogFile(this.GetType() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, ex.Message);
                return(0);
            }
        }
Exemple #2
0
        public bool StartCameraService()
        {
            try
            {
                this.cam = new fxCamera();
                // Check the fxcam module
                cam.IsValid();

                // Connect to the camera
                Console.Write("Connect to the camera...");
                cam.SetProperty("connect/devname", this.Ip);
                cam.Connect();
                Console.WriteLine("OK");

                // Stop capture
                cam.StopCapture();

                // Turn on automatic synchronization (synchronize the DSP time to PC time)
                // Don't use this if you have NTP synchronization in the camera
                cam.SetProperty("time/sync", 1);

                // Query camera information
                int img_width  = cam.GetPropertyInt("info/capture/xsize");
                int img_height = cam.GetPropertyInt("info/capture/ysize");

                if ((img_width == 0) || (img_height == 0))
                {
                    Console.WriteLine("Unknown camera type: {0}", cam.GetPropertyInt("info/camera_type"));
                    return(false);
                }

                // Setup camera
                Console.Write("Setup camera...");
                cam.MPStartTransaction();


                cam.SetProperty("capture/again", 100);
                cam.SetProperty("capture/dgain", 100);
                HPS.BLL.InCameraPicturesBLL.BLLInCameraPictures_TFactory factory = new HPS.BLL.InCameraPicturesBLL.BLLInCameraPictures_TFactory();
                //if (factory.ServerTime.CompareTo("20:00:00")>0 && factory.ServerTime.CompareTo("06:00:00")<0)
                //{
                cam.SetProperty("capture/shutter", 500);
                cam.SetProperty("capture/lights", 0);
                //}
                //else
                //{
                //    cam.SetProperty("capture/shutter",2500);
                //    cam.SetProperty("capture/lights", 1);
                //}

                cam.SetProperty("capture/fps", cam.GetPropertyInt("info/capture/fps"));
                cam.SetProperty("capture/gamma", 0);            // 0: linear, 1: gamma

                cam.SetProperty("camera/led_infra", 1);         // 1 = turn on all LEDs (0=off)
                cam.SetProperty("camera/led_power", 1);         // normal: 16V
                cam.SetProperty("camera/led_timeus", 100);      // 100us

                cam.SetProperty("imgproc/shutter/max", 10000);
                cam.SetProperty("imgproc/again/max", 200);
                cam.SetProperty("capture/color", 0);

                cam.MPCommit();
                Console.WriteLine("OK");

                // Switch to automatic mode
                Console.Write("Switch to the automatic mode...");
                cam.SwitchMode((int)FXCAM_MODES.FXCAM_MODE_AUTOMATIC);
                Console.WriteLine("OK");

                // Unlock all locked frames if there is any
                cam.UnlockFrames((ushort)FXCAM_UNLOCK_FLAGS.FXCAM_UNLOCK_RELEASE_ALL, 0, 0);

                // Start capture
                Console.Write("Start the capturing...");
                cam.StartCapture();
                Console.WriteLine("OK");

                //Waiting for the end of the camera initialization
                Thread.Sleep(2000);

                return(true);
            }
            catch
            {
                return(false);
            }
        }