public static void DisplayImage(Image img, PictureBox pb, bool stretch, bool invert)
        {
            Bitmap bm;

            if (img is Int32Image)
            {
                Int32Image disp = new Int32Image((Int32Image)img);
                if (invert)
                {
                    VisionLab.Not((Int32Image)disp);
                }
                if (stretch)
                {
                    VisionLab.Multiply((Int32Image)disp, 255);
                }

                bm = VisionLabEx.JLToBitmap(disp);
                disp.Dispose();
            }
            else
            {
                bm = VisionLabEx.JLToBitmap(img);
            }

            if (pb.Image != null)
            {
                pb.Image.Dispose();
            }
            pb.Image = bm;
        }
예제 #2
0
        /*  Description:
         *      Find the largest license plate in the image
         *          - Segment using ThresholdHSVchannels
         *          - Remove blobs which are not license plates
         *  Input:
         *          //Original image
         *          RGB888Image plateImage
         *  Output:
         *          //Segmented license plate
         *          ref Int32Image binaryPlateImage
         *  Return:
         *          //License plate found?
         *          bool
         */
        public static bool FindPlate(RGB888Image plateImage, ref Int32Image binaryPlateImage)
        {
            //Constants
            const int c_threshold_h_min  = 21;
            const int c_threshold_h_max  = 50;
            const int c_threshold_s_min  = 100;
            const int c_threshold_s_max  = 255;
            const int c_threshold_v_min  = 100;
            const int c_threshold_v_max  = 255;
            const int c_remove_blobs_min = 1;
            const int c_remove_blobs_max = 5000;

            //*******************************//
            //** Exercise:                 **//
            //**   adjust licenseplate     **//
            //**   segmentation            **//
            //*******************************//

            //Find licenseplate
            HSV888Image plateImageHSV = new HSV888Image();

            //Convert to RGB to HSV
            VisionLab.FastRGBToHSV(plateImage, plateImageHSV);

            //Threshold HSV image
            VisionLab.Threshold3Channels(plateImageHSV, binaryPlateImage, c_threshold_h_min, c_threshold_h_max, c_threshold_s_min, c_threshold_s_max, c_threshold_v_min, c_threshold_v_max);

            //Remove blobs with small areas
            VisionLab.RemoveBlobs(binaryPlateImage, Connected.EightConnected, BlobAnalyse.BA_Area, c_remove_blobs_min, c_remove_blobs_max);

            plateImageHSV.Dispose();
            //GC.Collect();
            //Return true, if pixels found
            return(VisionLab.SumIntPixels(binaryPlateImage) > 0);
        }
예제 #3
0
 public Int32Image(Int32Image image) : this(VisionLabPINVOKE.new_Int32Image__SWIG_3(Int32Image.getCPtr(image)), true)
 {
     if (VisionLabPINVOKE.SWIGPendingException.Pending)
     {
         throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
     }
 }
예제 #4
0
 public virtual void Resize(HeightWidth hw, Int32Image properties)
 {
     VisionLabPINVOKE.Int32Image_Resize__SWIG_1(swigCPtr, HeightWidth.getCPtr(hw), Int32Image.getCPtr(properties));
     if (VisionLabPINVOKE.SWIGPendingException.Pending)
     {
         throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
     }
 }
예제 #5
0
 public virtual void SnapShot(Int32Image image)
 {
     VisionLabPINVOKE.Camera_Int32_SnapShot__SWIG_1(swigCPtr, Int32Image.getCPtr(image));
     if (VisionLabPINVOKE.SWIGPendingException.Pending)
     {
         throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
     }
 }
    public override int BestMatch(Int32Image blob, float beginAngle, float endAngle, ref float confidence, ref float error, ref float scale, ref float angle)
    {
        int ret = VisionLabPINVOKE.BlobMatcher_Int32_BestMatch(swigCPtr, Int32Image.getCPtr(blob), beginAngle, endAngle, ref confidence, ref error, ref scale, ref angle);

        if (VisionLabPINVOKE.SWIGPendingException.Pending)
        {
            throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
    public override int FindPatterns(Int32Image image, float maxError, float minConfindence, float beginAngle, float endAngle, vector_PatternMatchResult labelTab, vector_vector_int patTab)
    {
        int ret = VisionLabPINVOKE.BlobMatcher_Int32_FindPatterns(swigCPtr, Int32Image.getCPtr(image), maxError, minConfindence, beginAngle, endAngle, vector_PatternMatchResult.getCPtr(labelTab), vector_vector_int.getCPtr(patTab));

        if (VisionLabPINVOKE.SWIGPendingException.Pending)
        {
            throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
    public override Int32Image PatternImage(string name)
    {
        Int32Image ret = new Int32Image(VisionLabPINVOKE.BlobMatcher_Int32_PatternImage__SWIG_1(swigCPtr, name), false);

        if (VisionLabPINVOKE.SWIGPendingException.Pending)
        {
            throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
예제 #9
0
    public virtual Int32Image PatternImage(int id)
    {
        Int32Image ret = new Int32Image(VisionLabPINVOKE.PatternMatcher_Int32_PatternImage__SWIG_0(swigCPtr, id), false);

        if (VisionLabPINVOKE.SWIGPendingException.Pending)
        {
            throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
    public override int AddPattern(Int32Image image, string name)
    {
        int ret = VisionLabPINVOKE.BlobMatcher_Int32_AddPattern(swigCPtr, Int32Image.getCPtr(image), name);

        if (VisionLabPINVOKE.SWIGPendingException.Pending)
        {
            throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
    public Int32Image GetImage(string className, int imageIndex)
    {
        Int32Image ret = new Int32Image(VisionLabPINVOKE.ClassFeatureSet_Int32_GetImage(swigCPtr, className, imageIndex), false);

        if (VisionLabPINVOKE.SWIGPendingException.Pending)
        {
            throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
    public double TrainImage(double learnRate, double momentum, Int32Image image, int classNr)
    {
        double ret = VisionLabPINVOKE.BPN_ImageClassifier_Int32_TrainImage(swigCPtr, learnRate, momentum, Int32Image.getCPtr(image), classNr);

        if (VisionLabPINVOKE.SWIGPendingException.Pending)
        {
            throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
    public double ClassifyOutputTab(Int32Image image, vector_ClassOutput outputTab)
    {
        double ret = VisionLabPINVOKE.BPN_ImageClassifier_Int32_ClassifyOutputTab(swigCPtr, Int32Image.getCPtr(image), vector_ClassOutput.getCPtr(outputTab));

        if (VisionLabPINVOKE.SWIGPendingException.Pending)
        {
            throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
    public double EvaluateImage(Int32Image image, int classExp, ref int classRes, ref double confidency, vector_double output)
    {
        double ret = VisionLabPINVOKE.BPN_ImageClassifier_Int32_EvaluateImage(swigCPtr, Int32Image.getCPtr(image), classExp, ref classRes, ref confidency, vector_double.getCPtr(output));

        if (VisionLabPINVOKE.SWIGPendingException.Pending)
        {
            throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
    public bool GetImage(string imageName, Int32Image image)
    {
        bool ret = VisionLabPINVOKE.VisLibCmdInt_GetImage__SWIG_4(swigCPtr, imageName, Int32Image.getCPtr(image));

        if (VisionLabPINVOKE.SWIGPendingException.Pending)
        {
            throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
    public int Classify(Int32Image image, ref double confidency)
    {
        int ret = VisionLabPINVOKE.BPN_ImageClassifier_Int32_Classify(swigCPtr, Int32Image.getCPtr(image), ref confidency);

        if (VisionLabPINVOKE.SWIGPendingException.Pending)
        {
            throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
    public int AddImage(string className, Int32Image image)
    {
        int ret = VisionLabPINVOKE.ClassFeatureSet_Int32_AddImage(swigCPtr, className, Int32Image.getCPtr(image));

        if (VisionLabPINVOKE.SWIGPendingException.Pending)
        {
            throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
    public override float AllMatches(Int32Image blob, float beginAngle, float endAngle, vector_PatternMatchResult tab)
    {
        float ret = VisionLabPINVOKE.BlobMatcher_Int32_AllMatches(swigCPtr, Int32Image.getCPtr(blob), beginAngle, endAngle, vector_PatternMatchResult.getCPtr(tab));

        if (VisionLabPINVOKE.SWIGPendingException.Pending)
        {
            throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
예제 #19
0
        /*  Description:
         *      Locates the characters of the license plate
         *              - Warp image (Rectify)
         *              - Segment characters
         *              - Remove blobs which are to small (Lines between characters)
         *  Input:
         *          //Original image
         *          RGB888Image plateImage
         *          //Segmented license plate
         *          Int32Image binaryPlateImage
         *  Output:
         *          //Image containing binary six characters
         *          ref Int32Image binaryCharacterImage
         *  Return:
         *          //Function executed successfully
         *          bool
         */
        public static bool FindCharacters(RGB888Image plateImage, Int32Image binaryPlateImage, ref Int32Image binaryCharacterImage)
        {
            //Constants
            const int c_height           = 100;
            const int c_width            = 470;
            const int c_remove_blobs_min = 1;
            const int c_remove_blobs_max = 400;

            XYCoord leftTop     = new XYCoord();
            XYCoord rightTop    = new XYCoord();
            XYCoord leftBottom  = new XYCoord();
            XYCoord rightBottom = new XYCoord();


            //Find licenseplate
            VisionLab.FindCornersRectangle(binaryPlateImage, Connected.EightConnected, 0.5, Orientation.Landscape, leftTop, rightTop, leftBottom, rightBottom);

            Int32Image plateImageGray = new Int32Image();

            VisionLab.Convert(plateImage, plateImageGray);

            try
            {
                //Rectify plate
                VisionLab.Warp(plateImageGray, binaryCharacterImage, TransformDirection.ForwardT, new Coord2D(leftTop), new Coord2D(rightTop), new Coord2D(leftBottom), new Coord2D(rightBottom), c_height, c_width, 0);
            }
            catch (Exception)
            {
                //Warp, 3 coords on one line
                return(false);
            }
            plateImageGray.Dispose();

            //*******************************//
            //** Exercise:                 **//
            //**   adjust licenseplate     **//
            //**   segmentation            **//
            //*******************************//

            //Find dark text on bright licenseplate using ThresholdISOData
            VisionLab.ThresholdIsoData(binaryCharacterImage, ObjectBrightness.DarkObject);

            //Remove blobs connected to the border
            VisionLab.RemoveBorderBlobs(binaryCharacterImage, Connected.EightConnected, Border.AllBorders);
            //Remove small blobs
            VisionLab.RemoveBlobs(binaryCharacterImage, Connected.EightConnected, BlobAnalyse.BA_Area, c_remove_blobs_min, c_remove_blobs_max);

            leftTop.Dispose();
            rightTop.Dispose();
            leftBottom.Dispose();
            rightBottom.Dispose();
            //GC.Collect();
            return(true);
        }
        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();
        }
예제 #21
0
 /*
  *  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, ref LicensePlate result)
 {
     try
     {
         VisionLab.SetInt32Image(cmdInt, "binaryCharacterImage", binaryCharacterImage);
         String plateStr = StripTime(cmdInt.ExecRequest("icall MatchPlate binaryCharacterImage"));
         if (plateStr.Substring(0, 5) != "false")
         {
             string[] plateResult      = plateStr.Split(' ');
             string   plateResultChars = plateResult[0];
             result.confidence = double.Parse(plateResult[1], CultureInfo.InvariantCulture);
             for (int c = 0; c < 6; c++)
             {
                 result.characters.Add(new LicenseCharacter(plateResultChars[c].ToString(), double.Parse(plateResult[2 + c], CultureInfo.InvariantCulture), result.confidence));
             }
             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);
         }
         else
         {
             return(false);
         }
     }
     catch (System.Exception ex)
     {
         throw new Exception("MatchPlate: " + ex.Message);
     }
 }
        /*
         *  Description:
         *      Find the largest license plate in the image
         *      - Segment using ThresholdHSVchannels
         *      - Remove blobs which are not license plates
         *  Input:
         *      //Original image
         *      RGB888Image plateImage
         *  Output:
         *      //Segmented license plate
         *      ref Int32Image binaryPlateImage
         *  Return:
         *      //License plate found?
         *      bool
         */
        public static bool FindPlate(RGB888Image plateImage, ref Int32Image binaryPlateImage)
        {
            try
            {
                //Constants
                const int c_threshold_h_min = 14;
                const int c_threshold_h_max = 50;
                const int c_threshold_s_min = 100;
                const int c_threshold_s_max = 255;
                const int c_threshold_v_min = 46;
                const int c_threshold_v_max = 255;

                //*******************************//
                //** Exercise:                 **//
                //**   adjust licenseplate     **//
                //**   segmentation            **//
                //*******************************//

                //Find licenseplate
                HSV888Image plateImageHSV = new HSV888Image();
                //Convert to RGB to HSV
                VisionLab.FastRGBToHSV(plateImage, plateImageHSV);

                //Threshold HSV image
                VisionLab.Threshold3Channels(plateImageHSV, binaryPlateImage, c_threshold_h_min, c_threshold_h_max, c_threshold_s_min, c_threshold_s_max, c_threshold_v_min, c_threshold_v_max);


                VisionLab.LabelBlobs(binaryPlateImage, Connected.EightConnected);

                VisionLab.RemoveBlobs(binaryPlateImage, Connected.EightConnected, BlobAnalyse.BA_LengthBreadthRatio, 0.0, 2.50);
                VisionLab.RemoveBlobs(binaryPlateImage, Connected.EightConnected, BlobAnalyse.BA_LengthBreadthRatio, 10.0, 9999.0);

                //Remove blobs with small areas
                VisionLab.RemoveBlobs(binaryPlateImage, Connected.EightConnected, BlobAnalyse.BA_Area, 1, 1000, UseXOrY.UseX);
                //VisionLab.RemoveBlobs(binaryPlateImage, Connected.EightConnected, BlobAnalyse.BA_Area, 80000, 120000);

                //Fill up characters
                VisionLab.FillHoles(binaryPlateImage, Connected.EightConnected);

                plateImageHSV.Dispose();
                //Return true, if pixels found
                return(VisionLab.SumIntPixels(binaryPlateImage) > 0);
            }
            catch (System.Exception ex)
            {
                throw new Exception("FindPlate: " + ex.Message);
            }
        }
예제 #23
0
 /*
  *  Description:
  *      Find the largest license plate in the image
  *      - Segment using ThresholdHSVchannels
  *      - Remove blobs which are not license plates
  *  Input:
  *      //Original image
  *      RGB888Image plateImage
  *  Output:
  *      //Segmented license plate
  *      ref Int32Image binaryPlateImage
  *  Return:
  *      //License plate found?
  *      bool
  */
 public static bool FindPlate(RGB888Image plateImage, ref Int32Image binaryPlateImage)
 {
     try {
         VisionLab.SetRGB888Image(cmdInt, "plateImage", plateImage);
         String result = StripTime(cmdInt.ExecRequest("icall FindPlate plateImage binaryPlateImage"));
         if (result == "true")
         {
             VisionLab.GetInt32Image(cmdInt, "binaryPlateImage", binaryPlateImage);
         }
         return(result == "true");
     }
     catch (System.Exception ex)
     {
         throw new Exception("FindPlate: " + ex.Message);
     }
 }
예제 #24
0
 /*
  *  Description:
  *      Locates the characters of the license plate
  *      - Warp image (Rectify)
  *      - Segment characters
  *      - Remove blobs which are to small (Lines between characters)
  *  Input:
  *      //Original image
  *      RGB888Image plateImage
  *      //Segmented license plate
  *      Int32Image binaryPlateImage
  *      Output:
  *      //Image containing binary six characters
  *      ref Int32Image binaryCharacterImage
  *  Return:
  *      //Function executed successfully
  *      bool
  */
 public static bool FindCharacters(RGB888Image plateImage, Int32Image binaryPlateImage, ref Int32Image binaryCharacterImage)
 {
     try
     {
         VisionLab.SetRGB888Image(cmdInt, "plateImage", plateImage);
         VisionLab.SetInt32Image(cmdInt, "binaryPlateImage", binaryPlateImage);
         String result = StripTime(cmdInt.ExecRequest("icall FindCharacters plateImage binaryPlateImage binaryCharacterImage"));
         if (result == "true")
         {
             VisionLab.GetInt32Image(cmdInt, "binaryCharacterImage", binaryCharacterImage);
         }
         return(result == "true");
     }
     catch (System.Exception ex)
     {
         //if (ex.Message.StartsWith("[DefaultLUTForImage]"))
         //    return false;
         ////if (ex.Message.Substring(0, 6) == "[DefaultLUTForImage]")
         ////    return false;
         throw new Exception("FindCharacters: " + ex.Message);
     }
 }
예제 #25
0
 public static vector_HoughLine FindFastBestLines(Int32Image src, HLParams p, int edgeMin, int nrLines, double minR, double minPhi, int minHits) {
   vector_HoughLine ret = new vector_HoughLine(VisionLabPINVOKE.FindFastBestLines__SWIG_4(Int32Image.getCPtr(src), HLParams.getCPtr(p), edgeMin, nrLines, minR, minPhi, minHits), true);
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
 public double EvaluateImage(Int32Image image, int classExp, ref int classRes, ref double confidency, vector_double output) {
   double ret = VisionLabPINVOKE.BPN_ImageClassifier_Int32_EvaluateImage(swigCPtr, Int32Image.getCPtr(image), classExp, ref classRes, ref confidency, vector_double.getCPtr(output));
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
 public int Classify(Int32Image image, ref double confidency) {
   int ret = VisionLabPINVOKE.BPN_ImageClassifier_Int32_Classify(swigCPtr, Int32Image.getCPtr(image), ref confidency);
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
예제 #28
0
 public static void DiskShape(Int32Image image, XYCoord centre, double r, int value) {
   VisionLabPINVOKE.DiskShape__SWIG_9(Int32Image.getCPtr(image), XYCoord.getCPtr(centre), r, value);
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
 }
예제 #29
0
 public static int CountPixel(Int32Image image, int value) {
   int ret = VisionLabPINVOKE.CountPixel__SWIG_4(Int32Image.getCPtr(image), value);
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
예제 #30
0
 public static void BlockPattern(Int32Image image, XYCoord leftTop, int height, int width, int value, int repeatx, int repeaty) {
   VisionLabPINVOKE.BlockPattern__SWIG_9(Int32Image.getCPtr(image), XYCoord.getCPtr(leftTop), height, width, value, repeatx, repeaty);
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
 }
예제 #31
0
 public static void ThresholdMulti(Int32Image image, SWIGTYPE_p_std__setT_int_t selectSet) {
   VisionLabPINVOKE.ThresholdMulti__SWIG_4(Int32Image.getCPtr(image), SWIGTYPE_p_std__setT_int_t.getCPtr(selectSet));
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
 }
        /*
         *  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);
            }
        }
예제 #33
0
 public static void FastHoughLineT(Int32Image src, HLParams p, int edgeMin, Int32Image dest) {
   VisionLabPINVOKE.FastHoughLineT__SWIG_4(Int32Image.getCPtr(src), HLParams.getCPtr(p), edgeMin, Int32Image.getCPtr(dest));
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
 }
예제 #34
0
 public static void ContrastStretchLUT(Int32Image image, int low, int high) {
   VisionLabPINVOKE.ContrastStretchLUT__SWIG_4(Int32Image.getCPtr(image), low, high);
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
 }
예제 #35
0
 public static void CalcHistogram0(Int32Image image, int hisSize, SWIGTYPE_p_int his) {
   VisionLabPINVOKE.CalcHistogram0__SWIG_4(Int32Image.getCPtr(image), hisSize, SWIGTYPE_p_int.getCPtr(his));
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
 }
예제 #36
0
 public static Histogram CalcHistogram(Int32Image image, Int32Image roi) {
   Histogram ret = new Histogram(VisionLabPINVOKE.CalcHistogram__SWIG_19(Int32Image.getCPtr(image), Int32Image.getCPtr(roi)), true);
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
예제 #37
0
 public static void Extract1Channel(HSV161616Image image, HSVColor plane, Int32Image chan) {
   VisionLabPINVOKE.Extract1Channel__SWIG_66(HSV161616Image.getCPtr(image), (int)plane, Int32Image.getCPtr(chan));
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
 }
예제 #38
0
 public static void ThresholdHysteresis(Int32Image image, int low, int high, Connected connected) {
   VisionLabPINVOKE.ThresholdHysteresis__SWIG_4(Int32Image.getCPtr(image), low, high, (int)connected);
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
 }
예제 #39
0
 public static int ThresholdIsoData(Int32Image image, Int32Image roi, ObjectBrightness arg2) {
   int ret = VisionLabPINVOKE.ThresholdIsoData__SWIG_9(Int32Image.getCPtr(image), Int32Image.getCPtr(roi), (int)arg2);
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
예제 #40
0
 public static void Remainder(Int32Image dest, Int32Image src) {
   VisionLabPINVOKE.Remainder__SWIG_4(Int32Image.getCPtr(dest), Int32Image.getCPtr(src));
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
 }
예제 #41
0
 public static void AddBorder(Int32Image src, Int32Image dest, int top, int left, int right, int bottom, int value) {
   VisionLabPINVOKE.AddBorder__SWIG_4(Int32Image.getCPtr(src), Int32Image.getCPtr(dest), top, left, right, bottom, value);
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
 }
예제 #42
0
 public static void SetMultiToValueLUT(Int32Image image, SWIGTYPE_p_std__setT_int_t selectSet, int value) {
   VisionLabPINVOKE.SetMultiToValueLUT__SWIG_4(Int32Image.getCPtr(image), SWIGTYPE_p_std__setT_int_t.getCPtr(selectSet), value);
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
 }
예제 #43
0
 public static void CircleShape(Int32Image image, XYCoord centre, int r, int value, ZeroOrOriginal zorg) {
   VisionLabPINVOKE.CircleShape__SWIG_8(Int32Image.getCPtr(image), XYCoord.getCPtr(centre), r, value, (int)zorg);
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
 }
예제 #44
0
 public static int SumIntPixels(Int32Image image) {
   int ret = VisionLabPINVOKE.SumIntPixels__SWIG_4(Int32Image.getCPtr(image));
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
예제 #45
0
 public static void DeInterlace(Int32Image image) {
   VisionLabPINVOKE.DeInterlace__SWIG_4(Int32Image.getCPtr(image));
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
 }
예제 #46
0
 public static void SwapAxis(Int32Image src, Int32Image dest, ViewPoint viewPoint, int scale) {
   VisionLabPINVOKE.SwapAxis__SWIG_4(Int32Image.getCPtr(src), Int32Image.getCPtr(dest), (int)viewPoint, scale);
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
 }
 public double TrainImage(double learnRate, double momentum, Int32Image image, int classNr) {
   double ret = VisionLabPINVOKE.BPN_ImageClassifier_Int32_TrainImage(swigCPtr, learnRate, momentum, Int32Image.getCPtr(image), classNr);
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
예제 #48
0
 public static void ThresholdFast(Int32Image image, int thres, ObjectBrightness arg2) {
   VisionLabPINVOKE.ThresholdFast__SWIG_26(Int32Image.getCPtr(image), thres, (int)arg2);
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
 }
 public double ClassifyOutputTab(Int32Image image, vector_ClassOutput outputTab) {
   double ret = VisionLabPINVOKE.BPN_ImageClassifier_Int32_ClassifyOutputTab(swigCPtr, Int32Image.getCPtr(image), vector_ClassOutput.getCPtr(outputTab));
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
예제 #50
0
 public static void ThresholdFast(Int32Image image, int low, int high) {
   VisionLabPINVOKE.ThresholdFast__SWIG_29(Int32Image.getCPtr(image), low, high);
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
 }
예제 #51
0
 internal static HandleRef getCPtr(Int32Image obj)
 {
     return((obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr);
 }
예제 #52
0
 public static HoughLine FindFastBestLine(Int32Image src, HLParams p, int edgeMin) {
   HoughLine ret = new HoughLine(VisionLabPINVOKE.FindFastBestLine__SWIG_4(Int32Image.getCPtr(src), HLParams.getCPtr(p), edgeMin), true);
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
예제 #53
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Int32Image obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
예제 #54
0
 public static void LUT(Int32Image image, int minPixel, vector_int tab) {
   VisionLabPINVOKE.LUT__SWIG_9(Int32Image.getCPtr(image), minPixel, vector_int.getCPtr(tab));
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
 }
예제 #55
0
 public static void GammaLUT(Int32Image image, double gamma) {
   VisionLabPINVOKE.GammaLUT__SWIG_4(Int32Image.getCPtr(image), gamma);
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
 }
        /*
         *  Description:
         *      Locates the characters of the license plate
         *      - Warp image (Rectify)
         *      - Segment characters
         *      - Remove blobs which are to small (Lines between characters)
         *  Input:
         *      //Original image
         *      RGB888Image plateImage
         *      //Segmented license plate
         *      Int32Image binaryPlateImage
         *      Output:
         *      //Image containing binary six characters
         *      ref Int32Image binaryCharacterImage
         *  Return:
         *      //Function executed successfully
         *      bool
         */
        public static bool FindCharacters(RGB888Image plateImage, Int32Image binaryPlateImage, ref Int32Image binaryCharacterImage)
        {
            try
            {
                //Constants
                const int c_height           = 100;
                const int c_width            = 470;
                const int c_remove_blobs_min = 1;
                const int c_remove_blobs_max = 450;

                XYCoord leftTop     = new XYCoord();
                XYCoord rightTop    = new XYCoord();
                XYCoord leftBottom  = new XYCoord();
                XYCoord rightBottom = new XYCoord();


                //Find licenseplate
                VisionLab.FindCornersRectangle(binaryPlateImage, Connected.EightConnected, 0.5, Orientation.Landscape, leftTop, rightTop, leftBottom, rightBottom);
                if (!VisionLab.WarpCoordsValid(new Coord2D(leftTop), new Coord2D(rightTop), new Coord2D(leftBottom), new Coord2D(rightBottom)))
                {
                    VisionLab.FindCornersRectangleSq(binaryPlateImage, Connected.EightConnected, leftTop, rightTop, leftBottom, rightBottom);
                    if (!VisionLab.WarpCoordsValid(new Coord2D(leftTop), new Coord2D(rightTop), new Coord2D(leftBottom), new Coord2D(rightBottom)))
                    {
                        return(false);
                    }
                }

                Int32Image plateImageGray = new Int32Image();
                VisionLab.Convert(plateImage, plateImageGray);

                //Rectify plate
                VisionLab.Warp(plateImageGray, binaryCharacterImage, TransformDirection.ForwardT, new Coord2D(leftTop), new Coord2D(rightTop), new Coord2D(leftBottom), new Coord2D(rightBottom), c_height, c_width, 0);


                plateImageGray.Dispose();

                //*******************************//
                //** Exercise:                 **//
                //**   adjust licenseplate     **//
                //**   segmentation            **//
                //*******************************//


                //Find dark text on bright licenseplate using ThresholdISOData
                VisionLab.ThresholdIsoData(binaryCharacterImage, ObjectBrightness.DarkObject);

                //Remove small blobs and noise
                Int32Image binaryCharacterImageCopy = new Int32Image(binaryCharacterImage);
                VisionLab.Opening(binaryCharacterImageCopy, binaryCharacterImage, new Mask_Int32(5, 1, 1));

                //Remove blobs connected to the border
                VisionLab.RemoveBorderBlobs(binaryCharacterImage, Connected.EightConnected, Border.AllBorders);
                //Remove small blobs
                VisionLab.RemoveBlobs(binaryCharacterImage, Connected.EightConnected, BlobAnalyse.BA_Area, c_remove_blobs_min, c_remove_blobs_max);

                leftTop.Dispose();
                rightTop.Dispose();
                leftBottom.Dispose();
                rightBottom.Dispose();

                return(true);
            }
            catch (System.Exception ex)
            {
                throw new Exception("FindCharacters: " + ex.Message);
            }
        }
예제 #57
0
 public static void HistogramEqualize(Int32Image image) {
   VisionLabPINVOKE.HistogramEqualize__SWIG_4(Int32Image.getCPtr(image));
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
 }
예제 #58
0
 public static void InvertLUT(Int32Image image) {
   VisionLabPINVOKE.InvertLUT__SWIG_4(Int32Image.getCPtr(image));
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
 }
예제 #59
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);

            VisionLabEx.DisplayImage(plateImage, imgOrig);

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

            if (!LicensePlateMatcher.FindPlate(plateImage, ref binaryPlateImage))
            {
                VisionLabEx.DisplayImage(binaryPlateImage, imgPlateBin, true, true);
                lblLexiconResult.Text = "";
                if (add)
                {
                    lstFindPlateErr.Items.Add(Filename);
                    lblFindPlateErrCount.Text = lstFindPlateErr.Items.Count.ToString();
                }
                ClearResultLabels();
                return;
            }
            VisionLabEx.DisplayImage(binaryPlateImage, imgPlateBin, true, true);
            //**
            //** Enable this to display blob measurements to debug output
            //**
            DisplayBlobs(binaryPlateImage);

            //*******************//
            //** Rectify plate **//
            //*******************//
            Int32Image binaryCharacterImage = new Int32Image();

            if (!LicensePlateMatcher.FindCharacters(plateImage, binaryPlateImage, ref binaryCharacterImage))
            {
                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;
            }
            VisionLabEx.DisplayImage(binaryCharacterImage, imgRectifiedPlate, true, true);
            //**
            //** Enable this to display blob measurements to debug output
            //**
            DisplayBlobs(binaryCharacterImage);

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

            if (!LicensePlateMatcher.MatchPlate(binaryCharacterImage, blobMatcher, lexicon, ref result, ref lexiconResult))
            {
                lblLexiconResult.Text = "";
                if (add)
                {
                    lstMatchPlateErr.Items.Add(Filename);
                    lblMatchPlateErrCount.Text = lstMatchPlateErr.Items.Count.ToString();
                }
                ClearResultLabels();
                return;
            }

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

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

            //Force a garbage collect to prevens malloc errors from unmanaged code.
            GC.Collect();
        }
        /*  Description:
         *      Find the largest license plate in the image
         *          - Segment using ThresholdHSVchannels
         *          - Remove blobs which are not license plates
         *  Input:
         *          //Original image
         *          RGB888Image plateImage
         *  Output:
         *          //Segmented license plate
         *          ref Int16Image binaryPlateImage
         *  Return:
         *          //License plate found?
         *          bool
         */
        public static bool FindPlate(RGB888Image plateImage, ref Int16Image binaryPlateImage, TresholdConditions state)
        {
            //Constants
            int c_threshold_h_min  = 0;
            int c_threshold_h_max  = 0;
            int c_threshold_s_min  = 0;
            int c_threshold_s_max  = 0;
            int c_threshold_v_min  = 0;
            int c_threshold_v_max  = 0;
            int c_remove_blobs_min = 0;
            int c_remove_blobs_max = 500;

            switch (state)
            {
            case (TresholdConditions.NORMAAL):
                c_threshold_h_min = 21;
                c_threshold_h_max = 50;
                c_threshold_s_min = 100;
                c_threshold_s_max = 255;
                c_threshold_v_min = 100;
                c_threshold_v_max = 255;
                break;

            case (TresholdConditions.ONDERBELICHT):
                c_threshold_h_min = 11;
                c_threshold_h_max = 119;
                c_threshold_s_min = 23;
                c_threshold_s_max = 255;
                c_threshold_v_min = 56;
                c_threshold_v_max = 176;
                break;

            case (TresholdConditions.OVERBELICHT):
                c_threshold_h_min = 0;
                c_threshold_h_max = 241;
                c_threshold_s_min = 29;
                c_threshold_s_max = 241;
                c_threshold_v_min = 249;
                c_threshold_v_max = 255;
                break;
            }

            //*******************************//
            //** Exercise:                 **//
            //**   adjust licenseplate     **//
            //**   segmentation            **//
            //*******************************//

            //Find licenseplate
            HSV888Image plateImageHSV = new HSV888Image();

            //Convert to RGB to HSV
            VisionLab.FastRGBToHSV(plateImage, plateImageHSV);

            //Threshold HSV image
            VisionLab.Threshold3Channels(plateImageHSV, binaryPlateImage, c_threshold_h_min, c_threshold_h_max, c_threshold_s_min, c_threshold_s_max, c_threshold_v_min, c_threshold_v_max);

            //Convert to a 32 bit format
            Int32Image binaryPlateImage32 = new Int32Image();

            VisionLab.Convert(binaryPlateImage, binaryPlateImage32);

            //Remove blobs with small areas
            VisionLab.RemoveBlobs(binaryPlateImage32, Connected.EightConnected, BlobAnalyse.BA_Area, c_remove_blobs_min, c_remove_blobs_max);

            //Remove border blobs
            VisionLab.RemoveBorderBlobs(binaryPlateImage32, Connected.EightConnected, Border.AllBorders);

            //Length Breath Ratio
            VisionLab.RemoveBlobs(binaryPlateImage32, Connected.EightConnected, BlobAnalyse.BA_LengthBreadthRatio, 0, 2.5);
            VisionLab.RemoveBlobs(binaryPlateImage32, Connected.EightConnected, BlobAnalyse.BA_LengthBreadthRatio, 6.7, 10);

            // Remove blobs that have to less holes
            VisionLab.RemoveBlobs(binaryPlateImage32, Connected.EightConnected, BlobAnalyse.BA_NrOfHoles, 0, 5);
            // And remove blobs that have a to small area for the holes
            VisionLab.RemoveBlobs(binaryPlateImage32, Connected.EightConnected, BlobAnalyse.BA_AreaHoles, 0, 200);

            //Convert back to a 16 bit format
            VisionLab.Convert(binaryPlateImage32, binaryPlateImage);

            //binPlateImage32.Dispose();
            binaryPlateImage32.Dispose();
            plateImageHSV.Dispose();

            GC.Collect();

            //Return true, if pixels found
            return(VisionLab.SumIntPixels(binaryPlateImage) > 0);
            //return VisionLab.LabelBlobs(binaryPlateImage, Connected.EightConnected) == 1;
        }