Ejemplo n.º 1
0
 public vector_Blob(vector_Blob other) : this(VisionLabPINVOKE.new_vector_Blob__SWIG_1(vector_Blob.getCPtr(other)), true)
 {
     if (VisionLabPINVOKE.SWIGPendingException.Pending)
     {
         throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 2
0
 public vector_BlobEnumerator(vector_Blob collection)
 {
     collectionRef = collection;
     currentIndex  = -1;
     currentObject = null;
     currentSize   = collectionRef.Count;
 }
Ejemplo n.º 3
0
 public void SetRange(int index, vector_Blob values)
 {
     VisionLabPINVOKE.vector_Blob_SetRange(swigCPtr, index, vector_Blob.getCPtr(values));
     if (VisionLabPINVOKE.SWIGPendingException.Pending)
     {
         throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 4
0
    public vector_Blob GetRange(int index, int count)
    {
        IntPtr      cPtr = VisionLabPINVOKE.vector_Blob_GetRange(swigCPtr, index, count);
        vector_Blob ret  = (cPtr == IntPtr.Zero) ? null : new vector_Blob(cPtr, true);

        if (VisionLabPINVOKE.SWIGPendingException.Pending)
        {
            throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
Ejemplo n.º 5
0
    public static vector_Blob Repeat(Blob value, int count)
    {
        IntPtr      cPtr = VisionLabPINVOKE.vector_Blob_Repeat(Blob.getCPtr(value), count);
        vector_Blob ret  = (cPtr == IntPtr.Zero) ? null : new vector_Blob(cPtr, true);

        if (VisionLabPINVOKE.SWIGPendingException.Pending)
        {
            throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
Ejemplo n.º 6
0
        public void DisplayBlobs(Image binaryImage)
        {
            vector_BlobAnalyse ba    = new vector_BlobAnalyse();
            vector_Blob        blobs = new vector_Blob();

            ba.Add(BlobAnalyse.BA_Area);
            ba.Add(BlobAnalyse.BA_Eccentricity);
            ba.Add(BlobAnalyse.BA_LengthBreadthRatio);
            VisionLabEx.GetBlobsInfo(binaryImage, ba, ref blobs);
            System.Diagnostics.Debug.WriteLine("Blob Info: ");
            foreach (Blob b in blobs)
            {
                System.Diagnostics.Debug.WriteLine("   Area: " + b.Area().ToString() +
                                                   " Eccentricity: " + b.Eccentricity().ToString() +
                                                   " LengthBreadthRatio: " + b.LengthBreadthRatio().ToString());
            }
            ba.Dispose();
            blobs.Dispose();
        }
Ejemplo n.º 7
0
 public static void GrayScaleBlobAnalysis(Int32Image labelledImage, Int32Image grayImage, SWIGTYPE_p_std__setT_JL_VisionLib_V3__BlobAnalyse_t s, int maxLabelNr, vector_Blob blobs) {
   VisionLabPINVOKE.GrayScaleBlobAnalysis__SWIG_24(Int32Image.getCPtr(labelledImage), Int32Image.getCPtr(grayImage), SWIGTYPE_p_std__setT_JL_VisionLib_V3__BlobAnalyse_t.getCPtr(s), maxLabelNr, vector_Blob.getCPtr(blobs));
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
 }
        /*
         *  Description:
         *      Read the license plate
         *  Input:
         *          //Rectified license plate image containing six characters
         *          Int16Image labeledRectifiedPlateImage
         *          BlobMatcher_Int16 matcher	//initialized blobmatcher
         *          ClassLexicon lexicon		//initialized lexicon
         *  Output:
         *          //Result by the blob matcher
         *          ref LicensePlate result
         *          //Result by the lexicon
         *          ref LicensePlate lexiconResult
         *  Return:
         *          //six characters found
         *      bool
         */
        public static bool MatchPlate(Int16Image binaryCharacterImage, BlobMatcher_Int16 matcher,
                                      ClassLexicon lexicon, ref LicensePlate result, ref LicensePlate lexiconResult, bool dilate)
        {
            // NIEUW
            // 2de optie voor aanroep als eerste low confidence levert
            if (dilate)
            {
                Int16Image temp = new Int16Image();
                VisionLab.Dilation(binaryCharacterImage, temp, new Mask_Int32(3, 3, 1));
                binaryCharacterImage = new Int16Image(temp);
                temp.Dispose();
            }
            if (VisionLab.LabelBlobs(binaryCharacterImage, Connected.EightConnected) != 6)
            {
                return(false);
            }

            //Calculate dimensions and locations of all characters/blobs.
            vector_BlobAnalyse ba_vec = new vector_BlobAnalyse();

            ba_vec.Add(BlobAnalyse.BA_TopLeft);
            ba_vec.Add(BlobAnalyse.BA_Height);
            ba_vec.Add(BlobAnalyse.BA_Width);
            vector_Blob returnBlobs = new vector_Blob();

            VisionLab.BlobAnalysis(binaryCharacterImage, VisionLab.VectorToSet_BlobAnalyse(ba_vec), VisionLab.MaxPixel(binaryCharacterImage), returnBlobs, SortOrder.SortDown, BlobAnalyse.BA_TopLeft, UseXOrY.UseX);
            ba_vec.Dispose();
            Int16Image binaryCharacter = new Int16Image();

            //Create data structure for lexicon.
            vector_vector_LetterMatch match = new vector_vector_LetterMatch();

            // NIEUW
            // Change the matcher params
            matcher.ChangeParams(60, 10, 64, 0);
            //Process each character/blob.
            foreach (Blob b in returnBlobs)
            {
                //Cut out character
                VisionLab.ROI(binaryCharacterImage, binaryCharacter, b.TopLeft(), new HeightWidth(b.Height(), b.Width()));
                //Convert ROI result to binary
                VisionLab.ClipPixelValue(binaryCharacter, 0, 1);
                //Calculate character's classification for all classes.
                vector_PatternMatchResult returnMatches = new vector_PatternMatchResult();
                float  conf = matcher.AllMatches(binaryCharacter, (float)-0.5, (float)0.5, returnMatches);
                float  err  = returnMatches[0].error;
                int    id   = returnMatches[0].id;
                string chr  = matcher.PatternName(id);
                // NIEUW
                // If error to big decrease the confidence
                if (err > 0.20f)
                {
                    conf -= 0.2f;
                }
                //Fill datastructure for lexicon.
                match.Add(VisionLabEx.PatternMatchResultToLetterMatch(returnMatches));

                //Store best match in result
                result.characters.Add(
                    new LicenseCharacter(
                        chr,
                        err,
                        conf,

                        // NIEUW
                        // Extra param: The middle of a character
                        // (used for matching patterns)
                        b.TopLeft().x + ((b.TopRight().x - b.TopLeft().x) / 2),

                        // NIEUW
                        // All other results that we're found
                        // So we can switch between em
                        returnMatches
                        ));
            }

            //Validate match with lexicon.
            vector_int bestWord = new vector_int();

            lexiconResult.confidence = lexicon.FindBestWord(match, bestWord, Optimize.OptimizeForMinimum);
            for (int i = 0; i < bestWord.Count; i++)
            {
                string character = matcher.PatternName(bestWord[i]);
                //Store lexicon result
                lexiconResult.characters.Add(new LicenseCharacter(character));
            }

            // NIEUW
            // Create the best match with the aid of the pattern matcher
            result.CalculateBestMatch(matcher);

            binaryCharacter.Dispose();
            returnBlobs.Dispose();
            match.Dispose();
            bestWord.Dispose();
            GC.Collect();
            return(true);
        }
Ejemplo n.º 9
0
 public static void GrayScaleBlobAnalysis(ByteImage labelledImage, ByteImage grayImage, SWIGTYPE_p_std__setT_JL_VisionLib_V3__BlobAnalyse_t s, int maxLabelNr, vector_Blob blobs, SortOrder so, BlobAnalyse sortBA) {
   VisionLabPINVOKE.GrayScaleBlobAnalysis__SWIG_7(ByteImage.getCPtr(labelledImage), ByteImage.getCPtr(grayImage), SWIGTYPE_p_std__setT_JL_VisionLib_V3__BlobAnalyse_t.getCPtr(s), maxLabelNr, vector_Blob.getCPtr(blobs), (int)so, (int)sortBA);
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
 }
Ejemplo n.º 10
0
 public static void GrayScaleBlobAnalysis(Int32Image labelledImage, Int32Image grayImage, SWIGTYPE_p_std__setT_JL_VisionLib_V3__BlobAnalyse_t s, int maxLabelNr, vector_Blob blobs, SortOrder so, BlobAnalyse sortBA, UseXOrY xy, BlobAnalyseModifier baMod) {
   VisionLabPINVOKE.GrayScaleBlobAnalysis__SWIG_20(Int32Image.getCPtr(labelledImage), Int32Image.getCPtr(grayImage), SWIGTYPE_p_std__setT_JL_VisionLib_V3__BlobAnalyse_t.getCPtr(s), maxLabelNr, vector_Blob.getCPtr(blobs), (int)so, (int)sortBA, (int)xy, BlobAnalyseModifier.getCPtr(baMod));
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
 }
Ejemplo n.º 11
0
 public static void BlobAnalyseTabToVectorStr(vector_string vs, SWIGTYPE_p_std__setT_JL_VisionLib_V3__BlobAnalyse_t s, vector_Blob blobs) {
   VisionLabPINVOKE.BlobAnalyseTabToVectorStr__SWIG_1(vector_string.getCPtr(vs), SWIGTYPE_p_std__setT_JL_VisionLib_V3__BlobAnalyse_t.getCPtr(s), vector_Blob.getCPtr(blobs));
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
 }
Ejemplo n.º 12
0
 public static void BlobAnalysis(Int32Image labelledImage, SWIGTYPE_p_std__setT_JL_VisionLib_V3__BlobAnalyse_t s, int maxLabelNr, vector_Blob blobs, SortOrder so) {
   VisionLabPINVOKE.BlobAnalysis__SWIG_23(Int32Image.getCPtr(labelledImage), SWIGTYPE_p_std__setT_JL_VisionLib_V3__BlobAnalyse_t.getCPtr(s), maxLabelNr, vector_Blob.getCPtr(blobs), (int)so);
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
 }
Ejemplo n.º 13
0
 public static bool IsTheSame(vector_Blob b1, vector_Blob b2, double dev) {
   bool ret = VisionLabPINVOKE.IsTheSame__SWIG_1(vector_Blob.getCPtr(b1), vector_Blob.getCPtr(b2), dev);
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
Ejemplo n.º 14
0
 public static string BlobAnalyseTabToStr(SWIGTYPE_p_std__setT_JL_VisionLib_V3__BlobAnalyse_t s, vector_Blob blobs) {
   string ret = VisionLabPINVOKE.BlobAnalyseTabToStr__SWIG_1(SWIGTYPE_p_std__setT_JL_VisionLib_V3__BlobAnalyse_t.getCPtr(s), vector_Blob.getCPtr(blobs));
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
Ejemplo n.º 15
0
        private void MatchImage(String Filename, bool add)
        {
            ErrorTB.Text     = "";
            lblExpected.Text = Filename.Substring(0, 6);

            //*************************************//
            //** load and display original image **//
            //*************************************//
            Bitmap bm;

            bm = new Bitmap(Filename);
            RGB888Image plateImage = VisionLabEx.BitmapToJL(bm);

            DisplayImage(plateImage, imgOrig);

            //****************//
            //** Find plate **//
            //****************//
            Int16Image binaryPlateImage = new Int16Image();

            if (!LicensePlateMatcher.FindPlate(plateImage, ref binaryPlateImage, TresholdConditions.NORMAAL) &&
                !LicensePlateMatcher.FindPlate(plateImage, ref binaryPlateImage, TresholdConditions.OVERBELICHT) &&
                !LicensePlateMatcher.FindPlate(plateImage, ref binaryPlateImage, TresholdConditions.ONDERBELICHT))
            {
                DisplayImage(binaryPlateImage, imgPlateBin, true, true);
                lblLexiconResult.Text = "";
                if (add)
                {
                    lstFindPlateErr.Items.Add(Filename);
                    lblFindPlateErrCount.Text = lstFindPlateErr.Items.Count.ToString();
                }
                ClearResultLabels();
                return;
            }
            DisplayImage(binaryPlateImage, imgPlateBin, true, true);

            //*******************//
            //** Rectify plate **//
            //*******************//
            Int16Image binaryRectifiedImage = new Int16Image();

            do
            {
                // Check if we can find the plate
                if (LicensePlateMatcher.FindCharacters(plateImage, binaryPlateImage, ref binaryRectifiedImage))
                {
                    // if so we are done
                    break;
                }
                else
                {
                    // ************************************
                    // **  Find the biggest blob in the  **
                    // **  image and remove that one     **
                    // ************************************
                    VisionLab.LabelBlobs(binaryPlateImage, Connected.EightConnected);
                    vector_BlobAnalyse ba_vec = new vector_BlobAnalyse();
                    ba_vec.Add(BlobAnalyse.BA_Area);
                    vector_Blob blobs = new vector_Blob();
                    VisionLab.BlobAnalysis(binaryPlateImage, VisionLab.VectorToSet_BlobAnalyse(ba_vec), VisionLab.MaxPixel(binaryPlateImage), blobs);
                    int biggestArea = 0;
                    foreach (Blob ba in blobs)
                    {
                        if (ba.Area() > biggestArea)
                        {
                            biggestArea = ba.Area();
                        }
                    }
                    VisionLab.RemoveBlobs(binaryPlateImage, Connected.EightConnected, BlobAnalyse.BA_Area, biggestArea - 1, biggestArea + 1);
                }
            } // Repeat this until there is nothing left
            while (VisionLab.SumIntPixels(binaryPlateImage) > 0);

            // If that is so it wasn't found
            if (VisionLab.SumIntPixels(binaryPlateImage) == 0)
            {
                // So do all this
                if (imgRectifiedPlate.Image != null)
                {
                    imgRectifiedPlate.Image.Dispose();
                }
                imgRectifiedPlate.Image = null;
                lblLexiconResult.Text   = "";
                if (add)
                {
                    lstRectifyPlateErr.Items.Add(Filename);
                    lblRectfyPlateErrCount.Text = lstRectifyPlateErr.Items.Count.ToString();
                }
                ClearResultLabels();
                return;
            }

            DisplayImage(binaryRectifiedImage, imgRectifiedPlate, true, true);


            //*****************//
            //** Match Plate **//
            //*****************//
            LicensePlate result        = new LicensePlate();
            LicensePlate lexiconResult = new LicensePlate();

            if (!LicensePlateMatcher.MatchPlate(binaryRectifiedImage, blobMatcher, lexicon, ref result, ref lexiconResult, false))
            {
                lblLexiconResult.Text = "";
                if (add)
                {
                    lstMatchPlateErr.Items.Add(Filename);
                    lblMatchPlateErrCount.Text = lstMatchPlateErr.Items.Count.ToString();
                }
                ClearResultLabels();
                return;
            }
            // Extra way to up confidence perhaps
            if (result.characters != null && result.confidence < (double)nupConfidence.Value / 100)
            {
                LicensePlateMatcher.MatchPlate(binaryRectifiedImage, blobMatcher, lexicon, ref result, ref lexiconResult, true);
            }

            //*********************//
            //** Process results **//
            //*********************//
            ProcessResults(result, lexiconResult, Filename, (double)nupConfidence.Value / 100, add);

            bm.Dispose();
            plateImage.Dispose();
            binaryPlateImage.Dispose();
            binaryRectifiedImage.Dispose();

            //Force a garbage collect to prevens malloc errors from unmanaged code.
            GC.Collect();
        }
Ejemplo n.º 16
0
        private void MatchImage(String Filename, bool add)
        {
            ErrorTB.Text = "";
            lblExpected.Text = Filename.Substring(0, 6);

            //*************************************//
            //** load and display original image **//
            //*************************************//
            Bitmap bm;
            bm = new Bitmap(Filename);
            RGB888Image plateImage = VisionLabEx.BitmapToJL(bm);
            DisplayImage(plateImage, imgOrig);            

            //****************//
            //** Find plate **//
            //****************//
            Int16Image binaryPlateImage = new Int16Image();

            if (!LicensePlateMatcher.FindPlate(plateImage, ref binaryPlateImage, TresholdConditions.NORMAAL) 
                && !LicensePlateMatcher.FindPlate(plateImage, ref binaryPlateImage, TresholdConditions.OVERBELICHT)
                && !LicensePlateMatcher.FindPlate(plateImage, ref binaryPlateImage, TresholdConditions.ONDERBELICHT))
            {
                DisplayImage(binaryPlateImage, imgPlateBin, true, true);
                lblLexiconResult.Text = "";
                if (add)
                {
                    lstFindPlateErr.Items.Add(Filename);
                    lblFindPlateErrCount.Text = lstFindPlateErr.Items.Count.ToString();
                }
                ClearResultLabels();
                return;
            }           
            DisplayImage(binaryPlateImage, imgPlateBin, true, true);
            
            //*******************//
            //** Rectify plate **//
            //*******************//                       
            Int16Image binaryRectifiedImage = new Int16Image();

            do
            {
                // Check if we can find the plate
                if (LicensePlateMatcher.FindCharacters(plateImage, binaryPlateImage, ref binaryRectifiedImage))
                {
                    // if so we are done
                    break;
                }
                else
                {
                    // ************************************
                    // **  Find the biggest blob in the  **
                    // **  image and remove that one     **
                    // ************************************
                    VisionLab.LabelBlobs(binaryPlateImage, Connected.EightConnected);
                    vector_BlobAnalyse ba_vec = new vector_BlobAnalyse();
                    ba_vec.Add(BlobAnalyse.BA_Area);
                    vector_Blob blobs = new vector_Blob();
                    VisionLab.BlobAnalysis(binaryPlateImage, VisionLab.VectorToSet_BlobAnalyse(ba_vec), VisionLab.MaxPixel(binaryPlateImage), blobs);
                    int biggestArea = 0;
                    foreach (Blob ba in blobs)
                    {
                        if (ba.Area() > biggestArea)
                        {
                            biggestArea = ba.Area();
                        }
                    }
                    VisionLab.RemoveBlobs(binaryPlateImage, Connected.EightConnected, BlobAnalyse.BA_Area, biggestArea - 1, biggestArea + 1);
                }
            } // Repeat this until there is nothing left
            while (VisionLab.SumIntPixels(binaryPlateImage) > 0);

            // If that is so it wasn't found
            if (VisionLab.SumIntPixels(binaryPlateImage) == 0)
            {
                // So do all this
                if (imgRectifiedPlate.Image != null)
                    imgRectifiedPlate.Image.Dispose();
                imgRectifiedPlate.Image = null;
                lblLexiconResult.Text = "";
                if (add)
                {
                    lstRectifyPlateErr.Items.Add(Filename);
                    lblRectfyPlateErrCount.Text = lstRectifyPlateErr.Items.Count.ToString();
                }
                ClearResultLabels();
                return;
            }

            DisplayImage(binaryRectifiedImage, imgRectifiedPlate, true, true);
            

            //*****************//
            //** Match Plate **//
            //*****************//
            LicensePlate result = new LicensePlate();
            LicensePlate lexiconResult = new LicensePlate();
            if (!LicensePlateMatcher.MatchPlate(binaryRectifiedImage, blobMatcher, lexicon, ref result, ref lexiconResult, false))
            {
                lblLexiconResult.Text = "";
                if (add)
                {
                    lstMatchPlateErr.Items.Add(Filename);
                    lblMatchPlateErrCount.Text = lstMatchPlateErr.Items.Count.ToString();
                }
                ClearResultLabels();
                return;
            }            
            // Extra way to up confidence perhaps
            if(result.characters != null && result.confidence < (double)nupConfidence.Value / 100)
            {
                LicensePlateMatcher.MatchPlate(binaryRectifiedImage, blobMatcher, lexicon, ref result, ref lexiconResult, true);
            }

            //*********************//
            //** Process results **//
            //*********************//            
            ProcessResults(result, lexiconResult, Filename, (double) nupConfidence.Value / 100, add);
            
            bm.Dispose();
            plateImage.Dispose();
            binaryPlateImage.Dispose();
            binaryRectifiedImage.Dispose();

            //Force a garbage collect to prevens malloc errors from unmanaged code.
            GC.Collect();
        }
        /*
            Description:
                Read the license plate
            Input:
	            //Rectified license plate image containing six characters	
	            Int16Image labeledRectifiedPlateImage
	            BlobMatcher_Int16 matcher	//initialized blobmatcher
	            ClassLexicon lexicon		//initialized lexicon
            Output:
	            //Result by the blob matcher
	            ref LicensePlate result
	            //Result by the lexicon
	            ref LicensePlate lexiconResult
            Return:
	            //six characters found
	        bool 
        */
        public static bool MatchPlate(Int16Image binaryCharacterImage, BlobMatcher_Int16 matcher, 
            ClassLexicon lexicon, ref LicensePlate result, ref LicensePlate lexiconResult, bool dilate)
        {
            // NIEUW
            // 2de optie voor aanroep als eerste low confidence levert
            if (dilate)
            {
                Int16Image temp = new Int16Image();
                VisionLab.Dilation(binaryCharacterImage, temp, new Mask_Int32(3, 3, 1));
                binaryCharacterImage = new Int16Image(temp);
                temp.Dispose();
            }
            if (VisionLab.LabelBlobs(binaryCharacterImage, Connected.EightConnected) != 6)
                return false;

            //Calculate dimensions and locations of all characters/blobs.
            vector_BlobAnalyse ba_vec = new vector_BlobAnalyse();
            ba_vec.Add(BlobAnalyse.BA_TopLeft);
            ba_vec.Add(BlobAnalyse.BA_Height);
            ba_vec.Add(BlobAnalyse.BA_Width);
            vector_Blob returnBlobs = new vector_Blob();
            VisionLab.BlobAnalysis(binaryCharacterImage, VisionLab.VectorToSet_BlobAnalyse(ba_vec), VisionLab.MaxPixel(binaryCharacterImage), returnBlobs, SortOrder.SortDown, BlobAnalyse.BA_TopLeft, UseXOrY.UseX);
            ba_vec.Dispose();
            Int16Image binaryCharacter = new Int16Image();

            //Create data structure for lexicon.
            vector_vector_LetterMatch match = new vector_vector_LetterMatch();
            
            // NIEUW
            // Change the matcher params
            matcher.ChangeParams(60, 10, 64, 0);
            //Process each character/blob.
            foreach (Blob b in returnBlobs)
            {
                //Cut out character
                VisionLab.ROI(binaryCharacterImage, binaryCharacter, b.TopLeft(), new HeightWidth(b.Height(), b.Width()));
                //Convert ROI result to binary
                VisionLab.ClipPixelValue(binaryCharacter, 0, 1);
                //Calculate character's classification for all classes.
                vector_PatternMatchResult returnMatches = new vector_PatternMatchResult();
                float conf = matcher.AllMatches(binaryCharacter, (float)-0.5, (float)0.5, returnMatches);
                float err = returnMatches[0].error;
                int id = returnMatches[0].id;
                string chr = matcher.PatternName(id);
                // NIEUW
                // If error to big decrease the confidence
                if(err > 0.20f)
                    conf -= 0.2f;
                //Fill datastructure for lexicon.
                match.Add(VisionLabEx.PatternMatchResultToLetterMatch(returnMatches));
                
                //Store best match in result
                result.characters.Add(
                    new LicenseCharacter(
                        chr, 
                        err, 
                        conf,

                        // NIEUW
                        // Extra param: The middle of a character
                        // (used for matching patterns)
                        b.TopLeft().x + ((b.TopRight().x - b.TopLeft().x)/2) ,

                        // NIEUW
                        // All other results that we're found
                        // So we can switch between em
                        returnMatches
                        ));
            }

            //Validate match with lexicon.
            vector_int bestWord = new vector_int();
            lexiconResult.confidence = lexicon.FindBestWord(match, bestWord, Optimize.OptimizeForMinimum);
            for (int i = 0; i < bestWord.Count; i++)
            {
                string character = matcher.PatternName(bestWord[i]);
                //Store lexicon result
                lexiconResult.characters.Add(new LicenseCharacter(character));
            }

            // NIEUW
            // Create the best match with the aid of the pattern matcher
            result.CalculateBestMatch(matcher);
            
            binaryCharacter.Dispose();
            returnBlobs.Dispose();
            match.Dispose();
            bestWord.Dispose();
            GC.Collect();
            return true;
        }
        /*
         *  Description:
         *      Read the license plate
         *  Input:
         *      //Rectified license plate image containing six characters
         *      Int32Image labeledRectifiedPlateImage
         *  Output:
         *      //Result by the blob matcher
         *      ref LicensePlate result
         *  Return:
         *      //six characters found
         *      bool
         */
        public static bool MatchPlate(Int32Image binaryCharacterImage, BlobMatcher_Int32 matcher, ClassLexicon lexicon, ref LicensePlate result, ref LicensePlate lexiconResult)
        {
            try
            {
                //Check if 6 characters/blobs have been found and label image.
                if (VisionLab.LabelBlobs(binaryCharacterImage, Connected.EightConnected) != 6)
                {
                    return(false);
                }

                //Calculate dimensions and locations of all characters/blobs.
                vector_BlobAnalyse ba_vec = new vector_BlobAnalyse();
                ba_vec.Add(BlobAnalyse.BA_TopLeft);
                ba_vec.Add(BlobAnalyse.BA_Height);
                ba_vec.Add(BlobAnalyse.BA_Width);
                vector_Blob returnBlobs = new vector_Blob();
                VisionLab.BlobAnalysis(binaryCharacterImage, VisionLab.VectorToSet_BlobAnalyse(ba_vec), VisionLab.MaxPixel(binaryCharacterImage), returnBlobs, SortOrder.SortDown, BlobAnalyse.BA_TopLeft, UseXOrY.UseX);
                ba_vec.Dispose();
                Int32Image binaryCharacter = new Int32Image();

                //Create data structure for lexicon.
                vector_vector_LetterMatch match = new vector_vector_LetterMatch();

                //Process each character/blob.
                foreach (Blob b in returnBlobs)
                {
                    //Cut out character
                    VisionLab.ROI(binaryCharacterImage, binaryCharacter, b.TopLeft(), new HeightWidth(b.Height(), b.Width()));
                    //Convert ROI result to binary
                    VisionLab.ClipPixelValue(binaryCharacter, 0, 1);

                    //Calculate character's classification for all classes.
                    vector_PatternMatchResult returnMatches = new vector_PatternMatchResult();
                    float  conf = matcher.AllMatches(binaryCharacter, (float)-0.5, (float)0.5, returnMatches);
                    float  err  = returnMatches[0].error;
                    int    id   = returnMatches[0].id;
                    string chr  = matcher.PatternName(id);

                    //Fill datastructure for lexicon.
                    match.Add(VisionLabEx.PatternMatchResultToLetterMatch(returnMatches));

                    //Store best match in result
                    result.characters.Add(new LicenseCharacter(chr, err, conf));
                }

                //Validate match with lexicon.
                vector_int bestWord = new vector_int();
                lexiconResult.confidence = lexicon.FindBestWord(match, bestWord, Optimize.OptimizeForMinimum);
                for (int i = 0; i < bestWord.Count; i++)
                {
                    string character = matcher.PatternName(bestWord[i]);
                    //Store lexicon result
                    lexiconResult.characters.Add(new LicenseCharacter(character));
                }

                binaryCharacter.Dispose();
                returnBlobs.Dispose();
                match.Dispose();
                bestWord.Dispose();

                bool[] types = new bool[6];
                for (int i = 0; i < 6; i++)
                {
                    types[i] = '0' <= result.characters[i].character[0] && result.characters[i].character[0] <= '9';
                }
                if (types[0] && types[1] && !types[2] && !types[3] && !types[4] && !types[5])
                {
                    return(true);
                }
                if (!types[0] && !types[1] && types[2] && types[3] && !types[4] && !types[5])
                {
                    return(true);
                }
                if (!types[0] && !types[1] && !types[2] && !types[3] && types[4] && types[5])
                {
                    return(true);
                }
                if (types[0] && !types[1] && !types[2] && !types[3] && types[4] && types[5])
                {
                    return(true);
                }
                if (types[0] && types[1] && !types[2] && !types[3] && !types[4] && types[5])
                {
                    return(true);
                }
                return(false);
            }
            catch (System.Exception ex)
            {
                throw new Exception("MatchPlate: " + ex.Message);
            }
        }
Ejemplo n.º 19
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(vector_Blob obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
Ejemplo n.º 20
0
 internal static HandleRef getCPtr(vector_Blob obj)
 {
     return((obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr);
 }
        public static void GetBlobsInfo(Image binaryImage, vector_BlobAnalyse analysis, ref vector_Blob blobs)
        {
            Int32Image labeledBinaryImage = new Int32Image();

            VisionLab.Convert(binaryImage, labeledBinaryImage);
            int maxlabel = VisionLab.LabelBlobs(labeledBinaryImage, Connected.EightConnected);

            VisionLab.BlobAnalysis(labeledBinaryImage, VisionLab.VectorToSet_BlobAnalyse(analysis), maxlabel, blobs);
            labeledBinaryImage.Dispose();
            //GC.Collect();
        }