示例#1
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);
 }
示例#2
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);
            }
        }
示例#3
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);
            }
        }
示例#4
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);
            }
        }