Example #1
0
        public bool popMedia(ref GBUVideoFrame frame)
        {
            //Console.WriteLine("ImageBuffer" + _imageBufferCount);
            if (_imageBufferCount > 0)
            {
                int frontindex = _imageBufferEmptyIndex - _imageBufferCount;
                if (frontindex < 0)
                {
                    frontindex += Constants.MAX_IMAGE_BUFFER;
                }
                frame.frame    = _imageBuffer[frontindex].frame;
                frame.camindex = _imageBuffer[frontindex].camindex;

                _imageBufferCount--;

                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #2
0
        public bool popMedia(ref GBUVideoFrame frame)
        {
            //Console.WriteLine("ImageBuffer" + _imageBufferCount);
            if (_imageBufferCount > 0)
            {
                int frontindex = _imageBufferEmptyIndex - _imageBufferCount;
                if (frontindex < 0)
                {
                    frontindex += Constants.MAX_IMAGE_BUFFER;
                }
                frame.frame = _imageBuffer[frontindex].frame;
                frame.camindex = _imageBuffer[frontindex].camindex;

                _imageBufferCount--;

                return true;
            }
            else
            {
                return false;
            }
        }
Example #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);
            }
        }
Example #4
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);
            }
        }