/// <summary>
        /// Chup hinh nhan dang
        /// </summary>
        /// <param name="pTransactionID"></param>
        /// <param name="pLaneID"></param>
        public int CaptureImage(string pTransactionID, string pLaneID)
        {
            int retValue = 0;

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

                // Start capture
                mFxCamera.StartCapture();

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

                // Wait for valid frame
                //mFxCamera.GetCaptureInfo();
                int cap_frameix = mFxCamera.GetPropertyInt("captureinfo/newestframeix");

                gxImage image = new gxImage();
                for (int i = 1; i <= NumPictures; i++)
                {
                    // Save image at local folder
                    mFxCamera.GetFrame((int)FXCAM_GETFRAME_FLAGS.FXCAM_GETFRAME_NEWEST, 0, image);
                    if (image.GetPixelFormat() != (int)GX_PIXELFORMATS.GX_GRAY)
                    {
                        image.Convert((int)GX_PIXELFORMATS.GX_RGB);     // color image
                    }
                    image.Save(DefaultFileName, (int)GX_IMGFILEFORMATS.GX_JPEG);

                    ///TEST LOG
                    //WriteLogFile(this.GetType() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Start save image at server");

                    // Save image at server
                    string   pFileName = pTransactionID + "_" + pLaneID + "_" + i.ToString();
                    string   subfolder = string.Empty;
                    string[] temp      = pFileName.Split('_');
                    string   path      = string.Empty;
                    if (System.IO.Directory.Exists(RootFolder))
                    {
                        path  = RootFolder;
                        path += @"\" + pFileName.Substring(0, 10);
                        path += @"\" + temp[1];//004
                        if (!System.IO.Directory.Exists(path))
                        {
                            //Neu thu muc chua ton tai->tao thu muc do'
                            Directory.CreateDirectory(path);
                        }

                        ///TEST LOG
                        //WriteLogFile(this.GetType() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Check exists recog folder");

                        if (System.IO.Directory.Exists(path))
                        {
                            using (Image tempPic = Image.FromFile(DefaultFileName)) //chỗ này nếu ko chụp dc hình thì phải tạo 1 ảnh tạm
                            {
                                string pFullPath = path + @"\" + pFileName + ".jpg";
                                tempPic.Save(pFullPath);
                            }
                        }
                        else
                        {
                            WriteLogFile(this.GetType() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Cannot create folder: " + path);
                            return(-1); //Khong copy hinh len server duoc
                        }
                    }
                    else
                    {
                        WriteLogFile(this.GetType() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Folder " + RootFolder + " doesn't exist");
                    }
                }
                // Stop capture
                mFxCamera.StopCapture();

                ///TEST LOG
                //WriteLogFile(this.GetType() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Stop Capture");

                retValue = 1;
            }
            catch (Exception ex)
            {
                WriteLogFile(this.GetType() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, ex.Message);
            }

            return(retValue);
        }
Beispiel #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);
            }
        }