Beispiel #1
0
        public gxImage GetGxImage()
        {
            if (this.cam == null)
            {
                return(null);
            }

            cam.GetCaptureInfo();
            int cap_frameix = cam.GetPropertyInt("captureinfo/newestframeix");

            gxImage image = new gxImage();

            //String fname = "";
            //fname = String.Format("getframe{0:00}.bmp", i);
            //Console.Write(String.Format("GetFrame {0}...", i));

            cam.GetFrame((int)FXCAM_GETFRAME_FLAGS.FXCAM_GETFRAME_NEWEST, 0, image);
            //  Console.WriteLine("OK");
            // Save to file
            if (image.GetPixelFormat() != (int)GX_PIXELFORMATS.GX_GRAY)
            {
                image.Convert((int)GX_PIXELFORMATS.GX_RGB);                                                             // color image
            }
            //Console.Write(String.Format("Save image: {0}...", fname));

            //image.Save(fname, (int)GX_IMGFILEFORMATS.GX_BMP);
            //Console.WriteLine("OK");

            //System.Drawing.Image img = System.Drawing.Image.FromStream(new System.IO.MemoryStream(image.SaveToMem((int)gx.GX_IMGFILEFORMATS.GX_JPEG)));
            return(image);
        }
Beispiel #2
0
        public Image GetImage()
        {
            gxImage gxImg = this.GetGxImage();

            System.Drawing.Image img = System.Drawing.Image.FromStream(new System.IO.MemoryStream(gxImg.SaveToMem((int)gx.GX_IMGFILEFORMATS.GX_JPEG)));
            return(img);
        }
Beispiel #3
0
    public int prSaveMRZImage()
    {
        try
        {
            if (_doc.IsValid())
            {
                /* Saving the MRZ image */
                gxImage img = _doc.FieldImage((int)(PR_DOCFIELD.PR_DF_MRZ1 & PR_DOCFIELD.PR_DF_MRZ2));
                if (img.IsValid())
                {
                    img.Save("mrz.jpg", (int)GX_IMGFILEFORMATS.GX_JPEG);
                }

                //_doc.Free();
                //_doc = null;
                //_pr.ResetDocument();
            }
        }
        catch (Exception e)
        {
            _errorMessage = e.Message + " --- prSaveMRZImage()";
            return(1305);
        }

        return(0);
    }
Beispiel #4
0
 public static byte[] ConvertWSQToBmp(WsqImage wsq)
 {
     _wsqImg = new gxImage();
     _wsqImg.Create(wsq.PixelFormat, wsq.XSize, wsq.YSize, 0);
     _wsqImg.xres(wsq.XRes);
     _wsqImg.yres(wsq.YRes);
     _wsqImg.LoadFromMem(wsq.Content, wsq.PixelFormat);
     return _wsqImg.SaveToMem((int)GX_IMGFILEFORMATS.GX_BMP);
 }
Beispiel #5
0
        private void scan_verso()
        {
            //PassportReader pr = new PassportReader();
            try
            {
                //pr.UseDevice(0, (int)PR_USAGEMODE.PR_UMODE_FULL_CONTROL);
                pr.Capture();


                if (File.Exists(Environment.ExpandEnvironmentVariables("%TEMP%\\") + "verso.jpeg"))
                {
                    File.Delete(Environment.ExpandEnvironmentVariables("%TEMP%\\") + "verso.jpeg");
                }
                pr.SaveImage(0, (int)PR_LIGHT.PR_LIGHT_WHITE, (int)PR_IMAGE_TYPE.PR_IT_DOCUMENT, Environment.ExpandEnvironmentVariables("%TEMP%/") + "verso.jpeg", (int)GX_IMGFILEFORMATS.GX_JPEG);

                prDoc   doc = pr.Recognize(0);
                gxImage img = doc.FieldImage((int)PR_DOCFIELD.PR_DF_VIZ_FACE);
                if (img != null)
                {
                    if (File.Exists(Environment.ExpandEnvironmentVariables("%TEMP%\\") + "PhotoIdentite.jpeg"))
                    {
                        File.Delete(Environment.ExpandEnvironmentVariables("%TEMP%\\") + "PhotoIdentite.jpeg");
                    }
                    img.Save(Environment.ExpandEnvironmentVariables("%TEMP%\\") + "PhotoIdentite.jpeg", (int)GX_IMGFILEFORMATS.GX_JPEG);
                }

                string temp;
                temp = doc.Field((int)PR_DOCFIELD.PR_DF_MRZ1) + doc.Field((int)PR_DOCFIELD.PR_DF_MRZ2) + doc.Field((int)PR_DOCFIELD.PR_DF_MRZ3);
                if (!temp.Equals(""))
                {
                    MRZ = temp;
                }
                else
                {
                    Program.LogFich.Info("[ScannerPiece] pas de piste MRZ sur le verso");
                }
            }
            catch (Exception ex)
            {
                Program.LogFich.Error("[ScannerPiece] n'a pas pu lire le verso du document : " + ex.ToString());
            }
            finally
            {
                //pr.CloseDevice();
                //pr.Close();
                //pr.Dispose();
                //pr = null;
            }
        }
Beispiel #6
0
        public int getValidPlates(gxImage image, ref List <string> list)
        {
            int count = 0;

            lock (this)
            {
                try
                {
                    // Finds the first plate and displays it
                    //QueryPerformanceCounter(&counter_before);
                    bool found = _anpr.FindFirst(image);
                    //QueryPerformanceCounter(&counter_after);
                    //double anprTime = (double)(counter_after.QuadPart - counter_before.QuadPart) / freq.QuadPart;

                    list.Clear();

                    while (found)
                    {
                        string resultLoop = _anpr.GetText();

                        if (isValidPlateString(resultLoop))
                        {
                            //Console.WriteLine("[OK]" + resultLoop);
                            list.Add(getAdjustPlate(resultLoop));
                            count++;
                        }
                        else
                        {
                            //Console.WriteLine("[NG]" + resultLoop);
                        }

                        // Finds other plates
                        found = _anpr.FindNext();
                    }
                    //printf("\n");
                    //printf("\nMemLoad:%lf\tAnpr:%lf\n", loadTime, anprTime);
                }
                catch (gxException e)
                {
                    System.Diagnostics.Debug.WriteLine("Get Plates Failed : " + e.ToString());
                }
            }
            return(count);
        }
Beispiel #7
0
        private static SerializeObject ProcessPhoto(SerializeObject anprInfo)
        {
            var anpr  = new cmAnpr("default");
            var image = new gxImage("default");

            image.Load(anprInfo.PhotoPath);

            if (!anpr.FindFirst(image))
            {
                throw new NotFoundPhotoException($"Nie znaleziono zdjęcia o ścieżce: {anprInfo.PhotoPath}");
            }
            var frame = anpr.GetFrame();

            anprInfo.Vehicles.First().PlateLPR   = anpr.GetText();
            anprInfo.Vehicles.First().Confidence = anpr.GetConfidence();
            anprInfo.Vehicles.First().PlateX     = frame.x1;
            anprInfo.Vehicles.First().PlateY     = frame.y1;
            //anprInfo.Vehicles.First().PlateHeight = ;
            //anprInfo.Vehicles.First().PlateWidth = ;

            //while (anpr.FindNext())
            //{
            //    frame = anpr.GetFrame();
            //    anprInfo.Vehicles.Add(new Vehicle
            //    {
            //        PlateLPR = anpr.GetText(),
            //        Confidence = anpr.GetConfidence(),
            //        PlateX = frame.x1,
            //        PlateY = frame.y1,
            //        //PlateHeight =
            //        //PlateWidth =
            //    });
            //}

            return(anprInfo);
        }
Beispiel #8
0
    public int prGetMRZImage(out byte[] buff)
    {
        buff = null;

        try
        {
            if (_doc.IsValid())
            {
                /* Creating a MRZ image */
                gxImage img = _doc.FieldImage((int)(PR_DOCFIELD.PR_DF_MRZ1 & PR_DOCFIELD.PR_DF_MRZ2));
                if (img.IsValid())
                {
                    buff = img.SaveToMem((int)GX_IMGFILEFORMATS.GX_JPEG);
                }
            }
        }
        catch (Exception e)
        {
            _errorMessage = e.Message + " --- prGetMRZImage()";
            return(1305);
        }

        return(0);
    }
Beispiel #9
0
        public void ANPRThreadFunction()
        {
            List <string>          anpr_result      = new List <string>();
            List <PLATE_CANDIDATE> plate_candidates = new List <PLATE_CANDIDATE>();
            GBUVideoFrame          frame            = new GBUVideoFrame();

            while (_isANPRThreadRun)
            {
                if (popMedia(ref frame))
                {
                    anpr_result.Clear();

                    gxImage targetImg = new gxImage("default");

                    targetImg.LoadFromMem(frame.frame, (int)GX_PIXELFORMATS.GX_RGB);

                    if (getValidPlates(targetImg, ref anpr_result) > 0)
                    {
                        // Remove old results
                        int currentTime = Environment.TickCount;
                        for (int i = plate_candidates.Count - 1; i >= 0; i--)
                        {
                            if (currentTime - plate_candidates[i].firstfoundTime > Constants.CANDIDATE_REMOVE_TIME)
                            {
                                plate_candidates.RemoveAt(i);
                            }
                        }

                        // Check duplicate
                        for (int i = 0; i < anpr_result.Count; i++)
                        {
                            bool isNew = true;

                            for (int j = 0; j < plate_candidates.Count; j++)
                            {
                                //if (_tcsnccmp(anpr_result[i].c_str(), plate_candidates[j].plate_string, _tcslen(anpr_result[i].c_str())) == 0)  {
                                if (anpr_result[i].Equals(plate_candidates[j].plate_string) ||
                                    (anpr_result[i].Substring(anpr_result[i].Length - 4, 4).Equals(plate_candidates[j].plate_string.Substring(plate_candidates[j].plate_string.Length - 4, 4))))
                                {
                                    isNew = false;
#if (!FAST_DETECT)
                                    PLATE_CANDIDATE modified;
                                    modified.firstfoundTime = plate_candidates[j].firstfoundTime;
                                    modified.foundCount     = plate_candidates[j].foundCount + 1;
                                    modified.id             = plate_candidates[j].id;
                                    modified.plate_string   = plate_candidates[j].plate_string;
                                    plate_candidates.RemoveAt(j);
                                    plate_candidates.Add(modified);

                                    if (modified.foundCount == CANDIDATE_COUNT_FOR_PASS)
                                    {
                                        // Announce Event
                                        //SetLog(cropregion, plate_candidates[j].plate_string, TEXT("msg"));

                                        //wchar_t eventlog[1024];
                                        //wsprintf(eventlog, TEXT("%s\t"), plate_candidates[j].plate_string);
                                        //OutputDebugString(eventlog);
                                        Console.WriteLine("Detected candidate : " + modified.plate_string);
                                        ANPRDetected(_camID, modified.plate_string, frame.frame);
                                    }
                                    break;
#endif
                                }
                            }

                            if (isNew)
                            {
                                currentTime = Environment.TickCount;
                                PLATE_CANDIDATE newItem;
                                newItem.firstfoundTime = currentTime;
                                newItem.foundCount     = 1;
                                newItem.plate_string   = anpr_result[i];
                                newItem.id             = 0;

                                plate_candidates.Add(newItem);
#if (FAST_DETECT)
                                Console.WriteLine("Detected candidate : " + newItem.plate_string);
                                ANPRDetected(_camID, newItem.plate_string, frame.frame);
#endif
                            }
                        }
                    }
                }

                // end of thread cycle
                Thread.Sleep(1);
            }
        }
Beispiel #10
0
        public int getValidPlates(gxImage image, ref List<string> list)
        {
            int count = 0;

            lock (this)
            {

                try
                {

                    // Finds the first plate and displays it
                    //QueryPerformanceCounter(&counter_before);
                    bool found = _anpr.FindFirst(image);
                    //QueryPerformanceCounter(&counter_after);
                    //double anprTime = (double)(counter_after.QuadPart - counter_before.QuadPart) / freq.QuadPart;

                    list.Clear();

                    while (found)
                    {
                        string resultLoop = _anpr.GetText();

                        if (isValidPlateString(resultLoop))
                        {
                            //Console.WriteLine("[OK]" + resultLoop);
                            list.Add(getAdjustPlate(resultLoop));
                            count++;

                        }
                        else
                        {
                            //Console.WriteLine("[NG]" + resultLoop);
                        }

                        // Finds other plates
                        found = _anpr.FindNext();
                    }
                    //printf("\n");
                    //printf("\nMemLoad:%lf\tAnpr:%lf\n", loadTime, anprTime);
                }
                catch (gxException e)
                {
                    System.Diagnostics.Debug.WriteLine("Get Plates Failed : " + e.ToString());
                }

            }
            return count;
        }
Beispiel #11
0
        public void ANPRThreadFunction()
        {
            List<string> anpr_result = new List<string>();
            List<PLATE_CANDIDATE> plate_candidates = new List<PLATE_CANDIDATE>();
            GBUVideoFrame frame = new GBUVideoFrame();

            while (_isANPRThreadRun)
            {

                if (popMedia(ref frame))
                {
                    anpr_result.Clear();

                    gxImage targetImg = new gxImage("default");

                    targetImg.LoadFromMem(frame.frame, (int)GX_PIXELFORMATS.GX_RGB);

                    if (getValidPlates(targetImg, ref anpr_result) > 0)
                    {

                        // Remove old results
                        int currentTime = Environment.TickCount;
                        for (int i = plate_candidates.Count - 1; i >= 0; i--)
                        {
                            if (currentTime - plate_candidates[i].firstfoundTime > Constants.CANDIDATE_REMOVE_TIME)
                            {
                                plate_candidates.RemoveAt(i);
                            }
                        }

                        // Check duplicate
                        for (int i = 0; i < anpr_result.Count; i++)
                        {
                            bool isNew = true;

                            for (int j = 0; j < plate_candidates.Count; j++)
                            {
                                //if (_tcsnccmp(anpr_result[i].c_str(), plate_candidates[j].plate_string, _tcslen(anpr_result[i].c_str())) == 0)  {
                                if (anpr_result[i].Equals(plate_candidates[j].plate_string) ||
                                     (anpr_result[i].Substring(anpr_result[i].Length - 4, 4).Equals(plate_candidates[j].plate_string.Substring(plate_candidates[j].plate_string.Length - 4, 4))))
                                {
                                    isNew = false;
            #if (!FAST_DETECT)
                                    PLATE_CANDIDATE modified;
                                    modified.firstfoundTime = plate_candidates[j].firstfoundTime;
                                    modified.foundCount = plate_candidates[j].foundCount + 1;
                                    modified.id = plate_candidates[j].id;
                                    modified.plate_string = plate_candidates[j].plate_string;
                                    plate_candidates.RemoveAt(j);
                                    plate_candidates.Add(modified);

                                    if (modified.foundCount == CANDIDATE_COUNT_FOR_PASS)
                                    {
                                        // Announce Event
                                        //SetLog(cropregion, plate_candidates[j].plate_string, TEXT("msg"));

                                        //wchar_t eventlog[1024];
                                        //wsprintf(eventlog, TEXT("%s\t"), plate_candidates[j].plate_string);
                                        //OutputDebugString(eventlog);
                                        Console.WriteLine("Detected candidate : " + modified.plate_string);
                                        ANPRDetected(_camID, modified.plate_string, frame.frame);
                                    }
                                    break;
            #endif
                                }
                            }

                            if (isNew)
                            {
                                currentTime = Environment.TickCount;
                                PLATE_CANDIDATE newItem;
                                newItem.firstfoundTime = currentTime;
                                newItem.foundCount = 1;
                                newItem.plate_string = anpr_result[i];
                                newItem.id = 0;

                                plate_candidates.Add(newItem);
            #if (FAST_DETECT)
                                Console.WriteLine("Detected candidate : " + newItem.plate_string);
                                ANPRDetected(_camID, newItem.plate_string, frame.frame);
            #endif
                            }
                        }
                    }

                }

                // end of thread cycle
                Thread.Sleep(1);
            }
        }
    public int fpsGetFingersImages(int handAndFingerMask, bool saveFingerAsFile)
    {
        try
        {
            if (_arrayOfBMP != null) { _arrayOfBMP.Clear(); _arrayOfBMP = null; }
            if (_arrayOfWSQ != null) { _arrayOfWSQ.Clear(); _arrayOfWSQ = null; }

            /* Search Finger */
            int reqid, stat;

            /* Clears internal stored finger buffers */
            _fps.ResetFingerList();

            /* Starts an asynchronous capture process
            // params: time in usec, quality in per-thousand, mode of live scan, fingerlist
            //
            // The finger list has the format 0hhh 0000 iiii mmmm rrrr llll tttt ssss
            //	h - scan object: 001 left hand, 010 right hand, 011 same fingers of both hands
            //	i - index finger	|
            //	m - middle finger	|
            //	r - ring finger		|--> value of FPS_PRESENCE   FPS_AVAILABLE = 3
            //	l - little finger	|
            //	t - left thumb		|
            //	s - right thumb		|
            */

            int color = (int)FPS_STATUS_LED_COLOR.FPS_SLC_OFF;
            int index = 0;
            int middle = 0;
            int ring = 0;
            int little = 0;
            string wsqIndexFileName = String.Empty;
            string wsqMiddleFileName = String.Empty;
            string wsqRingFileName = String.Empty;
            string wsqLittleFileName = String.Empty;

            _fps.SetStatusLed(0xff, color); // off
            color = (int)FPS_STATUS_LED_COLOR.FPS_SLC_GREEN;

            int fingerMask = 0x00;
            switch (handAndFingerMask & 0xff000000)
            {
                case 0x10000000:    //0x10333300    left hand
                case 0x20000000:    //0x20333300    right hand
                    fingerMask |= (handAndFingerMask & 0x00300000) != 0 ? 0x08 : 0x00;
                    fingerMask |= (handAndFingerMask & 0x00030000) != 0 ? 0x04 : 0x00;
                    fingerMask |= (handAndFingerMask & 0x00003000) != 0 ? 0x02 : 0x00;
                    fingerMask |= (handAndFingerMask & 0x00000300) != 0 ? 0x01 : 0x00;
                    break;
                case 0x30000000:    //0x20000033    thumbs
                    fingerMask |= (handAndFingerMask & 0x00000030) != 0 ? 0x04 : 0x00;
                    fingerMask |= (handAndFingerMask & 0x00000003) != 0 ? 0x02 : 0x00;
                    break;
            }

            int lampMask = fingerMask;
            switch (handAndFingerMask & 0xff000000)
            {
                case 0x10000000:    //0x10333300  left hand
                    index = (int)FPS_POSITION.FPS_POS_LEFT_INDEX;
                    middle = (int)FPS_POSITION.FPS_POS_LEFT_MIDDLE;
                    ring = (int)FPS_POSITION.FPS_POS_LEFT_RING;
                    little = (int)FPS_POSITION.FPS_POS_LEFT_LITTLE;
                    wsqIndexFileName = "lindex.wsq";
                    wsqMiddleFileName = "lmiddle.wsq";
                    wsqRingFileName = "lring.wsq";
                    wsqLittleFileName = "llittle.wsq";
                    lampMask = 0x80;
                    lampMask |= (fingerMask & 0x00000001) != 0 ? 0x08 : 0x00;
                    lampMask |= (fingerMask & 0x00000002) != 0 ? 0x04 : 0x00;
                    lampMask |= (fingerMask & 0x00000004) != 0 ? 0x02 : 0x00;
                    lampMask |= (fingerMask & 0x00000008) != 0 ? 0x01 : 0x00;
                    break;
                case 0x20000000:    //0x20333300
                    index = (int)FPS_POSITION.FPS_POS_RIGHT_INDEX;
                    middle = (int)FPS_POSITION.FPS_POS_RIGHT_MIDDLE;
                    ring = (int)FPS_POSITION.FPS_POS_RIGHT_RING;
                    little = (int)FPS_POSITION.FPS_POS_RIGHT_LITTLE;
                    wsqIndexFileName = "rindex.wsq";
                    wsqMiddleFileName = "rmiddle.wsq";
                    wsqRingFileName = "rring.wsq";
                    wsqLittleFileName = "rlittle.wsq";
                    lampMask |= 0x40;
                    break;
                case 0x30000000:    //0x30000033
                    middle = (int)FPS_POSITION.FPS_POS_LEFT_THUMB;
                    ring = (int)FPS_POSITION.FPS_POS_RIGHT_THUMB;
                    wsqMiddleFileName = "lthumb.wsq";
                    wsqRingFileName = "rthumb.wsq";
                    lampMask |= 0x20;
                    break;
            }

            /* Turning the display leds depending on the mask */
            _fps.SetStatusLed(lampMask, color);

            //reqid = _fps.CaptureStart(100, 100, (int)FPS_IMPRESSION_TYPE.FPS_SCAN_LIVE, 0x10333300);
            reqid = _fps.CaptureStart(3000, 7000, (int)FPS_IMPRESSION_TYPE.FPS_SCAN_LIVE, handAndFingerMask);

            for (stat = 0; stat < 100; )
            {
                /* Test if better images are captured or capture has accomplished */
                stat = _fps.CaptureStatus(reqid);

                _helper.Wait(100);
            }

            /* Closing the capture sequence */
            _fps.CaptureWait(reqid);

            color = (int)FPS_STATUS_LED_COLOR.FPS_SLC_OFF;
            _fps.SetStatusLed(0xff, color); // off

            /* Save individual finger images */
            gxImage img;
            gxVariant var = null;
            int mask = 0x10;

            _arrayOfBMP = new ArrayList();
            _arrayOfWSQ = new ArrayList();

            for (int i = 0; i < 4; i++)
            {
                mask >>= 1;
                bool valid = true;
                switch (fingerMask & mask)
                {
                    case 0x08:
                        try
                        {
                            var = _fps.GetImage((int)FPS_IMPRESSION_TYPE.FPS_SCAN_LIVE, index, (int)FPS_IMAGE_TYPE.FPS_IT_FINGER);
                            if (saveFingerAsFile)
                                _fps.SaveImage(0, index, (int)FPS_IMAGE_TYPE.FPS_IT_FINGER, wsqIndexFileName, (int)GX_IMGFILEFORMATS.GX_WSQ);
                        }
                        catch
                        {
                            valid = false;
                            if (saveFingerAsFile)
                                File.Delete(wsqIndexFileName);
                        }
                        break;
                    case 0x04:
                        try
                        {
                            var = _fps.GetImage((int)FPS_IMPRESSION_TYPE.FPS_SCAN_LIVE, middle, (int)FPS_IMAGE_TYPE.FPS_IT_FINGER);
                            if (saveFingerAsFile)
                                _fps.SaveImage(0, middle, (int)FPS_IMAGE_TYPE.FPS_IT_FINGER, wsqMiddleFileName, (int)GX_IMGFILEFORMATS.GX_WSQ);
                        }
                        catch
                        {
                            valid = false;
                            if (saveFingerAsFile)
                                File.Delete(wsqMiddleFileName);
                        }
                        break;
                    case 0x02:
                        try
                        {
                            var = _fps.GetImage((int)FPS_IMPRESSION_TYPE.FPS_SCAN_LIVE, ring, (int)FPS_IMAGE_TYPE.FPS_IT_FINGER);
                            if (saveFingerAsFile)
                                _fps.SaveImage(0, ring, (int)FPS_IMAGE_TYPE.FPS_IT_FINGER, wsqRingFileName, (int)GX_IMGFILEFORMATS.GX_WSQ);
                        }
                        catch
                        {
                            valid = false;
                            if (saveFingerAsFile)
                                File.Delete(wsqRingFileName);
                        }
                        break;
                    case 0x01:
                        try
                        {
                            var = _fps.GetImage((int)FPS_IMPRESSION_TYPE.FPS_SCAN_LIVE, little, (int)FPS_IMAGE_TYPE.FPS_IT_FINGER);
                            if (saveFingerAsFile)
                                _fps.SaveImage(0, little, (int)FPS_IMAGE_TYPE.FPS_IT_FINGER, wsqLittleFileName, (int)GX_IMGFILEFORMATS.GX_WSQ);
                        }
                        catch
                        {
                            valid = false;
                            if (saveFingerAsFile)
                                File.Delete(wsqLittleFileName);
                        }
                        break;
                    default:
                        _arrayOfBMP.Add(new Byte[] { new Byte() });
                        _arrayOfWSQ.Add(new WsqImage());
        //                        _arrayOfWSQ.Add(new Byte[] { new Byte() });
                        continue;
                }

                if (valid)
                {
                    img = new gxImage();
                    gxVariant vtest = new gxVariant();
                    img.FromVariant(var);

                    WsqImage im = new WsqImage();
                    im.Content = img.SaveToMem((int)GX_IMGFILEFORMATS.GX_WSQ);
                    //im.Content = img.SaveToMem((int)GX_IMGFILEFORMATS.GX_BMP);
                    im.XRes = img.xres() / (10000 / 254);
                    im.YRes = img.yres() / (10000 / 254);
                    im.XSize = img.xsize();
                    im.YSize = img.ysize();
                    im.PixelFormat = img.format();
                    _arrayOfWSQ.Add(im);

                    _arrayOfBMP.Add(img.SaveToMem((int)GX_IMGFILEFORMATS.GX_BMP));
                    //_arrayOfWSQ.Add(img.SaveToMem((int)GX_IMGFILEFORMATS.GX_WSQ));
                    img.Dispose();
                }
                else
                {
                    //list.Add(new Byte[] { new Byte() });
                    _arrayOfBMP.Add(null);
                    _arrayOfWSQ.Add(null);
                }

                if (var != null)
                    var.Dispose();
            }
        }
        catch (gxException e)
        {
            return _helper.GetErrorMessage(e, out _errorMessage);
        }
        catch (Exception e)
        {
            _errorMessage = e.Message + " --- fpsGetFingersImages()";
            return 1305;
        }

        return 0;
    }
        /// <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 #14
0
        public string scanner_piece()
        {
            prDoc doc;

            try
            {
                //if (!pr.IsCalibrated((int)PR_WINDOW_ID.PR_OW_DEFAULT))
                //    pr.Calibrate((int)PR_WINDOW_ID.PR_OW_DEFAULT);

                pr.Capture();

                /*if (pr.TestDocument((int)PR_WINDOW_ID.PR_OW_DEFAULT) == (int)PR_TESTDOC.PR_TD_IN)
                 * {
                 *  MessageBox.Show("OK");
                 *  pr.Capture();
                 * }
                 * else
                 * {
                 *  MessageBox.Show("PAS OK");
                 *  pr.CloseDevice();
                 *  pr.Close();
                 *  return "";
                 * }*/
            }
            catch (Exception ex)
            {
                MessageBox.Show("Impossible de se connecter au scanner de pièces d'identité");
                Program.LogFich.Error("[ScannerPiece] Impossible de se connecter au scanner de pièces d'identité");
                Program.LogFich.Error(ex.ToString());

                //pr.CloseDevice();
                //pr.Close();
                return("");
            }

            try
            {
                if (File.Exists(Environment.ExpandEnvironmentVariables("%TEMP%\\") + "recto.jpeg"))
                {
                    File.Delete(Environment.ExpandEnvironmentVariables("%TEMP%\\") + "recto.jpeg");
                }

                doc = pr.Recognize(0);

                pr.SaveImage(0, (int)PR_LIGHT.PR_LIGHT_WHITE, (int)PR_IMAGE_TYPE.PR_IT_DOCUMENT, Environment.ExpandEnvironmentVariables("%TEMP%\\") + "recto.jpeg", (int)GX_IMGFILEFORMATS.GX_JPEG);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erreur : " + ex.ToString());
                Program.LogFich.Error("[ScannerPiece] Erreur : " + ex.ToString());
                //pr.CloseDevice();
                //pr.Close();
                return("");
            }

            try
            {
                //pr.SelfTest((int)PR_SELFTEST_ELEMENTS.PRV_ST_LIGHT_SWITCH);


                gxImage img = doc.FieldImage((int)PR_DOCFIELD.PR_DF_VIZ_FACE);
                if (img != null)
                {
                    if (File.Exists(Environment.ExpandEnvironmentVariables("%TEMP%\\") + "PhotoIdentite.jpeg"))
                    {
                        File.Delete(Environment.ExpandEnvironmentVariables("%TEMP%\\") + "PhotoIdentite.jpeg");
                    }
                    img.Save(Environment.ExpandEnvironmentVariables("%TEMP%\\") + "PhotoIdentite.jpeg", (int)GX_IMGFILEFORMATS.GX_JPEG);
                    img.Dispose();
                }

                MRZ = doc.Field((int)PR_DOCFIELD.PR_DF_MRZ1) + doc.Field((int)PR_DOCFIELD.PR_DF_MRZ2) + doc.Field((int)PR_DOCFIELD.PR_DF_MRZ3);
                if (MRZ.Equals(""))
                {
                    Program.LogFich.Info("[ScannerPiece] pas de piste MRZ sur le recto");
                }

                /*if (MessageBox.Show("Pour Scanner le verso, tournez la pièce et cliquer sur Oui.", "Scan Verso", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                 * {
                 *  pr.CloseDevice();
                 *  //pr.Close();
                 *  scan_verso();
                 * }*/


                if (this.MRZ.Equals("") && visiteurID.Equals(""))
                {
                    MessageBox.Show("Le Document n'a pas de piste MRZ");
                    Program.LogFich.Info("[ScannerPiece] Le Document n'a pas de piste MRZ");
                }

                return(MRZ);
            }
            catch (Exception ex)
            {
                Program.LogFich.Error("[ScannerPiece] n'a pas pu lire le recto du document : " + ex.ToString());
                return("");
            }
            finally
            {
                if (pr != null)
                {
                    pr.ResetDocument();
                    //pr.CloseDevice();
                    //pr.Close();
                    //pr.Dispose();
                }
            }
        }
Beispiel #15
0
    public int fpsGetFingersImages(int handAndFingerMask, bool saveFingerAsFile)
    {
        try
        {
            if (_arrayOfBMP != null)
            {
                _arrayOfBMP.Clear(); _arrayOfBMP = null;
            }
            if (_arrayOfWSQ != null)
            {
                _arrayOfWSQ.Clear(); _arrayOfWSQ = null;
            }

            /* Search Finger */
            int reqid, stat;

            /* Clears internal stored finger buffers */
            _fps.ResetFingerList();


            /* Starts an asynchronous capture process
             * // params: time in usec, quality in per-thousand, mode of live scan, fingerlist
             * //
             * // The finger list has the format 0hhh 0000 iiii mmmm rrrr llll tttt ssss
             * //	h - scan object: 001 left hand, 010 right hand, 011 same fingers of both hands
             * //	i - index finger	|
             * //	m - middle finger	|
             * //	r - ring finger		|--> value of FPS_PRESENCE   FPS_AVAILABLE = 3
             * //	l - little finger	|
             * //	t - left thumb		|
             * //	s - right thumb		|
             */

            int    color             = (int)FPS_STATUS_LED_COLOR.FPS_SLC_OFF;
            int    index             = 0;
            int    middle            = 0;
            int    ring              = 0;
            int    little            = 0;
            string wsqIndexFileName  = String.Empty;
            string wsqMiddleFileName = String.Empty;
            string wsqRingFileName   = String.Empty;
            string wsqLittleFileName = String.Empty;

            _fps.SetStatusLed(0xff, color); // off
            color = (int)FPS_STATUS_LED_COLOR.FPS_SLC_GREEN;

            int fingerMask = 0x00;
            switch (handAndFingerMask & 0xff000000)
            {
            case 0x10000000:        //0x10333300    left hand
            case 0x20000000:        //0x20333300    right hand
                fingerMask |= (handAndFingerMask & 0x00300000) != 0 ? 0x08 : 0x00;
                fingerMask |= (handAndFingerMask & 0x00030000) != 0 ? 0x04 : 0x00;
                fingerMask |= (handAndFingerMask & 0x00003000) != 0 ? 0x02 : 0x00;
                fingerMask |= (handAndFingerMask & 0x00000300) != 0 ? 0x01 : 0x00;
                break;

            case 0x30000000:        //0x20000033    thumbs
                fingerMask |= (handAndFingerMask & 0x00000030) != 0 ? 0x04 : 0x00;
                fingerMask |= (handAndFingerMask & 0x00000003) != 0 ? 0x02 : 0x00;
                break;
            }

            int lampMask = fingerMask;
            switch (handAndFingerMask & 0xff000000)
            {
            case 0x10000000:        //0x10333300  left hand
                index             = (int)FPS_POSITION.FPS_POS_LEFT_INDEX;
                middle            = (int)FPS_POSITION.FPS_POS_LEFT_MIDDLE;
                ring              = (int)FPS_POSITION.FPS_POS_LEFT_RING;
                little            = (int)FPS_POSITION.FPS_POS_LEFT_LITTLE;
                wsqIndexFileName  = "lindex.wsq";
                wsqMiddleFileName = "lmiddle.wsq";
                wsqRingFileName   = "lring.wsq";
                wsqLittleFileName = "llittle.wsq";
                lampMask          = 0x80;
                lampMask         |= (fingerMask & 0x00000001) != 0 ? 0x08 : 0x00;
                lampMask         |= (fingerMask & 0x00000002) != 0 ? 0x04 : 0x00;
                lampMask         |= (fingerMask & 0x00000004) != 0 ? 0x02 : 0x00;
                lampMask         |= (fingerMask & 0x00000008) != 0 ? 0x01 : 0x00;
                break;

            case 0x20000000:        //0x20333300
                index             = (int)FPS_POSITION.FPS_POS_RIGHT_INDEX;
                middle            = (int)FPS_POSITION.FPS_POS_RIGHT_MIDDLE;
                ring              = (int)FPS_POSITION.FPS_POS_RIGHT_RING;
                little            = (int)FPS_POSITION.FPS_POS_RIGHT_LITTLE;
                wsqIndexFileName  = "rindex.wsq";
                wsqMiddleFileName = "rmiddle.wsq";
                wsqRingFileName   = "rring.wsq";
                wsqLittleFileName = "rlittle.wsq";
                lampMask         |= 0x40;
                break;

            case 0x30000000:        //0x30000033
                middle            = (int)FPS_POSITION.FPS_POS_LEFT_THUMB;
                ring              = (int)FPS_POSITION.FPS_POS_RIGHT_THUMB;
                wsqMiddleFileName = "lthumb.wsq";
                wsqRingFileName   = "rthumb.wsq";
                lampMask         |= 0x20;
                break;
            }

            /* Turning the display leds depending on the mask */
            _fps.SetStatusLed(lampMask, color);

            //reqid = _fps.CaptureStart(100, 100, (int)FPS_IMPRESSION_TYPE.FPS_SCAN_LIVE, 0x10333300);
            reqid = _fps.CaptureStart(3000, 7000, (int)FPS_IMPRESSION_TYPE.FPS_SCAN_LIVE, handAndFingerMask);

            for (stat = 0; stat < 100;)
            {
                /* Test if better images are captured or capture has accomplished */
                stat = _fps.CaptureStatus(reqid);

                _helper.Wait(100);
            }

            /* Closing the capture sequence */
            _fps.CaptureWait(reqid);

            color = (int)FPS_STATUS_LED_COLOR.FPS_SLC_OFF;
            _fps.SetStatusLed(0xff, color); // off

            /* Save individual finger images */
            gxImage   img;
            gxVariant var  = null;
            int       mask = 0x10;

            _arrayOfBMP = new ArrayList();
            _arrayOfWSQ = new ArrayList();

            for (int i = 0; i < 4; i++)
            {
                mask >>= 1;
                bool valid = true;
                switch (fingerMask & mask)
                {
                case 0x08:
                    try
                    {
                        var = _fps.GetImage((int)FPS_IMPRESSION_TYPE.FPS_SCAN_LIVE, index, (int)FPS_IMAGE_TYPE.FPS_IT_FINGER);
                        if (saveFingerAsFile)
                        {
                            _fps.SaveImage(0, index, (int)FPS_IMAGE_TYPE.FPS_IT_FINGER, wsqIndexFileName, (int)GX_IMGFILEFORMATS.GX_WSQ);
                        }
                    }
                    catch
                    {
                        valid = false;
                        if (saveFingerAsFile)
                        {
                            File.Delete(wsqIndexFileName);
                        }
                    }
                    break;

                case 0x04:
                    try
                    {
                        var = _fps.GetImage((int)FPS_IMPRESSION_TYPE.FPS_SCAN_LIVE, middle, (int)FPS_IMAGE_TYPE.FPS_IT_FINGER);
                        if (saveFingerAsFile)
                        {
                            _fps.SaveImage(0, middle, (int)FPS_IMAGE_TYPE.FPS_IT_FINGER, wsqMiddleFileName, (int)GX_IMGFILEFORMATS.GX_WSQ);
                        }
                    }
                    catch
                    {
                        valid = false;
                        if (saveFingerAsFile)
                        {
                            File.Delete(wsqMiddleFileName);
                        }
                    }
                    break;

                case 0x02:
                    try
                    {
                        var = _fps.GetImage((int)FPS_IMPRESSION_TYPE.FPS_SCAN_LIVE, ring, (int)FPS_IMAGE_TYPE.FPS_IT_FINGER);
                        if (saveFingerAsFile)
                        {
                            _fps.SaveImage(0, ring, (int)FPS_IMAGE_TYPE.FPS_IT_FINGER, wsqRingFileName, (int)GX_IMGFILEFORMATS.GX_WSQ);
                        }
                    }
                    catch
                    {
                        valid = false;
                        if (saveFingerAsFile)
                        {
                            File.Delete(wsqRingFileName);
                        }
                    }
                    break;

                case 0x01:
                    try
                    {
                        var = _fps.GetImage((int)FPS_IMPRESSION_TYPE.FPS_SCAN_LIVE, little, (int)FPS_IMAGE_TYPE.FPS_IT_FINGER);
                        if (saveFingerAsFile)
                        {
                            _fps.SaveImage(0, little, (int)FPS_IMAGE_TYPE.FPS_IT_FINGER, wsqLittleFileName, (int)GX_IMGFILEFORMATS.GX_WSQ);
                        }
                    }
                    catch
                    {
                        valid = false;
                        if (saveFingerAsFile)
                        {
                            File.Delete(wsqLittleFileName);
                        }
                    }
                    break;

                default:
                    _arrayOfBMP.Add(new Byte[] { new Byte() });
                    _arrayOfWSQ.Add(new WsqImage());
//                        _arrayOfWSQ.Add(new Byte[] { new Byte() });
                    continue;
                }

                if (valid)
                {
                    img = new gxImage();
                    gxVariant vtest = new gxVariant();
                    img.FromVariant(var);

                    WsqImage im = new WsqImage();
                    im.Content = img.SaveToMem((int)GX_IMGFILEFORMATS.GX_WSQ);
                    //im.Content = img.SaveToMem((int)GX_IMGFILEFORMATS.GX_BMP);
                    im.XRes        = img.xres() / (10000 / 254);
                    im.YRes        = img.yres() / (10000 / 254);
                    im.XSize       = img.xsize();
                    im.YSize       = img.ysize();
                    im.PixelFormat = img.format();
                    _arrayOfWSQ.Add(im);

                    _arrayOfBMP.Add(img.SaveToMem((int)GX_IMGFILEFORMATS.GX_BMP));
                    //_arrayOfWSQ.Add(img.SaveToMem((int)GX_IMGFILEFORMATS.GX_WSQ));
                    img.Dispose();
                }
                else
                {
                    //list.Add(new Byte[] { new Byte() });
                    _arrayOfBMP.Add(null);
                    _arrayOfWSQ.Add(null);
                }

                if (var != null)
                {
                    var.Dispose();
                }
            }
        }
        catch (gxException e)
        {
            return(_helper.GetErrorMessage(e, out _errorMessage));
        }
        catch (Exception e)
        {
            _errorMessage = e.Message + " --- fpsGetFingersImages()";
            return(1305);
        }

        return(0);
    }
Beispiel #16
0
        private void ANPRThreadFunction()
        {
            List <PLATE_CANDIDATE> plate_candidates = new List <PLATE_CANDIDATE>();

            while (_isANPRThreadRunning)
            {
                byte[] imageData  = GetImage(); // dequeue image
                int    foundcount = 0;

                if (imageData != null)
                {
                    try
                    {
                        gxImage gximage = new gxImage("default");
                        gximage.LoadFromMem(imageData, (int)GX_PIXELFORMATS.GX_FORMAT_FIRST);

                        // Finds the first plate and displays it
                        bool isFound = anpr.FindFirst(gximage);
                        while (isFound)
                        {
                            foundcount++;
                            // plate found
                            DateTime datetime = DateTime.Now;
                            string   plateStr = anpr.GetText();

                            if (isValidPlateString(plateStr))
                            {
                                // Remove old results
                                int currentTime = Environment.TickCount;
                                for (int i = plate_candidates.Count - 1; i >= 0; i--)
                                {
                                    if (currentTime - plate_candidates[i].firstfoundTime > Constants.CANDIDATE_REMOVE_TIME)
                                    {
                                        plate_candidates.RemoveAt(i);
                                    }
                                }

                                // Check duplicate
                                bool isNew = true;

                                for (int i = 0; i < plate_candidates.Count; i++)
                                {
                                    if (plateStr.Equals(plate_candidates[i].plate_string) ||
                                        (plateStr.Substring(plateStr.Length - 4, 4).Equals(plate_candidates[i].plate_string.Substring(plate_candidates[i].plate_string.Length - 4, 4))))
                                    {
                                        isNew = false;

                                        PLATE_CANDIDATE modified;
                                        modified.firstfoundTime = plate_candidates[i].firstfoundTime;
                                        modified.foundCount     = plate_candidates[i].foundCount + 1;
                                        modified.id             = plate_candidates[i].id;
                                        modified.plate_string   = plate_candidates[i].plate_string;
                                        plate_candidates.RemoveAt(i);
                                        plate_candidates.Add(modified);

                                        if (modified.foundCount == Constants.CANDIDATE_COUNT_FOR_PASS)
                                        {
                                            string plateImageFilepath = _savepath + "\\ch" + cameraID;
                                            string dtStr = String.Format("{0:yyyyMMdd_HHmmss}", datetime);
                                            string plateImageFilename = plateImageFilepath + "\\CAM-" + cameraID + "_" + dtStr + "_" + plateStr + ".jpg";
                                            Console.WriteLine("Result: '{0}', ch {1}", plateStr, cameraID);

                                            // write anpr snapshot
                                            if (!Directory.Exists(plateImageFilepath))
                                            {
                                                Directory.CreateDirectory(plateImageFilepath);
                                            }
                                            File.WriteAllBytes(plateImageFilename, imageData);
                                            // write db
                                            db.InsertPlate(cameraID, datetime, plateStr, plateImageFilename); // db write
                                            //db.InsertPlateText(camera.camID, DateTime.Now, plateStr, returnImage); // file write test

                                            // invoke anpr event to mainform
                                            if (ANPRDetected != null)
                                            {
                                                ANPRDetected(cameraID, datetime, plateStr, plateImageFilename);
                                            }
                                        }
                                    }
                                }

                                if (isNew)
                                {
                                    currentTime = Environment.TickCount;
                                    PLATE_CANDIDATE newItem;
                                    newItem.firstfoundTime = currentTime;
                                    newItem.foundCount     = 1;
                                    newItem.plate_string   = plateStr;
                                    newItem.id             = 0;

                                    plate_candidates.Add(newItem);
                                }
                            }
                            else
                            {
                                // wrong plate
                                Console.WriteLine("Wrong plate found ch " + cameraID);
                            }

                            isFound = anpr.FindNext();
                        }

                        /*else
                         * {
                         *  // no plate
                         *  Console.WriteLine("No plate found ch " + cameraID);
                         * }*/
                        if (foundcount == 0)
                        {
                            // no plate
                            Console.WriteLine("No plate found ch " + cameraID);
                        }
                    }
                    catch (gxException e)
                    {
                        Console.WriteLine("Exception occurred: {0}", e.Message);
                    }
                }

                // end of thread cycle
                Thread.Sleep(1);
            }
        }